From bd61a47cea83285b5e9b0735e1fc31497f2b3da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B3=E4=BD=A9=E5=BA=AD?= Date: Mon, 14 Jul 2025 12:49:11 +0800 Subject: [PATCH] Initial commit --- .gitattributes | 2 ++ __pycache__/app.cpython-312.pyc | Bin 0 -> 1574 bytes app.py | 27 +++++++++++++++++++++++++++ requirements.txt | 5 +++++ 4 files changed, 34 insertions(+) create mode 100644 .gitattributes create mode 100644 __pycache__/app.cpython-312.pyc create mode 100644 app.py create mode 100644 requirements.txt diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/__pycache__/app.cpython-312.pyc b/__pycache__/app.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e375ff3d0ebfdd4ac612e630e1f3c462c3f3fbb0 GIT binary patch literal 1574 zcmZuw&2Jk;6rb5I@7mcoY0@er5RmAhE+rNyhYCeV7P&B@>GDfmd|ncnO(n*DdJlK) zfHQk)7h|NLj}YlwN5rOjVlCQ`>y`6adMEqOa%8E!ppb!e?d+Y|x}F<6mVr4eQqyk4 zZ+tQXFf-3x?vKJy z3^)z=Tuv9JJMF}nA^B4agmDCJ_ zWD=`^@1qBbhv!i)J-4b&KvS7)p|A?nU#37s_gI#4Oh9;lK@Yt@p}j(_F@M$UQ7)g$ z2(4E0h|r~+6iOHgt?Kecp_M}~V6vIQct57ENJW%S1DQmcFn491GcUN!Y#E_N?lR43 zOpdQG7hnb?nYt*>hD(wBq1RwBS(@le*dTetu7F8)HEM!rq9+$F?OeTg_1kOh@eY5O zz1%E3&JJ#`Y^`iJwi=zn4~vho`DWpX*}rXX+3m$g=Bv#chnl`I)0){_>b!lRjZ1B| zHQOF)mpYT*PklGFtM3j!9Gf`M^3pZknqDuQ7|7~xk94kdM&XVVRp~QMkfIwgX>$W2 zwE)BIRy`(JDTaF5M0Z$ajS-VI3A0)!ZU7Bux>N@kt%i*I?icb;pv<_5>}Bw=aT%b( z)CjZUE>W2FNa&TY7Vvm{p!Fe4pX>%3k|G|TxL@W}cU<3PZ-GP3M#Mmzs2JlTGp-fZR$h0z>g%1A(T|PwWhSjn*bN4>qy?$_U@~7)f>i~W5 rRKs|%oqLL4gN`Wr#z<>qGye#Wo+ue?w7>iZ!FH-5W$bThh~M-t7mQ*p literal 0 HcmV?d00001 diff --git a/app.py b/app.py new file mode 100644 index 0000000..496b3a7 --- /dev/null +++ b/app.py @@ -0,0 +1,27 @@ +from fastapi import FastAPI +from fastapi.staticfiles import StaticFiles +from pydantic import BaseModel +from reportlab.pdfgen import canvas +import uuid, os + +app = FastAPI() + +os.makedirs("static", exist_ok=True) +app.mount("/static", StaticFiles(directory="static"), name="static") + +class TextRequest(BaseModel): + content: str + +@app.post("/generate-pdf") +def generate_pdf(data: TextRequest): + filename = f"{uuid.uuid4()}.pdf" + filepath = os.path.join("static", filename) + + c = canvas.Canvas(filepath) + c.setFont("Helvetica", 12) + c.drawString(100, 750, data.content[:1000]) # 控制最多幾個字,否則會 overflow + c.save() + + return { + "url": f"/static/{filename}" + } diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e7caa4e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +fastapi +uvicorn +pydantic +reportlab +python-multipart