( filePath: string, options?: CommandOptions, index?: number, maxCharacters?: number, settings?: typeof defaultAdvancedSettings, )
| 80 | }; |
| 81 | |
| 82 | export async function getFileContent( |
| 83 | filePath: string, |
| 84 | options?: CommandOptions, |
| 85 | index?: number, |
| 86 | maxCharacters?: number, |
| 87 | settings?: typeof defaultAdvancedSettings, |
| 88 | ) { |
| 89 | const options_ = |
| 90 | options == undefined |
| 91 | ? { |
| 92 | useMetadata: true, |
| 93 | useAudioDetails: true, |
| 94 | useSoundClassification: true, |
| 95 | useSubjectClassification: true, |
| 96 | useFaceDetection: true, |
| 97 | useBarcodeDetection: true, |
| 98 | useRectangleDetection: true, |
| 99 | useSaliencyAnalysis: true, |
| 100 | } |
| 101 | : options; |
| 102 | |
| 103 | if (maxCharacters == undefined) { |
| 104 | const items = await LocalStorage.allItems(); |
| 105 | const modelObjs: Model[] = Object.entries(items) |
| 106 | .filter(([key]) => key.startsWith("--model-")) |
| 107 | .map(([, value]) => JSON.parse(value)) |
| 108 | .sort((a, b) => a.name.localeCompare(b.name)); |
| 109 | |
| 110 | let model = options?.model ? modelObjs.find((m) => m.name == options.model) : undefined; |
| 111 | if (!model) model = modelObjs.find((m) => m.isDefault) || modelObjs[0]; |
| 112 | maxCharacters = model ? parseInt(model.lengthLimit) : 3000; |
| 113 | } |
| 114 | |
| 115 | if (settings == undefined) { |
| 116 | settings = loadAdvancedSettingsSync(); |
| 117 | } |
| 118 | |
| 119 | const currentData = { |
| 120 | contents: `{${index == undefined ? "" : `File #${index + 1} - `}${path.basename(filePath)}}:\n`, |
| 121 | }; |
| 122 | |
| 123 | const filepath = filePath.toLowerCase(); |
| 124 | if (isTextFile(filepath)) addTextFileDetails(filepath, currentData); |
| 125 | |
| 126 | if (isTrueDirectory(filepath)) addDirectoryDetails(filepath, currentData); |
| 127 | else if (isApp(filepath)) await addAppDetails(filepath, currentData, options_); |
| 128 | else if (isPDF(filepath)) await addPDFDetails(filepath, currentData, options_); |
| 129 | else if (isVideoFile(filepath)) await addVideoDetails(filepath, currentData, options_, settings); |
| 130 | else if (isAudioFile(filepath)) await addAudioDetails(filepath, currentData, options_); |
| 131 | else if (isImageFile(filepath)) await addImageDetails(filepath, currentData, options_); |
| 132 | else if (isTextFile(filepath)) addTextFileDetails(filepath, currentData); |
| 133 | else if (isOfficeFile(filepath)) await addOfficeDetails(filepath, currentData); |
| 134 | else if (isSpreadsheet(filepath)) await addSpreadsheetDetails(filepath, currentData); |
| 135 | else if (filepath.endsWith(".pages")) await addPagesDetails(filepath, currentData); |
| 136 | else if (filepath.endsWith(".key")) await addKeynoteDetails(filepath, currentData, settings); |
| 137 | else if (!isTextFile(filepath)) attemptAddRawText(filepath, currentData); |
| 138 | |
| 139 | if (options_.useMetadata) addMetadataDetails(filepath, currentData); |
no test coverage detected