Add file size to upload text and file size checks
This commit is contained in:
parent
76cbb2a77b
commit
27e79f0eec
8
cli.js
8
cli.js
|
@ -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);
|
||||
|
|
6
index.js
6
index.js
|
@ -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));
|
||||
|
|
Reference in New Issue