|
|
@@ -8,8 +8,51 @@ export type PaasGeneratedFile = {
|
|
|
size?: number
|
|
|
}
|
|
|
|
|
|
+export type PaasFileCategory = "document" | "image" | "data" | "code" | "other"
|
|
|
+
|
|
|
const technicalExtensions = new Set(["json", "jsonl", "yaml", "yml", "toml", "ini", "cfg", "log", "lock"])
|
|
|
|
|
|
+const codeExtensions = new Set([
|
|
|
+ "py",
|
|
|
+ "pyw",
|
|
|
+ "ipynb",
|
|
|
+ "sh",
|
|
|
+ "bash",
|
|
|
+ "zsh",
|
|
|
+ "ps1",
|
|
|
+ "bat",
|
|
|
+ "cmd",
|
|
|
+ "js",
|
|
|
+ "jsx",
|
|
|
+ "mjs",
|
|
|
+ "cjs",
|
|
|
+ "ts",
|
|
|
+ "tsx",
|
|
|
+ "r",
|
|
|
+ "rb",
|
|
|
+ "go",
|
|
|
+ "rs",
|
|
|
+ "c",
|
|
|
+ "h",
|
|
|
+ "cc",
|
|
|
+ "cpp",
|
|
|
+ "cxx",
|
|
|
+ "hpp",
|
|
|
+ "java",
|
|
|
+ "kt",
|
|
|
+ "swift",
|
|
|
+ "php",
|
|
|
+ "lua",
|
|
|
+ "pl",
|
|
|
+ "sql",
|
|
|
+ "css",
|
|
|
+ "scss",
|
|
|
+])
|
|
|
+
|
|
|
+const dataCategoryExtensions = new Set([...technicalExtensions, "csv", "tsv"])
|
|
|
+
|
|
|
+const extension = (name: string) => name.split(".").pop()?.toLocaleLowerCase()
|
|
|
+
|
|
|
export function groupPaasFiles<T extends { name: string; mime?: string }>(files: T[]) {
|
|
|
const unique = Array.from(new Map(files.map((file) => [file.name.trim().toLocaleLowerCase(), file])).values())
|
|
|
const technical = unique.filter((file) => isTechnicalFile(file))
|
|
|
@@ -20,10 +63,21 @@ export function groupPaasFiles<T extends { name: string; mime?: string }>(files:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+export function paasFileCategory(file: { name: string; mime?: string }): PaasFileCategory {
|
|
|
+ const kind = paasPreviewKind(file.name, file.mime || "")
|
|
|
+ if (kind === "image") return "image"
|
|
|
+ const value = extension(file.name)
|
|
|
+ if (value && codeExtensions.has(value)) return "code"
|
|
|
+ if (value && dataCategoryExtensions.has(value)) return "data"
|
|
|
+ if (kind === "markdown" || kind === "pdf" || kind === "text") return "document"
|
|
|
+ return "other"
|
|
|
+}
|
|
|
+
|
|
|
function isTechnicalFile(file: { name: string; mime?: string }) {
|
|
|
- const extension = file.name.split(".").pop()?.toLocaleLowerCase()
|
|
|
+ const value = extension(file.name)
|
|
|
return (
|
|
|
- (!!extension && technicalExtensions.has(extension)) ||
|
|
|
+ (!!value && technicalExtensions.has(value)) ||
|
|
|
+ (!!value && codeExtensions.has(value)) ||
|
|
|
paasPreviewKind(file.name, file.mime || "") === "unsupported"
|
|
|
)
|
|
|
}
|