fix(server): setPgpPrivateKey 接口增加私钥格式校验
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { validatePgpPrivateKey } from '@furtherverse/crypto'
|
||||
import { ORPCError } from '@orpc/server'
|
||||
import { ensureUxConfig, setUxLicence, setUxPgpPrivateKey } from '@/server/ux-config'
|
||||
import { db } from '../middlewares'
|
||||
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 }) => {
|
||||
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)
|
||||
return toConfigOutput(config)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user