# 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 เตรียมไว้ก่อน