[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:
parent
e68d344410
commit
dc16f2862e
17 changed files with 334 additions and 223 deletions
32
packages/utils/src/attachment.ts
Normal file
32
packages/utils/src/attachment.ts
Normal 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;
|
||||
};
|
||||
|
|
@ -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";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue