เพิ่มกลุ่ม API docx template สำหรับ wordaddin (WIP): - POST /api/template/extract ดึงค่า Content Control ทั้งหมดจาก .docx - POST /api/template/render แทนค่า JSON ลง template คืน .docx ใหม่ - GET /api/template/test ตรวจว่า service มีชีวิต logic แชร์ที่ app/api/template/lib-tmpl.ts (pizzip+xpath) ไม่แตะ DB เพิ่มหน้า Swagger UI ที่ GET /api/swagger — spec inline จาก lib/openapi.ts ครอบ API ทุกกลุ่ม (template + N10), asset self-host ที่ public/note/swagger-ui/ จาก postinstall scripts/copy-swagger-ui.mjs (intranet ไม่ใช้ CDN — หาไฟล์ไม่เจอหลังอัปเกรด = exit 1 เหมือน patch-pdf-worker, Docker build รัน script นี้ด้วยผ่าน web.Dockerfile) middleware เปิดกว้างให้ api/template, api/swagger, note/swagger-ui จาก code review: จำกัดไฟล์แนบ 100MB ทั้ง extract/render ก่อนอ่าน เข้าหน่วยความจำกัน DoS, คืน 400 แทน 500 เมื่อ JSON ผิด format, sync คำอธิบาย BadRequest ใน openapi spec ให้ตรง behavior ใหม่ Co-Authored-By: Claude Code <noreply@anthropic.com>
57 lines
3.6 KiB
Markdown
57 lines
3.6 KiB
Markdown
# Docx Template
|
|
lib-tmpl.ts เป็นแชร์ไลบารีสำหรับการทำ Template ใช้ Content Control ใน MS Word
|
|
## วิธีการใช้ API
|
|
```sh
|
|
## Swagger UI — เปิดในเบราว์เซอร์ (ลองยิงจริงผ่านปุ่ม Try it out ได้เลย ไม่ต้อง login)
|
|
http://localhost:3000/docedit/api/swagger
|
|
|
|
## template/test ไว้ทดสอบเท่านั้น
|
|
curl.exe http://localhost:3000/docedit/api/template/test
|
|
|
|
## extract ค่าออกมาจาก content control
|
|
curl.exe -X POST http://localhost:3000/docedit/api/template/extract -F "file=@./output-T3.docx"
|
|
|
|
## render เอกสาร (docx) = template(docx)+data(json)
|
|
### อาจจะเพิ่มการเอา template จาก url และ file(local) ยังไม่รู้ว่าทางนั้นจะส่งไฟล์แบบไหนมาให้ เอาแค่นี้ไว้ทดสอบก่อน
|
|
curl.exe -X POST http://localhost:3000/docedit/api/template/render -F "template=@./T3.docx" -F "data=@./T2.json" -o output.docx
|
|
### data เอาจาก string
|
|
curl -X POST http://localhost:3000/docedit/api/template/render \
|
|
-F "template=@template.docx" \
|
|
-F 'dataJson={"member_name":"นายสมชาย","member_id":"123456"}' \
|
|
-o generated-document.docx
|
|
|
|
```
|
|
data(json) ตอนนี้อยู่ในรูปแบบ
|
|
```json
|
|
{
|
|
"notname": "คำสั่งเรียก ให้ทำคำให้การ",
|
|
"nottype": "(ต. ๑)",
|
|
"blackno": "คดีหมายเลขดำที่",
|
|
"blackyear": "๑๐/๒๕๖๙",
|
|
...
|
|
}
|
|
```
|
|
data(json)น่าจะปรับเป็นแบบนี้เพื่อรองรับการทำ Token-Based Seamless Integration
|
|
หลักผ่าน API
|
|
- ส่วนของ cc จะไปกรอกใน Content Control
|
|
- uid,uname,fid,ott,expire สร้างเป็น token ฝังใน custom property ของเอกสาร
|
|
```json
|
|
{
|
|
"uid":"id ผู้มีสิทธิ์แก้ไขเอกสาร",
|
|
"uname": "ชื่อผู้มีสิทธิ์แก้ไขเอกสาร สำหรับแสดงผล",
|
|
"fid":"file id จะได้เซฟข้อมูลกลับไปที่ Oracle ถูกตารางและหน่วยงาน",
|
|
"ott":"อายุของ one time token แบบระยะสั้น",
|
|
"expire": "อายุเอกสารแบบระยะยาวหลังเอา ott ไปแลก (optional)",
|
|
cc:{
|
|
"notname": "คำสั่งเรียก ให้ทำคำให้การ",
|
|
"nottype": "(ต. ๑)",
|
|
"blackno": "คดีหมายเลขดำที่",
|
|
"blackyear": "๑๐/๒๕๖๙",
|
|
...
|
|
}
|
|
}
|
|
```
|
|
ที่ต้องทำเพิ่ม
|
|
- render ปัจจุบันมีไว้ให้ทางศาลทดสอบ อันที่ใช้จริงหลังกดสร้าง Template เพื่อ Download จะสร้างเอกสารเวอร์ชั่นแรกใน object storage หรือถ้ามีอยู่แล้ว จะเป็นการอัปเดต
|
|
- Backend จัดการ version
|
|
- อัปเดตข้อมูลและเอกสารกลับระบบเดิม ส่วนนี้ยังไม่ชัดเจนอาจจะทำ mock api เตรียมไว้ก่อน
|