Files
web_app/src/core/TextFilePolicy.js

21 lines
608 B
JavaScript

export class TextFilePolicy {
constructor() {
this.maxSizeBytes = 1 * 1024 * 1024;
this.allowedExtensions = new Set([
".txt", ".md", ".json", ".xml", ".yaml", ".yml", ".js", ".jsx", ".ts", ".tsx",
".css", ".html", ".py", ".java", ".go", ".rs", ".sql", ".sh", ".env", ".ini", ".toml"
]);
}
isTextPath(path) {
const idx = path.lastIndexOf(".");
if (idx === -1) return true;
const ext = path.slice(idx).toLowerCase();
return this.allowedExtensions.has(ext);
}
isSupportedFile(path, size) {
return this.isTextPath(path) && size <= this.maxSizeBytes;
}
}