mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat: add .svg support (#3229)
This commit is contained in:
@@ -98,7 +98,7 @@ export function isBinaryFile(filePath: string): boolean {
|
||||
*/
|
||||
export function detectFileType(
|
||||
filePath: string,
|
||||
): 'text' | 'image' | 'pdf' | 'audio' | 'video' | 'binary' {
|
||||
): 'text' | 'image' | 'pdf' | 'audio' | 'video' | 'binary' | 'svg' {
|
||||
const ext = path.extname(filePath).toLowerCase();
|
||||
|
||||
// The mimetype for "ts" is MPEG transport stream (a video format) but we want
|
||||
@@ -107,6 +107,10 @@ export function detectFileType(
|
||||
return 'text';
|
||||
}
|
||||
|
||||
if (ext === '.svg') {
|
||||
return 'svg';
|
||||
}
|
||||
|
||||
const lookedUpMimeType = mime.lookup(filePath); // Returns false if not found, or the mime type string
|
||||
if (lookedUpMimeType) {
|
||||
if (lookedUpMimeType.startsWith('image/')) {
|
||||
@@ -235,6 +239,20 @@ export async function processSingleFileContent(
|
||||
returnDisplay: `Skipped binary file: ${relativePathForDisplay}`,
|
||||
};
|
||||
}
|
||||
case 'svg': {
|
||||
const SVG_MAX_SIZE_BYTES = 1 * 1024 * 1024;
|
||||
if (stats.size > SVG_MAX_SIZE_BYTES) {
|
||||
return {
|
||||
llmContent: `Cannot display content of SVG file larger than 1MB: ${relativePathForDisplay}`,
|
||||
returnDisplay: `Skipped large SVG file (>1MB): ${relativePathForDisplay}`,
|
||||
};
|
||||
}
|
||||
const content = await fs.promises.readFile(filePath, 'utf8');
|
||||
return {
|
||||
llmContent: content,
|
||||
returnDisplay: `Read SVG as text: ${relativePathForDisplay}`,
|
||||
};
|
||||
}
|
||||
case 'text': {
|
||||
const content = await fs.promises.readFile(filePath, 'utf8');
|
||||
const lines = content.split('\n');
|
||||
|
||||
Reference in New Issue
Block a user