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.
92 lines
4.9 KiB
PowerShell
92 lines
4.9 KiB
PowerShell
# ติดตั้ง (sideload) / ถอด Word add-in "e-Court Documents Versioning" บน Windows
|
|
# เวอร์ชัน PowerShell แบบส่งให้เครื่องทดสอบที่ไม่มี Node/repo — คู่หูของ
|
|
# scripts/install-wordaddin.mjs (รันใน repo) และ scripts/install-wordaddin.sh (macOS)
|
|
# กลไกเดียวกันทั้งสามไฟล์: โหลด manifest จาก server เก็บไว้
|
|
# %USERPROFILE%\Documents\wordaddin-manifest\ แล้วจดทะเบียน registry
|
|
# HKCU\Software\Microsoft\Office\16.0\Wef\Developer (กลไกเดียวกับ office-addin-dev-settings)
|
|
#
|
|
# ใช้: powershell -ExecutionPolicy Bypass -File install-wordaddin.ps1 [-Url <manifest-url>] [-Remove]
|
|
# -Url default https://ecourt-note.chamomind.com/docedit/wordaddin/manifest.xml
|
|
# -Remove ถอดการติดตั้ง
|
|
#
|
|
# (ไฟล์นี้ต้องมี BOM — Windows PowerShell 5.1 อ่าน UTF-8 ไม่มี BOM เป็น ANSI แล้วข้อความไทยพัง)
|
|
# หลังลง/ถอดต้อง restart Word ทุกครั้ง · รายละเอียดเต็ม: docs/WORDADDIN-DEV.md
|
|
|
|
param(
|
|
[string]$Url = "https://ecourt-note.chamomind.com/docedit/wordaddin/manifest.xml",
|
|
[switch]$Remove
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
# ให้ console พิมพ์ไทย/✓ ถูกต้อง และบังคับ TLS 1.2 (PS 5.1 บางเครื่อง default ยังเป็น TLS 1.0)
|
|
try { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 } catch { }
|
|
[Net.ServicePointManager]::SecurityProtocol = `
|
|
[Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
|
|
|
$Prefix = "[install-addin]"
|
|
$DevKeyCmd = "HKCU\Software\Microsoft\Office\16.0\Wef\Developer"
|
|
$ManifestDir = Join-Path $env:USERPROFILE "Documents\wordaddin-manifest"
|
|
$ManifestPath = Join-Path $ManifestDir "manifest.xml"
|
|
|
|
function Fail($message) {
|
|
Write-Host "$Prefix ✗ $message" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
function Print-NextSteps {
|
|
Write-Host ""
|
|
Write-Host "ขั้นต่อไป:"
|
|
Write-Host " 1. restart Word ให้ครบทุกหน้าต่าง (จำเป็นทุกครั้งหลังลง/ถอด)"
|
|
Write-Host ' 2. Insert > My Add-ins > SHARED FOLDER > เปิด "e-Court Documents Versioning"'
|
|
Write-Host " 3. เปิดไฟล์ .docx ที่มี ticket ของ e-Court (ขอจากทีม) เพื่อเริ่มทดสอบ"
|
|
}
|
|
|
|
if ($Remove) {
|
|
Write-Host "$Prefix platform: win32 · โหมดถอดการติดตั้ง"
|
|
if (-not (Test-Path $ManifestPath)) {
|
|
Fail "ไม่พบ manifest ที่เก็บไว้ ($ManifestPath) จึงไม่รู้ GUID ของ add-in — ลบเองได้ที่: reg delete `"$DevKeyCmd`" /v <GUID> /f"
|
|
}
|
|
$stored = Get-Content -Raw -Encoding UTF8 $ManifestPath
|
|
if ($stored -notmatch "<Id>([0-9a-fA-F-]{36})</Id>") {
|
|
Fail "อ่าน GUID จาก $ManifestPath ไม่ได้"
|
|
}
|
|
$guid = $Matches[1].ToLower()
|
|
& reg.exe delete $DevKeyCmd /v $guid /f | Out-Null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Fail "reg delete ไม่สำเร็จ (exit $LASTEXITCODE) — ลบเองได้ที่: reg delete `"$DevKeyCmd`" /v $guid /f"
|
|
}
|
|
Remove-Item $ManifestPath -ErrorAction SilentlyContinue
|
|
Write-Host "$Prefix ✓ ถอดการติดตั้งแล้ว (registry $guid + ไฟล์ $ManifestPath)"
|
|
Write-Host "$Prefix ✓ เสร็จ"
|
|
Print-NextSteps
|
|
exit 0
|
|
}
|
|
|
|
Write-Host "$Prefix platform: win32"
|
|
|
|
try {
|
|
$response = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 30
|
|
} catch {
|
|
Fail "โหลด manifest จาก $Url ไม่ได้ ($_)"
|
|
}
|
|
$xml = $response.Content
|
|
if ($xml -notmatch "<OfficeApp") {
|
|
Fail "response จาก $Url ไม่ใช่ manifest ของ Office add-in (ไม่มี <OfficeApp)"
|
|
}
|
|
if ($xml -notmatch "<Id>([0-9a-fA-F-]{36})</Id>") {
|
|
Fail "หา <Id> (GUID) ใน manifest ไม่เจอจาก $Url"
|
|
}
|
|
$guid = $Matches[1].ToLower()
|
|
|
|
New-Item -ItemType Directory -Force -Path $ManifestDir | Out-Null
|
|
# เขียน UTF-8 ไม่มี BOM — ให้ manifest เหมือนต้นฉบับบน server เป๊ะ
|
|
[System.IO.File]::WriteAllText($ManifestPath, $xml, (New-Object System.Text.UTF8Encoding($false)))
|
|
Write-Host "$Prefix ✓ เก็บ manifest ไว้ที่ $ManifestPath"
|
|
|
|
& reg.exe add $DevKeyCmd /v $guid /t REG_SZ /d $ManifestPath /f | Out-Null
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Fail "เขียน registry ไม่สำเร็จ (exit $LASTEXITCODE)"
|
|
}
|
|
Write-Host "$Prefix ✓ จดทะเบียน add-in ใน registry ($DevKeyCmd → $guid)"
|
|
Write-Host "$Prefix ✓ เสร็จ"
|
|
Print-NextSteps
|