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