finish api and docs validation fixes
This commit is contained in:
@@ -198,7 +198,7 @@ function uploadedFileToPart(file: Express.Multer.File): GeminiPart {
|
||||
return {
|
||||
inlineData: {
|
||||
data: file.buffer.toString('base64'),
|
||||
mimeType: file.mimetype || 'application/octet-stream',
|
||||
mimeType: inferMimeType(file),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -219,6 +219,30 @@ function normalizeTextInput(value: unknown) {
|
||||
return value == null ? '' : String(value);
|
||||
}
|
||||
|
||||
function inferMimeType(file: Express.Multer.File) {
|
||||
if (file.mimetype && file.mimetype !== 'application/octet-stream') {
|
||||
return file.mimetype;
|
||||
}
|
||||
|
||||
const ext = path.extname(file.originalname || '').toLowerCase();
|
||||
const mimeByExt: Record<string, string> = {
|
||||
'.png': 'image/png',
|
||||
'.jpg': 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.webp': 'image/webp',
|
||||
'.gif': 'image/gif',
|
||||
'.pdf': 'application/pdf',
|
||||
'.txt': 'text/plain',
|
||||
'.md': 'text/plain',
|
||||
'.csv': 'text/csv',
|
||||
'.json': 'application/json',
|
||||
'.html': 'text/html',
|
||||
'.htm': 'text/html',
|
||||
};
|
||||
|
||||
return mimeByExt[ext] || 'application/octet-stream';
|
||||
}
|
||||
|
||||
async function buildParts(body: GenerateRequest, files: Express.Multer.File[] = []) {
|
||||
const prompt = normalizeTextInput(body.prompt || body.instruction).trim();
|
||||
if (!prompt) {
|
||||
|
||||
Reference in New Issue
Block a user