@websolutespa/payload-plugin-bowl-llm
Version:
LLM plugin for Bowl PayloadCms plugin
42 lines (41 loc) • 1.19 kB
JavaScript
import { ResponseOptions, ResponseSuccess, withCors } from '@websolutespa/payload-utils/server';
import { options } from '../options';
import { appHandler } from './app.handler';
import { errorHandler } from './error.handler';
export const userUploadHandler = async (req)=>{
if (req.method === 'OPTIONS') {
return ResponseOptions();
}
const headers = withCors({
req,
cors: '*'
});
try {
const app = await appHandler(req);
const uploadedFile = req.file;
if (!uploadedFile) {
throw {
status: 400,
message: 'Bad Request: No file uploaded'
};
}
const doc = await req.payload.create({
collection: options.slug.llmUserUpload,
data: {
llmApp: app.id
},
overrideAccess: true,
req,
file: uploadedFile
});
doc.url = `${doc.url}?t=${doc.id}`;
return ResponseSuccess(doc, {
headers
});
} catch (error) {
return errorHandler(error, {
headers
});
}
};
//# sourceMappingURL=userUpload.handler.js.map