Added approximate file size to download button when available.

This commit is contained in:
Christian Bastian
2024-07-24 14:53:15 -04:00
parent 364fe7f6e2
commit de3e2a9693
2 changed files with 28 additions and 1 deletions

View File

@@ -337,6 +337,10 @@
row-gap: 16px;
}
.model-manager .download-button {
max-width: fit-content;
}
/* models tab */
.model-manager [data-name="Models"] .row {
position: sticky;

View File

@@ -3157,6 +3157,28 @@ class DownloadView {
return null;
}
/**
* Returns empty string on failure
* @param {float | undefined} fileSizeKB
* @returns {string}
*/
static #fileSizeToFormattedString(fileSizeKB) {
if (fileSizeKB === undefined) { return ""; }
const sizes = ["KB", "MB", "GB", "TB", "PB"];
let fileSizeString = fileSizeKB.toString();
const index = fileSizeString.indexOf(".");
const indexMove = index % 3 === 0 ? 3 : index % 3;
const sizeIndex = Math.floor((index - indexMove) / 3);
if (sizeIndex >= sizes.length || sizeIndex < 0) {
fileSizeString = fileSizeString.substring(0, fileSizeString.indexOf(".") + 3);
return `(${fileSizeString} ${sizes[0]})`;
}
const split = fileSizeString.split(".");
fileSizeString = split[0].substring(0, indexMove) + "." + split[0].substring(indexMove) + split[1];
fileSizeString = fileSizeString.substring(0, fileSizeString.indexOf(".") + 3);
return `(${fileSizeString} ${sizes[sizeIndex]})`;
}
/**
* @param {Object} info
* @param {ModelData} modelData
@@ -3221,7 +3243,8 @@ class DownloadView {
new ComfyButton({
icon: "arrow-collapse-down",
tooltip: "Download model",
classList: "comfyui-button icon-button",
content: "Download " + DownloadView.#fileSizeToFormattedString(info["details"]["fileSizeKB"]),
classList: "comfyui-button download-button",
action: async (e) => {
const pathDirectory = el_saveDirectoryPath.value;
const modelName = (() => {