Add file size to upload text and file size checks

This commit is contained in:
Jake 2019-04-12 16:21:07 +01:00
parent 76cbb2a77b
commit 27e79f0eec
No known key found for this signature in database
GPG Key ID: 1E172AEEACF8AE3D
2 changed files with 11 additions and 3 deletions

8
cli.js
View File

@ -54,7 +54,13 @@ async function upload(path) {
fileBytes(path).then(size => {
var sizeMib = size / 1048576;
var ret = ttmsh.retention(sizeMib);
console.log(`This file is expected to last approximately ${ret} days.`);
if (ret === -1) {
console.error(`This file is ~${sizeMib.toFixed(2)} MiB, which is over the limit of ${ttmsh.config.max_size} MiB!`);
return;
}
console.log(`This file is ~${sizeMib.toFixed(2)} MiB and last ~${ret} days.`);
// run the action, i.e upload the file
doAction("file", path);

View File

@ -2,15 +2,17 @@ const rp = require("request-promise");
const fs = require("fs");
const config = require("./config.json")
module.exports.config = config;
/**
* A function to calculate how long a file will last
*
* @param {integer} file_size How large the file is (MB)
* @returns An integer of how many days the file will last, or false if the file is too large.
* @returns An integer of how many days the file will last, or -1 if the file is too large.
*/
module.exports.retention = function(file_size) {
if (file_size > config["max_size"]) {
return false;
return -1;
}
return Math.floor(config["min_age"] + (-config["max_age"] + config["min_age"]) * Math.pow((file_size / config["max_size"] - 1), 3));