Refactor ticket verification and installation scripts
All checks were successful
Deploy eCourt Note Web to Server / Validate Database Schema (Drizzle) (push) Successful in 3s
Deploy eCourt Note Web to Server / Build Web Docker Image (push) Successful in 1m17s
Deploy eCourt Note Web to Server / Deploy eCourt Note Web to Server (push) Successful in 4s
Deploy eCourt Note Web to Server / Notify Deployment Status (push) Successful in 1s
All checks were successful
Deploy eCourt Note Web to Server / Validate Database Schema (Drizzle) (push) Successful in 3s
Deploy eCourt Note Web to Server / Build Web Docker Image (push) Successful in 1m17s
Deploy eCourt Note Web to Server / Deploy eCourt Note Web to Server (push) Successful in 4s
Deploy eCourt Note Web to Server / Notify Deployment Status (push) Successful in 1s
- Split `verifyAddinTicket` into two functions: `verifyAddinTicketHmac` (ignores expiration) and `verifyAddinTicket` (checks expiration). - Add `hasVersionByUser` function to check if a document has been previously worked on by a user, allowing expired tickets to be accepted if the user has a history with the document. - Update OpenAPI specification to reflect changes in ticket expiration handling. - Introduce new scripts for installing and uninstalling the Word add-in on Windows and macOS, providing a streamlined process for sideloading the add-in. - Enhance tests for ticket verification to cover new functionality regarding expired tickets and user history.
This commit is contained in:
parent
3726cb742f
commit
b1449ab668
14 changed files with 727 additions and 75 deletions
|
|
@ -33,7 +33,27 @@ manifest ต้องชี้ https — 2 ทางเลือก:
|
|||
1. **self-signed ของ Next (ง่ายสุด):** `npm run dev:https` → https://localhost:3000 — Word อาจเตือน certificate ครั้งแรก (เปิด URL ใน browser กดผ่านก่อน 1 ครั้ง)
|
||||
2. **ใบรับรอง trusted (แนะนำ ไม่มี warning):** รัน `npx office-addin-dev-certs install` ครั้งเดียว แล้ว copy `%USERPROFILE%\.office-addin-dev-certs\localhost.crt` + `localhost.key` มาที่ `certs/` (gitignore แล้ว) แล้วใช้ `npm run dev:https:cert`
|
||||
|
||||
## Sideload ใน Word Desktop (Windows)
|
||||
## ติดตั้ง (sideload) ด้วยสคริปต์ — Windows + macOS
|
||||
|
||||
`scripts/install-wordaddin.*` (มี 3 รูปแบบ กลไกเดียวกัน) โหลด manifest จาก server แล้วจดทะเบียนให้ Word Desktop เห็น add-in ในคำสั่งเดียว:
|
||||
|
||||
```bash
|
||||
# ใน repo (มี Node)
|
||||
npm run addin:install
|
||||
# ส่งให้เครื่องทดสอบที่ไม่มี Node/repo — ส่งไฟล์เดี่ยวได้เลย
|
||||
./install-wordaddin.sh # macOS (bash + curl ของเครื่อง)
|
||||
powershell -ExecutionPolicy Bypass -File install-wordaddin.ps1 # Windows
|
||||
node install-wordaddin.mjs # ใช้ Node ก็ได้ทั้งสอง OS
|
||||
```
|
||||
|
||||
- **default โหลดจาก server ทดสอบ** `https://ecourt-note.chamomind.com/docedit/wordaddin/manifest.xml` — เครื่องทดสอบไม่ต้องรันอะไรเพิ่ม · จะชี้ dev ให้ `--url https://localhost:3000/docedit/wordaddin/manifest.xml` (ต้อง `npm run dev:https` ไว้ก่อน)
|
||||
- **Windows:** เก็บ manifest ไว้ `%USERPROFILE%\Documents\wordaddin-manifest\` แล้วเขียน registry `HKCU\Software\Microsoft\Office\16.0\Wef\Developer` (กลไกเดียวกับ `office-addin-dev-settings`) — ไม่ต้องคลิก Trust Center
|
||||
- **macOS:** วางไฟล์ manifest เป็น `<GUID>.manifest.xml` ใน `~/Library/Containers/com.microsoft.Word/Data/Documents/wef/`
|
||||
- หลังรัน **restart Word** แล้วเปิดได้ที่ **Insert > My Add-ins > SHARED FOLDER** (Windows) / **Insert > My Add-ins** (macOS)
|
||||
- **ถอด:** `--remove` ทุกไฟล์ (`npm run addin:install -- --remove` / `./install-wordaddin.sh --remove` / `-Remove` ของ .ps1 — ลบ registry value / ไฟล์ใน wef · ถอดแบบ manual: `reg delete "HKCU\Software\Microsoft\Office\16.0\Wef\Developer" /v <GUID> /f` หรือลบไฟล์ในโฟลเดอร์ wef เอง) · ⚠️ ไฟล์ .ps1 ต้องมี **BOM** ติดตัวมา (PowerShell 5.1 อ่าน UTF-8 ไร้ BOM เป็น ANSI แล้วข้อความไทยพัง) — แก้ไฟล์แล้วอย่าลืมเซฟแบบ UTF-8 with BOM
|
||||
- รันซ้ำได้ (idempotent) — โหลด manifest ใหม่ทุกครั้งจึงได้ URL ของ environment ปัจจุบันเสมอ
|
||||
|
||||
## Sideload แบบ manual (Windows)
|
||||
|
||||
เครื่อง dev ที่มี repo (แนะนำ — ไม่ต้องดาวน์โหลด/คัดลอกอะไรเลย):
|
||||
|
||||
|
|
@ -49,6 +69,14 @@ manifest ต้องชี้ https — 2 ทางเลือก:
|
|||
|
||||
Deploy จริง (intranet): **ไม่ต้อง rewrite อะไรแล้ว** — manifest serve ผ่าน `app/wordaddin/manifest.xml/route.ts` ซึ่งเขียนทับ origin ให้ตรงโฮสต์ที่ขอไฟล์อัตโนมัติ ดาวน์โหลด `https://<โฮสต์>/docedit/wordaddin/manifest.xml` แล้วใช้ sideload ได้ทันทีทุก environment (dev/UAT/production) · proxy ฝั่งหน้าควรส่ง `X-Forwarded-Host`/`X-Forwarded-Proto` ตามมาตรฐาน — ถ้าไม่ส่ง route ก็ยังใช้ Host ของ request และบังคับ https ให้โฮสต์ที่ไม่ใช่ localhost อยู่ดี
|
||||
|
||||
### macOS (manual)
|
||||
|
||||
Word for Mac ไม่มี Trust Center แบบ Windows — สแกน add-in จากโฟลเดอร์ของตัวเอง:
|
||||
|
||||
1. ดาวน์โหลด manifest จาก environment นั้น: `https://<โฮสต์>/docedit/wordaddin/manifest.xml`
|
||||
2. วางไฟล์ใน `~/Library/Containers/com.microsoft.Word/Data/Documents/wef/` (สร้างโฟลเดอร์ได้ถ้ายังไม่มี) — ชื่อไฟล์เป็นอะไรก็ได้ ขอแค่ลงท้าย `.xml` (สคริปต์ด้านบนตั้งชื่อ `<GUID>.manifest.xml` ให้เอง)
|
||||
3. restart Word แล้วเปิดได้ที่ **Insert > My Add-ins**
|
||||
|
||||
รุ่น Office ที่รองรับ: manifest กำหนด WordApi **1.3** เป็นค่าต่ำสุด (customXmlParts คือ API สูงสุดที่ใช้ประจำ) — Microsoft 365 / Office 2021+ ใช้ได้ครบทุกฟีเจอร์ · **Office 2019 โหลดได้ แต่ปุ่ม "…และปิดเอกสาร" ถูกซ่อนอัตโนมัติ** เพราะ `document.close()` ต้องการ WordApi 1.4/1.5 (Microsoft 365 เท่านั้น) — `canCloseDocument()` เช็ค `isSetSupported` ตอน runtime แล้วซ่อน พฤติกรรมเดียวกับ Word on the web · Office 2016 (WordApi 1.1) โหลดไม่ขึ้น (เดิมเคยตั้ง 1.5 ทำให้ Office 2019 โหลดไม่ขึ้นด้วย — แก้ 2026-10-16)
|
||||
|
||||
## ทดสอบใน browser ธรรมดา (ไม่ต้องเปิด Word)
|
||||
|
|
@ -72,7 +100,7 @@ node scripts/make-ticket-docx.mjs path/to/file.ticket.docx --list
|
|||
node scripts/make-ticket-docx.mjs path/to/file.docx --tracked --in-place
|
||||
```
|
||||
|
||||
แล้วเปิดไฟล์ใน Word ที่ sideload แล้ว → ต้องเข้าเฟส untracked (หรือ tracking เมื่อ `--tracked`) ทันที ชื่อผู้ใช้ = `uname` · ทดสอบ fail-case: แก้ `ticket_data` ผ่าน **File → Info → Properties → Advanced Properties → Custom** สัก 1 ตัวอักษร → no-access "ไฟล์ถูกแก้ไข" · สร้างด้วย `--exp +1` รอ 1 นาทีแล้วเปิด → no-access "ticket หมดอายุ" · เปิดเอกสารเดิมซ้ำ (จน ticket หมดอายุแต่ token ยังอยู่ใน localStorage) → ยังใช้ได้ตาม requirement ขั้น 7
|
||||
แล้วเปิดไฟล์ใน Word ที่ sideload แล้ว → ต้องเข้าเฟส untracked (หรือ tracking เมื่อ `--tracked`) ทันที ชื่อผู้ใช้ = `uname` · ทดสอบ fail-case: แก้ `ticket_data` ผ่าน **File → Info → Properties → Advanced Properties → Custom** สัก 1 ตัวอักษร → no-access "ไฟล์ถูกแก้ไข" · สร้างด้วย `--exp +1` รอ 1 นาทีแล้วเปิด**เอกสารที่ยังไม่เคยสร้าง version** → no-access "ticket หมดอายุ" · เปิดเอกสารเดิมซ้ำหลัง ticket หมดอายุ → ยังใช้ได้ตาม requirement ขั้น 7: add-in ยิงขอ token ใหม่แล้ว server ตรวจว่า fid นี้เคยมี version โดย uid เดียวกัน → ออกให้ต่อ (แก้ 2026-10-28 — ใช้ได้แม้ token เก่าหมดอายุหรือ localStorage `wordaddin-auth` โดนเคลียร์ เพราะไม่พึ่ง cache ในเครื่องอีกต่อไป · ข้อจำกัด: เอกสารที่เคยเปิดแต่ยังไม่เคยสร้าง version ไม่มีหลักฐานฝั่ง server ต้องขอไฟล์ใหม่จาก e-Court)
|
||||
|
||||
หมายเหตุ: การขอ token ยิง same-origin `/docedit/api/documents/token` จริง (ไม่ผูก `NEXT_PUBLIC_ADDIN_API_BASE_URL`) — dev server ต้องรันอยู่และ secret ฝั่ง server (`ADDIN_TICKET_SECRET` → `SECRET` → default `super_secret`) ตรงกับ `--secret` ของสคริปต์
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue