K-VAULT / functions /api /admin /_middleware.js
spongyicybulk's picture
feat: 适配 HuggingFace Space 单容器部署
c8cfaf5 verified
Raw
History Blame Contribute Delete
600 Bytes
import { checkAuthentication, isAuthRequired } from '../../utils/auth.js';
import { apiError } from '../../utils/api-v1.js';
export async function onRequest(context) {
if (!context.env?.img_url) {
return apiError(
'SERVER_MISCONFIGURED',
'KV binding img_url is not configured.',
500
);
}
if (!isAuthRequired(context.env)) {
return context.next();
}
const authResult = await checkAuthentication(context);
if (authResult.authenticated) {
return context.next();
}
return apiError('UNAUTHORIZED', 'You need to login.', 401);
}