mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat: add assistant mode, SSE streaming, and OpenCode server integration (#214)
This commit is contained in:
1 parent
3cc24288a6
commit
c3d6549f01
133 files changed
+7284
-6293
No files matched your search
@@ -0,0 +1,19 @@
|
||||
import { createMiddleware } from 'hono/factory'
|
||||
import { timingSafeEqual } from 'node:crypto'
|
||||
import type { Database } from 'bun:sqlite'
|
||||
import { getOrCreateInternalToken } from '../services/internal-token'
|
||||
|
||||
export function createInternalTokenMiddleware(db: Database) {
|
||||
return createMiddleware(async (c, next) => {
|
||||
const header = c.req.header('authorization') ?? c.req.header('Authorization')
|
||||
if (!header || !header.startsWith('Bearer ')) {
|
||||
return c.json({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
const provided = Buffer.from(header.slice(7))
|
||||
const expected = Buffer.from(getOrCreateInternalToken(db))
|
||||
if (provided.length !== expected.length || !timingSafeEqual(provided, expected)) {
|
||||
return c.json({ error: 'Unauthorized' }, 401)
|
||||
}
|
||||
await next()
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user