feat(console): add support actions (#33492)
This commit is contained in:
parent
633fc6fc03
commit
ad3651d8f1
14 changed files with 255 additions and 156 deletions
|
|
@ -147,6 +147,12 @@ export namespace Share {
|
|||
}
|
||||
})
|
||||
|
||||
export const removeAdmin = fn(Info.pick({ id: true }), async (body) => {
|
||||
const share = await get(body.id)
|
||||
if (!share) throw new Errors.NotFound(body.id)
|
||||
await remove({ id: share.id, secret: share.secret })
|
||||
})
|
||||
|
||||
export const sync = fn(
|
||||
z.object({
|
||||
share: Info.pick({ id: true, secret: true }),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import { validator } from "hono-openapi"
|
|||
import z from "zod"
|
||||
import { cors } from "hono/cors"
|
||||
import { Share } from "~/core/share"
|
||||
import { Resource } from "sst"
|
||||
import { timingSafeEqual } from "node:crypto"
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
|
|
@ -137,6 +139,22 @@ app
|
|||
return c.json({})
|
||||
},
|
||||
)
|
||||
.post(
|
||||
"/support/actions/remove-share",
|
||||
async (c) => {
|
||||
const authorization = c.req.header("authorization")
|
||||
const expected = `Bearer ${(Resource as unknown as Record<string, { value: string }>).SUPPORT_API_KEY.value}`
|
||||
const actual = Buffer.from(authorization ?? "")
|
||||
const secret = Buffer.from(expected)
|
||||
if (actual.length !== secret.length || !timingSafeEqual(actual, secret)) return c.json({ error: "Unauthorized" }, 401)
|
||||
|
||||
const body = z.object({ shareID: z.string().min(1) }).safeParse(await c.req.json().catch(() => undefined))
|
||||
if (!body.success) return c.json({ error: "Invalid request", issues: body.error.issues }, 400)
|
||||
return Share.removeAdmin({ id: body.data.shareID })
|
||||
.then(() => c.json({ success: true, message: "Share removed" }))
|
||||
.catch((error) => c.json({ error: error instanceof Error ? error.message : String(error) }, 400))
|
||||
},
|
||||
)
|
||||
|
||||
export function GET(event: APIEvent) {
|
||||
return app.fetch(event.request)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue