mirror of https://github.com/jetkvm/kvm.git
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:
parent
56968dede5
commit
136966a0a7
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue