web/ProcessingQueue: add estimated storage usage

This commit is contained in:
wukko 2025-02-06 22:56:05 +06:00
parent 7a042e3bfa
commit cff47da742
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
3 changed files with 55 additions and 15 deletions

View File

@ -7,5 +7,6 @@
"state.waiting": "queued", "state.waiting": "queued",
"state.starting": "starting...", "state.starting": "starting...",
"state.running.remux": "remuxing", "state.running.remux": "remuxing",
"state.running.fetch": "downloading" "state.running.fetch": "downloading",
"estimated_storage_usage": "estimated storage usage:"
} }

View File

@ -3,7 +3,8 @@
import { onNavigate } from "$app/navigation"; import { onNavigate } from "$app/navigation";
import { onMount, type SvelteComponent } from "svelte"; import { onMount, type SvelteComponent } from "svelte";
import { clearFileStorage } from "$lib/storage"; import { formatFileSize } from "$lib/util";
import { clearFileStorage, getStorageQuota } from "$lib/storage";
import { currentTasks } from "$lib/state/queen-bee/current-tasks"; import { currentTasks } from "$lib/state/queen-bee/current-tasks";
import { clearQueue, queue as readableQueue } from "$lib/state/queen-bee/queue"; import { clearQueue, queue as readableQueue } from "$lib/state/queen-bee/queue";
@ -20,6 +21,13 @@
$: queue = Object.entries($readableQueue); $: queue = Object.entries($readableQueue);
let quotaUsage = 0;
const updateQuota = async () => {
const storageInfo = await getStorageQuota();
quotaUsage = storageInfo?.usage || 0;
}
const totalItemProgress = (completed: number, current: number, total: number) => { const totalItemProgress = (completed: number, current: number, total: number) => {
return (completed * 100 + current) / total return (completed * 100 + current) / total
} }
@ -41,6 +49,7 @@
const popoverAction = async () => { const popoverAction = async () => {
expanded = !expanded; expanded = !expanded;
if (expanded) updateQuota();
}; };
onNavigate(() => { onNavigate(() => {
@ -68,6 +77,7 @@
expandStart="right" expandStart="right"
> >
<div id="processing-header"> <div id="processing-header">
<div class="header-top">
<SectionHeading <SectionHeading
title={$t("queue.title")} title={$t("queue.title")}
sectionId="queue" sectionId="queue"
@ -76,13 +86,23 @@
/> />
<div class="header-buttons"> <div class="header-buttons">
{#if queue.length} {#if queue.length}
<button class="clear-button" on:click={clearQueue}> <button class="clear-button" on:click={() => {
clearQueue();
updateQuota();
}}>
<IconX /> <IconX />
{$t("button.clear")} {$t("button.clear")}
</button> </button>
{/if} {/if}
</div> </div>
</div> </div>
{#if quotaUsage}
<div class="storage-info">
{$t("queue.estimated_storage_usage")} {formatFileSize(quotaUsage)}
</div>
{/if}
</div>
<div id="processing-list"> <div id="processing-list">
{#each queue as [id, item]} {#each queue as [id, item]}
<ProcessingQueueItem <ProcessingQueueItem
@ -127,6 +147,13 @@
} }
#processing-header { #processing-header {
display: flex;
flex-direction: column;
flex-wrap: wrap;
gap: 4px;
}
.header-top {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between; justify-content: space-between;
@ -135,6 +162,11 @@
gap: 6px; gap: 6px;
} }
.storage-info {
font-size: 12px;
color: var(--gray);
}
.header-buttons { .header-buttons {
display: flex; display: flex;
flex-direction: row; flex-direction: row;

View File

@ -64,3 +64,10 @@ export const clearFileStorage = async () => {
} }
} }
export const getStorageQuota = async () => {
let estimate;
if (navigator.storage.estimate) {
estimate = await navigator.storage.estimate();
}
return estimate;
}