mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-15 20:17:22 +00:00
keep extension from file when generating random name (#127)
* keep extension from file when generating random name * added test for random name generation
This commit is contained in:
@@ -96,5 +96,10 @@ describe("media/mime-types", () => {
|
||||
`getRandomizedFilename(): ${filename} should end with ${ext}`,
|
||||
).toBe(ext);
|
||||
}
|
||||
|
||||
// make sure it keeps the extension, even if the file has a different type
|
||||
const file = new File([""], "image.jpg", { type: "text/plain" });
|
||||
const [, ext] = getRandomizedFilename(file).split(".");
|
||||
expect(ext).toBe("jpg");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ export function getRandomizedFilename(file: File | string, length = 16): string
|
||||
}
|
||||
|
||||
let ext = getExtensionFromName(filename);
|
||||
if (isFile(file) && file.type) {
|
||||
if (!ext && isFile(file) && file.type) {
|
||||
const _ext = extension(file.type);
|
||||
if (_ext.length > 0) ext = _ext;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user