fix: resolve Chinese filename garbling on upload and page update failure (#72, #71)

- Fix multipart upload parsing to use Buffer operations instead of latin1
  string conversion, preserving multi-byte characters in filenames (#72)
- Support RFC 5987 filename* encoding for cross-platform compatibility
- Fix in-page update by running npm install directly instead of CLI command
  that kills the server process before response is sent (#71)
- Add no-cache header to version check to avoid stale latest version
- Change version check interval from 4 hours to 1 hour

Closes #72, Closes #71

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-04-20 12:15:47 +08:00
parent 5d16d56d9f
commit eb6c2dc9f6
3 changed files with 48 additions and 14 deletions
+8 -3
View File
@@ -36,6 +36,7 @@ async function checkLatestVersion(): Promise<void> {
try {
const res = await fetch('https://registry.npmjs.org/hermes-web-ui/latest', {
signal: AbortSignal.timeout(5000),
headers: { 'Cache-Control': 'no-cache' },
})
if (res.ok) {
const data = await res.json()
@@ -83,9 +84,11 @@ export async function bootstrap() {
app.use(async (ctx, next) => {
if (ctx.path === '/api/hermes/update' && ctx.method === 'POST') {
const isWin = process.platform === 'win32'
// Run npm install directly — calling `hermes-web-ui update` would kill this
// process (stopDaemon) before the response can be sent to the client.
const cmd = isWin
? 'cmd /c hermes-web-ui update'
: 'hermes-web-ui update'
? 'cmd /c npm install -g hermes-web-ui@latest'
: 'npm install -g hermes-web-ui@latest'
try {
const { execSync } = await import('child_process')
@@ -95,6 +98,8 @@ export async function bootstrap() {
stdio: ['pipe', 'pipe', 'pipe'],
})
ctx.body = { success: true, message: output.trim() }
// Restart the server after response is sent
setTimeout(() => process.exit(0), 1000)
} catch (err: any) {
ctx.status = 500
ctx.body = { success: false, message: err.stderr || err.message }
@@ -168,7 +173,7 @@ export async function bootstrap() {
// Check for updates every 4 hours
checkLatestVersion()
setInterval(checkLatestVersion, 4 * 60 * 60 * 1000)
setInterval(checkLatestVersion, 60 * 60 * 1000)
}
// ============================