add moment and child_process

This commit is contained in:
Liam
2022-11-14 00:45:20 +00:00
parent a20f6c88c9
commit 63c94365ce
8 changed files with 103 additions and 15 deletions

View File

@ -84,6 +84,7 @@ export async function createFile(
const file = await FileModel.create({
uploader: uploader._id,
fileId: fileId,
originalFileName: fileName,
uploadDate: new Date(),
contentType: contentType,
ext: extention,

View File

@ -14,3 +14,22 @@ export function randomString(length) {
}
return result;
}
/**
* Returns the given bytes formatted
*
* @param {Number} bytes The bytes amount
* @param {Number} decimals The amount of decimals to show
* @returns
*/
export function formatBytes(bytes, decimals = 2) {
if (!+bytes) return "0 Bytes";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
}

View File

@ -0,0 +1,8 @@
export function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}