2024-01-28 13:00:53 +00:00
|
|
|
export const generateFileName = (fileName: string) => {
|
|
|
|
const date = new Date();
|
|
|
|
const timestamp = date.getTime();
|
|
|
|
|
|
|
|
const _fileName = getFileName(fileName);
|
|
|
|
const nameWithoutExtension = _fileName.length > 80 ? _fileName.substring(0, 80) : _fileName;
|
|
|
|
const extension = getFileExtension(fileName);
|
|
|
|
|
|
|
|
return `${nameWithoutExtension}-${timestamp}.${extension}`;
|
|
|
|
};
|
|
|
|
|
2023-11-08 15:01:46 +00:00
|
|
|
export const getFileExtension = (filename: string) => filename.slice(((filename.lastIndexOf(".") - 1) >>> 0) + 2);
|
2023-04-06 09:37:11 +00:00
|
|
|
|
|
|
|
export const getFileName = (fileName: string) => {
|
|
|
|
const dotIndex = fileName.lastIndexOf(".");
|
|
|
|
|
|
|
|
const nameWithoutExtension = fileName.substring(0, dotIndex);
|
|
|
|
|
|
|
|
return nameWithoutExtension;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const convertBytesToSize = (bytes: number) => {
|
|
|
|
let size;
|
|
|
|
|
|
|
|
if (bytes < 1024 * 1024) {
|
|
|
|
size = Math.round(bytes / 1024) + " KB";
|
|
|
|
} else {
|
|
|
|
size = Math.round(bytes / (1024 * 1024)) + " MB";
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
};
|