θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collector/processSingleFile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function processSingleFile(targetFilename, options = {}) {
};

const fileExtension = path.extname(fullFilePath).toLowerCase();
if (!fileExtension) {
if (fullFilePath.includes(".") && !fileExtension) {
return {
success: false,
reason: `No file extension found. This file cannot be processed.`,
Expand Down
22 changes: 20 additions & 2 deletions collector/utils/files/mime.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const MimeLib = require("mime");

const path = require("path");
class MimeDetector {
nonTextTypes = ["multipart", "image", "model", "audio", "video"];
badMimes = [
Expand Down Expand Up @@ -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) {
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;
}
}

Expand Down