mirror of
https://github.com/kennethnym/aris.git
synced 2026-03-27 12:21:17 +00:00
feat(backend): add GET /api/sources/:sourceId (#89)
Return { enabled, config } for a user's source. Defaults to
{ enabled: false, config: {} } when no row exists.
Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
@@ -38,10 +38,31 @@ export function registerSourcesHttpHandlers(
|
||||
await next()
|
||||
})
|
||||
|
||||
app.get("/api/sources/:sourceId", inject, authSessionMiddleware, handleGetSource)
|
||||
app.patch("/api/sources/:sourceId", inject, authSessionMiddleware, handleUpdateSource)
|
||||
app.put("/api/sources/:sourceId", inject, authSessionMiddleware, handleReplaceSource)
|
||||
}
|
||||
|
||||
async function handleGetSource(c: Context<Env>) {
|
||||
const sourceId = c.req.param("sourceId")
|
||||
if (!sourceId) {
|
||||
return c.body(null, 404)
|
||||
}
|
||||
|
||||
const sessionManager = c.get("sessionManager")
|
||||
const user = c.get("user")!
|
||||
|
||||
try {
|
||||
const result = await sessionManager.fetchSourceConfig(user.id, sourceId)
|
||||
return c.json(result)
|
||||
} catch (err) {
|
||||
if (err instanceof SourceNotFoundError) {
|
||||
return c.json({ error: err.message }, 404)
|
||||
}
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
async function handleUpdateSource(c: Context<Env>) {
|
||||
const sourceId = c.req.param("sourceId")
|
||||
if (!sourceId) {
|
||||
|
||||
Reference in New Issue
Block a user