mirror of
https://github.com/documenso/documenso.git
synced 2026-07-12 22:15:01 +10:00
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
|
import { verifyEmbeddingPresignToken } from '@documenso/lib/server-only/embedding-presign/verify-embedding-presign-token';
|
|
|
|
import { procedure } from '../trpc';
|
|
import {
|
|
verifyEmbeddingPresignTokenMeta,
|
|
ZVerifyEmbeddingPresignTokenRequestSchema,
|
|
ZVerifyEmbeddingPresignTokenResponseSchema,
|
|
} from './verify-embedding-presign-token.types';
|
|
|
|
/**
|
|
* Public route.
|
|
*/
|
|
export const verifyEmbeddingPresignTokenRoute = procedure
|
|
.meta(verifyEmbeddingPresignTokenMeta)
|
|
.input(ZVerifyEmbeddingPresignTokenRequestSchema)
|
|
.output(ZVerifyEmbeddingPresignTokenResponseSchema)
|
|
.mutation(async ({ input }) => {
|
|
try {
|
|
const { token, scope } = input;
|
|
|
|
const apiToken = await verifyEmbeddingPresignToken({
|
|
token,
|
|
scope,
|
|
}).catch(() => null);
|
|
|
|
return { success: !!apiToken };
|
|
} catch (error) {
|
|
if (error instanceof AppError) {
|
|
throw error;
|
|
}
|
|
|
|
throw new AppError(AppErrorCode.UNKNOWN_ERROR, {
|
|
message: 'Failed to verify embedding presign token',
|
|
});
|
|
}
|
|
});
|