mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-19 12:40:09 +01:00
Add exception handling for special case files like Dockerfile
and Jenkinsfile
(#2410)
This commit is contained in:
parent
5ac6020480
commit
93d64642f3
@ -38,7 +38,7 @@ async function processSingleFile(targetFilename, options = {}) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const fileExtension = path.extname(fullFilePath).toLowerCase();
|
const fileExtension = path.extname(fullFilePath).toLowerCase();
|
||||||
if (!fileExtension) {
|
if (fullFilePath.includes(".") && !fileExtension) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
reason: `No file extension found. This file cannot be processed.`,
|
reason: `No file extension found. This file cannot be processed.`,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const MimeLib = require("mime");
|
const MimeLib = require("mime");
|
||||||
|
const path = require("path");
|
||||||
class MimeDetector {
|
class MimeDetector {
|
||||||
nonTextTypes = ["multipart", "image", "model", "audio", "video"];
|
nonTextTypes = ["multipart", "image", "model", "audio", "video"];
|
||||||
badMimes = [
|
badMimes = [
|
||||||
@ -44,8 +44,26 @@ class MimeDetector {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are file types that are not detected by the mime library and need to be processed as text files.
|
||||||
|
// You should only add file types that are not detected by the mime library, are parsable as text, and are files
|
||||||
|
// with no extension. Otherwise, their extension should be added to the overrides array.
|
||||||
|
#specialTextFileTypes = ["dockerfile", "jenkinsfile"];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the MIME type of the file. If the file has no extension found, it will be processed as a text file.
|
||||||
|
* @param {string} filepath
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
getType(filepath) {
|
getType(filepath) {
|
||||||
return this.lib.getType(filepath);
|
const parsedMime = this.lib.getType(filepath);
|
||||||
|
if (!!parsedMime) return parsedMime;
|
||||||
|
|
||||||
|
// If the mime could not be parsed, it could be a special file type like Dockerfile or Jenkinsfile
|
||||||
|
// which we can reliably process as text files.
|
||||||
|
const baseName = path.basename(filepath)?.toLowerCase();
|
||||||
|
if (this.#specialTextFileTypes.includes(baseName)) return "text/plain";
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user