fix auth freezing requests, fix ext extraction ?, fix upload not taking sanatized name, add file query and thumbnails

This commit is contained in:
creations 2025-03-12 12:54:25 -04:00
parent 6a55f9f5a9
commit b24b1484cb
Signed by: creations
GPG key ID: 8F553AA4320FC711
6 changed files with 264 additions and 19 deletions

View file

@ -109,16 +109,72 @@ export function getBaseUrl(request: Request): string {
return `${protocol}://${url.hostname}${portSegment}`;
}
// * File Specific Helpers
const knownExtensions: Set<string> = new Set([
"mp4",
"txt",
"pdf",
"gz",
"tar",
"zip",
"7z",
"rar",
"png",
"jpg",
"jpeg",
"webp",
"gif",
"js",
"ts",
"tsx",
"json",
"html",
"css",
"md",
"log",
"db",
"db3",
"sqlite",
"csv",
"xml",
"yaml",
"yml",
"toml",
"ini",
"cfg",
"conf",
"env",
"sh",
"bash",
"zsh",
"fish",
"ps1",
"bat",
"cmd",
"py",
"pyc",
"pyo",
"pyd",
"pyw",
"pyz",
"pyzw",
]);
export function getExtension(fileName: string): string | null {
return fileName.split(".").length > 1 && fileName.split(".").pop() !== ""
? (fileName.split(".").pop() ?? null)
: null;
const lastDotIndex: number = fileName.lastIndexOf(".");
if (lastDotIndex <= 0) return null;
const ext: string = fileName.slice(lastDotIndex + 1).toLowerCase();
return knownExtensions.has(ext) ? ext : null;
}
export function nameWithoutExtension(fileName: string): string {
const extension: string | null = getExtension(fileName);
return extension ? fileName.slice(0, -extension.length - 1) : fileName;
const lastDotIndex: number = fileName.lastIndexOf(".");
if (lastDotIndex <= 0) return fileName;
const ext: string = fileName.slice(lastDotIndex + 1).toLowerCase();
return knownExtensions.has(ext)
? fileName.slice(0, lastDotIndex)
: fileName;
}
export function supportsExif(mimeType: string, extension: string): boolean {