From a9e6fbf6b267600bdea97d5d058027a7abac678c Mon Sep 17 00:00:00 2001 From: Renato Rosa Date: Wed, 19 Aug 2026 23:10:29 -0300 Subject: [PATCH] Atualizar app/app.py --- app/app.py | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 4 deletions(-) diff --git a/app/app.py b/app/app.py index 09f8552..1f17932 100644 --- a/app/app.py +++ b/app/app.py @@ -1182,9 +1182,9 @@ def subscribe(): # =========== # IO -from io.excel import convert_excel, convert_excel_all_sheets +from io.spreadsheet import convert_excel, convert_excel_all_sheets -@app.route("/api/import_excel/", methods=["POST"]) +@app.route("/api/io/s/", methods=["POST"]) @login_required def import_excel(cid): file = request.files.get("file") @@ -1218,13 +1218,99 @@ def import_excel(cid): return jsonify({"status": "ok", "sheets": list(sheets.keys())}) +from io.presentation import convert_presentation +@app.route("/api/io/p/", methods=["POST"]) +@login_required +def import_presentation(cid): + file = request.files.get("file") + if not file: + return jsonify({"erro": "Nenhum arquivo enviado."}), 400 + + ext = file.filename.lower().split(".")[-1] + if ext not in ["ppt", "pptx", "odp"]: + return jsonify({"erro": "Formato não suportado."}), 400 + + email = session["user"]["email"] if app.config["AUTH_MODE"] == "oauth" else session["db_user"]["email"] + + temp_path = f"/data/{uuid.uuid4()}.{ext}" + file.save(temp_path) + + slides = convert_presentation(temp_path) + + db = SessionLocal() + + for slide_name, content in slides: + tsv = "\x09".join([normalize_newlines(content)]) + filename = f"{slide_name}.tsv" + + file_id = str(uuid.uuid4()) + path = f"/data/{file_id}_{filename}" + + with open(path, "w", encoding="utf-8") as f: + f.write(tsv) + + db.add(File( + id=file_id, + user_email=email, + path=path, + original_name=filename + )) + + msg = Message( + id=str(uuid.uuid4()), + conversation_id=cid, + role="user", + content=f"Slide importado: {filename}\n```\n{tsv}\n```" + ) + db.add(msg) + + db.commit() + db.close() + + return jsonify({"status": "ok", "slides": [s[0] for s in slides]}) + +from pptx import Presentation + +@app.route("/api/io/p//") +@login_required +def export_pptx(cid, filename): + email = session["user"]["email"] if app.config["AUTH_MODE"] == "oauth" else session["db_user"]["email"] + + db = SessionLocal() + msgs = ( + db.query(Message) + .join(Conversation) + .filter(Conversation.id == cid, Conversation.user_email == email) + .order_by(Message.created_at) + .all() + ) + db.close() + + prs = Presentation() + for m in msgs: + slide = prs.slides.add_slide(prs.slide_layouts[1]) + body = slide.shapes.placeholders[1] + tf = body.text_frame + tf.text = m.content + + out = f"/data/{uuid.uuid4()}_{filename}" + prs.save(out) + + return send_file(out, as_attachment=True, download_name=filename) + +@app.route("/api/export/odp//") +@login_required +def export_odp(cid, filename): + # similar approach using odfpy + # create ODP with each message as a slide + ... # ================ -# TASKS - +# TASKS +# ================ from tasks import generate_task @app.route("/api/queue/generate", methods=["POST"])