[WIKI-181] refactor: make file handling generic in editor (#7046)

* refactor: make file handling generic

* fix: useeffect dependency array

* chore: remove mime type to extension conversion
This commit is contained in:
Aaryan Khandelwal 2025-05-12 18:37:36 +05:30 committed by GitHub
parent e68d344410
commit dc16f2862e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 334 additions and 223 deletions

View file

@ -0,0 +1,32 @@
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}`;
};
export const getFileExtension = (filename: string) => filename.slice(((filename.lastIndexOf(".") - 1) >>> 0) + 2);
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;
};

View file

@ -1,4 +1,5 @@
export * from "./array";
export * from "./attachment";
export * from "./auth";
export * from "./datetime";
export * from "./color";
@ -16,4 +17,3 @@ export * from "./work-item";
export * from "./get-icon-for-link";
export * from "./subscription";