fix(ui): upload file size could not be parsed (#1011)

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Aveline 2025-11-27 10:52:08 +01:00 committed by GitHub
parent 56968dede5
commit 136966a0a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 25 deletions

View File

@ -503,6 +503,12 @@ function UrlView({
); );
} }
export interface StorageFile {
name: string;
size: string;
createdAt: Date;
}
function DeviceFileView({ function DeviceFileView({
onMountStorageFile, onMountStorageFile,
mountInProgress, mountInProgress,
@ -514,13 +520,7 @@ function DeviceFileView({
onBack: () => void; onBack: () => void;
onNewImageClick: (incompleteFileName?: string) => void; onNewImageClick: (incompleteFileName?: string) => void;
}) { }) {
const [onStorageFiles, setOnStorageFiles] = useState< const [onStorageFiles, setOnStorageFiles] = useState<StorageFile[]>([]);
{
name: string;
size: string;
createdAt: string;
}[]
>([]);
const [selected, setSelected] = useState<string | null>(null); const [selected, setSelected] = useState<string | null>(null);
const [usbMode, setUsbMode] = useState<RemoteVirtualMediaState["mode"]>("CDROM"); const [usbMode, setUsbMode] = useState<RemoteVirtualMediaState["mode"]>("CDROM");
@ -565,7 +565,7 @@ function DeviceFileView({
const formattedFiles = files.map(file => ({ const formattedFiles = files.map(file => ({
name: file.filename, name: file.filename,
size: formatters.bytes(file.size), size: formatters.bytes(file.size),
createdAt: formatters.date(new Date(file?.createdAt)), createdAt: new Date(file?.createdAt),
})); }));
setOnStorageFiles(formattedFiles); setOnStorageFiles(formattedFiles);
@ -582,10 +582,6 @@ function DeviceFileView({
}); });
}, [send, setOnStorageFiles, setStorageSpace]); }, [send, setOnStorageFiles, setStorageSpace]);
useEffect(() => {
syncStorage();
}, [syncStorage]);
interface StorageFiles { interface StorageFiles {
files: { files: {
filename: string; filename: string;
@ -598,7 +594,7 @@ function DeviceFileView({
syncStorage(); syncStorage();
}, [syncStorage]); }, [syncStorage]);
function handleDeleteFile(file: { name: string; size: string; createdAt: string }) { function handleDeleteFile(file: StorageFile) {
console.log("Deleting file:", file); console.log("Deleting file:", file);
send("deleteStorageFile", { filename: file.name }, (resp: JsonRpcResponse) => { send("deleteStorageFile", { filename: file.name }, (resp: JsonRpcResponse) => {
if ("error" in resp) { if ("error" in resp) {
@ -610,7 +606,7 @@ function DeviceFileView({
}); });
} }
function handleOnSelectFile(file: { name: string; size: string; createdAt: string }) { function handleOnSelectFile(file: StorageFile) {
setSelected(file.name); setSelected(file.name);
if (file.name.endsWith(".iso")) { if (file.name.endsWith(".iso")) {
setUsbMode("CDROM"); setUsbMode("CDROM");
@ -1292,7 +1288,7 @@ function PreUploadedImageItem({
}: { }: {
name: string; name: string;
size: string; size: string;
uploadedAt: string; uploadedAt: Date;
isSelected: boolean; isSelected: boolean;
isIncomplete: boolean; isIncomplete: boolean;
onSelect: () => void; onSelect: () => void;

View File

@ -1,10 +1,12 @@
import { KeySequence } from "@hooks/stores"; import { KeySequence } from "@hooks/stores";
import { getLocale , locales } from "@localizations/runtime.js"; import { getLocale, locales } from "@localizations/runtime.js";
import { m } from "@localizations/messages.js"; import { m } from "@localizations/messages.js";
const isInvalidDate = (date: Date) => date instanceof Date && isNaN(date.getTime());
export const formatters = { export const formatters = {
date: (date: Date, options?: Intl.DateTimeFormatOptions) => date: (date: Date, options?: Intl.DateTimeFormatOptions) =>
new Intl.DateTimeFormat(getLocale() || "en-US", { isInvalidDate(date) ? "Invalid Date" : new Intl.DateTimeFormat(getLocale() || "en-US", {
year: "numeric", year: "numeric",
month: "long", month: "long",
day: "numeric", day: "numeric",
@ -46,14 +48,14 @@ export const formatters = {
amount: number; amount: number;
name: Intl.RelativeTimeFormatUnit; name: Intl.RelativeTimeFormatUnit;
}[] = [ }[] = [
{ amount: 60, name: "seconds" }, { amount: 60, name: "seconds" },
{ amount: 60, name: "minutes" }, { amount: 60, name: "minutes" },
{ amount: 24, name: "hours" }, { amount: 24, name: "hours" },
{ amount: 7, name: "days" }, { amount: 7, name: "days" },
{ amount: 4.34524, name: "weeks" }, { amount: 4.34524, name: "weeks" },
{ amount: 12, name: "months" }, { amount: 12, name: "months" },
{ amount: Number.POSITIVE_INFINITY, name: "years" }, { amount: Number.POSITIVE_INFINITY, name: "years" },
]; ];
let duration = (date.valueOf() - new Date().valueOf()) / 1000; let duration = (date.valueOf() - new Date().valueOf()) / 1000;