mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 12:56:05 +00:00
fix media mime guessing when uploading to entity
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { randomString } from "core/utils";
|
||||
import { isFile, randomString } from "core/utils";
|
||||
import { extension } from "media/storage/mime-types-tiny";
|
||||
|
||||
export function getExtension(filename: string): string | undefined {
|
||||
export function getExtensionFromName(filename: string): string | undefined {
|
||||
if (!filename.includes(".")) return;
|
||||
|
||||
const parts = filename.split(".");
|
||||
@@ -17,6 +18,12 @@ export function getRandomizedFilename(file: File | string, length = 16): string
|
||||
throw new Error("Invalid file name");
|
||||
}
|
||||
|
||||
let ext = getExtensionFromName(filename);
|
||||
if (isFile(file) && file.type) {
|
||||
const _ext = extension(file.type);
|
||||
if (_ext.length > 0) ext = _ext;
|
||||
}
|
||||
|
||||
// @todo: use uuid instead?
|
||||
return [randomString(length), getExtension(filename)].filter(Boolean).join(".");
|
||||
return [randomString(length), ext].filter(Boolean).join(".");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user