Reject mismatched uploads; add local mock AI runner
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
parent
75158c4449
commit
c59591ccb9
2 changed files with 13 additions and 1 deletions
8
scripts/mock-ai.ts
Normal file
8
scripts/mock-ai.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// Runs the scripted OpenAI-compatible mock used by the tests, so the AI features can be tried
|
||||
// locally without a real provider:
|
||||
// npx tsx scripts/mock-ai.ts
|
||||
// Then add an "OpenAI-compatible" provider with URL http://localhost:4010/v1 and key "mock-key".
|
||||
import { startMockAi } from '../tests/mockAi.ts';
|
||||
|
||||
const mock = await startMockAi(Number(process.env.MOCK_AI_PORT ?? 4010));
|
||||
console.log(`Mock AI provider listening at ${mock.url} (API key: mock-key)`);
|
||||
|
|
@ -108,7 +108,11 @@ export function ingestUpload(
|
|||
throw new HttpError(413, 'too_large', `"${input.filename}" is larger than the ${Math.round(app.config.maxUploadBytes / 1048576)} MB upload limit.`);
|
||||
}
|
||||
const filename = path.basename(input.filename.replace(/\\/g, '/')).slice(0, 200) || 'upload';
|
||||
const kind = detectKind(filename, input.mime, input.bytes);
|
||||
let kind = detectKind(filename, input.mime, input.bytes);
|
||||
// A file whose name claims a binary format but whose bytes say otherwise (a renamed
|
||||
// executable, say) is refused here instead of being stored and failing later.
|
||||
if (kind === 'pdf' && !Buffer.from(input.bytes.subarray(0, 1024)).includes('%PDF')) kind = null;
|
||||
if ((kind === 'docx' || kind === 'pptx') && !(input.bytes[0] === 0x50 && input.bytes[1] === 0x4b) && !(input.bytes[0] === 0xd0 && input.bytes[1] === 0xcf)) kind = null;
|
||||
if (!kind) {
|
||||
throw new HttpError(415, 'unsupported_type', `"${filename}" is not a supported file type. Upload PDF, Word (.docx), PowerPoint (.pptx), text, Markdown, or an image.`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue