Replies: 1 comment 1 reply
-
|
Interesting... shouldn't be very hard to calculate, here's a script to run in your Disbox browser tab. const getSHA256Hash = async (input) => {
const textAsBuffer = new TextEncoder().encode(input);
const hashBuffer = await window.crypto.subtle.digest("SHA-256", textAsBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hash = hashArray
.map((item) => item.toString(16).padStart(2, "0"))
.join("");
return hash;
};
function humanFileSize(size) {
var i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
return +((size / Math.pow(1024, i)).toFixed(2)) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
}
function getDirSize(dir) {
let size = 0;
for (child of Object.values(dir.children)) {
if (child.children === undefined) {
size += child.size
} else {
size += getDirSize(child)
}
}
return size;
}
async function getTotalSize(webhookUrl) {
const url = new URL(webhookUrl);
let fileTrees = {};
// Handle Discord changing webhook URLs
for (const hostname of ["discord.com", "discordapp.com"]) {
url.hostname = hostname;
const result = await fetch(`${'https://disbox-server.fly.dev'}/files/get/${await getSHA256Hash(url.href)}`);
if (result.status === 200) {
fileTrees[url.href] = await result.json();
}
}
if (fileTrees.length === 0) {
throw new Error(`Failed to get files for user.`);
}
// If one of them has entries, choose it no matter what the entered URL was.
const [chosenUrl, fileTree] = Object.entries(fileTrees).sort((f1, f2) => f2[1].length - f1[1].length)[0];
return getDirSize(fileTree);
}
console.log(`Your Disbox storage size is ${humanFileSize(await getTotalSize(localStorage.getItem("webhookUrl")))}`)Keep in mind that partial files (e.g. files that were paused mid-upload by a refresh) will not be calculated in this. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to see how many MBs/GBs are all files I've uploaded
Beta Was this translation helpful? Give feedback.
All reactions