fix(server): setPgpPrivateKey 接口增加私钥格式校验

This commit is contained in:
2026-03-10 15:07:31 +08:00
parent 1945417f28
commit 4a5dd437fa

View File

@@ -1,3 +1,5 @@
import { validatePgpPrivateKey } from '@furtherverse/crypto'
import { ORPCError } from '@orpc/server'
import { ensureUxConfig, setUxLicence, setUxPgpPrivateKey } from '@/server/ux-config' import { ensureUxConfig, setUxLicence, setUxPgpPrivateKey } from '@/server/ux-config'
import { db } from '../middlewares' import { db } from '../middlewares'
import { os } from '../server' import { os } from '../server'
@@ -19,6 +21,12 @@ export const setLicence = os.config.setLicence.use(db).handler(async ({ context,
}) })
export const setPgpPrivateKey = os.config.setPgpPrivateKey.use(db).handler(async ({ context, input }) => { export const setPgpPrivateKey = os.config.setPgpPrivateKey.use(db).handler(async ({ context, input }) => {
await validatePgpPrivateKey(input.pgpPrivateKey).catch((error) => {
throw new ORPCError('BAD_REQUEST', {
message: `Invalid PGP private key: ${error instanceof Error ? error.message : 'unable to parse'}`,
})
})
const config = await setUxPgpPrivateKey(context.db, input.pgpPrivateKey) const config = await setUxPgpPrivateKey(context.db, input.pgpPrivateKey)
return toConfigOutput(config) return toConfigOutput(config)
}) })