fix: add auth to /upload endpoint to resolve 401 on file attachment

Fixes #10

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-04-15 19:29:44 +08:00
parent 71c7f25f4b
commit 4917242dca
2 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -51,7 +51,7 @@ export async function authMiddleware(token: string | null) {
const path = ctx.path const path = ctx.path
if ( if (
path === '/health' || path === '/health' ||
(!path.startsWith('/api') && !path.startsWith('/v1') && path !== '/upload' && path !== '/webhook') (!path.startsWith('/api') && !path.startsWith('/v1') && path !== '/webhook')
) { ) {
await next() await next()
return return
+6 -1
View File
@@ -51,7 +51,12 @@ async function uploadFiles(attachments: Attachment[]): Promise<{ name: string; p
for (const att of attachments) { for (const att of attachments) {
if (att.file) formData.append('file', att.file, att.name) if (att.file) formData.append('file', att.file, att.name)
} }
const res = await fetch('/upload', { method: 'POST', body: formData }) const token = localStorage.getItem('hermes_api_key') || ''
const res = await fetch('/upload', {
method: 'POST',
body: formData,
headers: token ? { Authorization: `Bearer ${token}` } : {},
})
if (!res.ok) throw new Error(`Upload failed: ${res.status}`) if (!res.ok) throw new Error(`Upload failed: ${res.status}`)
const data = await res.json() as { files: { name: string; path: string }[] } const data = await res.json() as { files: { name: string; path: string }[] }
return data.files return data.files