Atualizar app/app.py
This commit is contained in:
+12
-10
@@ -752,10 +752,12 @@ def list_conversations():
|
||||
db.close()
|
||||
return jsonify(data)
|
||||
|
||||
@app.route("/api/export/md/<cid>")
|
||||
|
||||
@app.route("/api/export/md/<cid>/<filename>")
|
||||
@login_required
|
||||
@rate_limited
|
||||
def export_md(cid):
|
||||
def export_md(cid, filename):
|
||||
# validação de conversa + usuário
|
||||
|
||||
db = SessionLocal()
|
||||
email = session["user"]["email"] if app.config["AUTH_MODE"] == "oauth" else session["db_user"]["email"]
|
||||
conv = db.query(Conversation).filter_by(id=cid, user_email=email).first()
|
||||
@@ -772,7 +774,8 @@ def export_md(cid):
|
||||
md += f"### {m.role.capitalize()}\n\n{m.content}\n\n"
|
||||
|
||||
db.close()
|
||||
return Response(md, mimetype="text/markdown")
|
||||
#return Response(md, mimetype="text/markdown")
|
||||
return send_file(md_path, as_attachment=True, download_name=filename)
|
||||
|
||||
|
||||
@app.route("/api/file/<file_id>/<filename>")
|
||||
@@ -847,11 +850,9 @@ def import_file(cid):
|
||||
|
||||
return jsonify({"status": "ok", "imported_as_markdown": True})
|
||||
|
||||
|
||||
@app.route("/api/export/pdf/<cid>")
|
||||
@app.route("/api/export/pdf/<cid>/<filename>")
|
||||
@login_required
|
||||
@rate_limited
|
||||
def export_pdf(cid):
|
||||
def export_pdf(cid, filename):
|
||||
db = SessionLocal()
|
||||
email = session["user"]["email"] if app.config["AUTH_MODE"] == "oauth" else session["db_user"]["email"]
|
||||
conv = db.query(Conversation).filter_by(id=cid, user_email=email).first()
|
||||
@@ -869,7 +870,8 @@ def export_pdf(cid):
|
||||
db.close()
|
||||
|
||||
pdf = HTML(string=html).write_pdf()
|
||||
return Response(pdf, mimetype="application/pdf")
|
||||
#return Response(pdf, mimetype="application/pdf")
|
||||
return send_file(pdf_path, as_attachment=True, download_name=filename)
|
||||
|
||||
|
||||
|
||||
@@ -1208,7 +1210,7 @@ def import_excel(cid):
|
||||
id=str(uuid.uuid4()),
|
||||
conversation_id=cid,
|
||||
role="user",
|
||||
content=f"### Sheet: {sheet_name}\n```\n{tsv}\n```"
|
||||
content=f"Arquivo importado: {sheet_name}.tsv\n```\n{tsv}\n```"
|
||||
)
|
||||
db.add(msg)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user