Fixed issue with upload doctype
This commit is contained in:
@@ -40,12 +40,27 @@ function createKnowledgeBaseRouter(db, upload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POST /api/knowledge-base/upload - Upload new document
|
// POST /api/knowledge-base/upload - Upload new document
|
||||||
router.post('/upload', requireAuth(db), requireRole(db, 'editor', 'admin'), upload.single('file'), async (req, res) => {
|
router.post('/upload', requireAuth(db), requireRole(db, 'editor', 'admin'), (req, res, next) => {
|
||||||
|
upload.single('file')(req, res, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('[KB Upload] Multer error:', err);
|
||||||
|
return res.status(400).json({ error: err.message || 'File upload failed' });
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
}, async (req, res) => {
|
||||||
|
console.log('[KB Upload] Request received:', {
|
||||||
|
hasFile: !!req.file,
|
||||||
|
body: req.body,
|
||||||
|
contentType: req.headers['content-type']
|
||||||
|
});
|
||||||
|
|
||||||
const uploadedFile = req.file;
|
const uploadedFile = req.file;
|
||||||
const { title, description, category } = req.body;
|
const { title, description, category } = req.body;
|
||||||
|
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
if (!title || !title.trim()) {
|
if (!title || !title.trim()) {
|
||||||
|
console.error('[KB Upload] Error: Title is missing');
|
||||||
if (uploadedFile) fs.unlinkSync(uploadedFile.path);
|
if (uploadedFile) fs.unlinkSync(uploadedFile.path);
|
||||||
return res.status(400).json({ error: 'Title is required' });
|
return res.status(400).json({ error: 'Title is required' });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,7 +108,11 @@ app.use(cors({
|
|||||||
origin: CORS_ORIGINS,
|
origin: CORS_ORIGINS,
|
||||||
credentials: true
|
credentials: true
|
||||||
}));
|
}));
|
||||||
app.use(express.json({ limit: '1mb' }));
|
// Only parse JSON for requests with application/json content type
|
||||||
|
app.use(express.json({
|
||||||
|
limit: '1mb',
|
||||||
|
type: 'application/json'
|
||||||
|
}));
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use('/uploads', express.static('uploads', {
|
app.use('/uploads', express.static('uploads', {
|
||||||
dotfiles: 'deny',
|
dotfiles: 'deny',
|
||||||
|
|||||||
Reference in New Issue
Block a user