Atualizar app/app.py
This commit is contained in:
+90
-4
@@ -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/<cid>", methods=["POST"])
|
||||
@app.route("/api/io/s/<cid>", 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/<cid>", 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/<cid>/<filename>")
|
||||
@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/<cid>/<filename>")
|
||||
@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"])
|
||||
|
||||
Reference in New Issue
Block a user