Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Added filesize to items on dav explore page.
nzbdav-dev244e80349885
diff --git a/frontend/app/routes/explore/route.module.css b/frontend/app/routes/explore/route.module.cssindex 08d1ed06..0faa2290 100644--- a/frontend/app/routes/explore/route.module.css+++ b/frontend/app/routes/explore/route.module.css@@ -86,11 +86,25 @@background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cg fill='%2393a1a1'%3E%3Cpath d='M6.002 5.5a1.5 1.5 0 1 1-3 0a1.5 1.5 0 0 1 3 0'/%3E%3Cpath d='M2.002 1a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V3a2 2 0 0 0-2-2zm12 1a1 1 0 0 1 1 1v6.5l-3.777-1.947a.5.5 0 0 0-.577.093l-3.71 3.71l-2.66-1.772a.5.5 0 0 0-.63.062L1.002 12V3a1 1 0 0 1 1-1z'/%3E%3C/g%3E%3C/svg%3E");}+.item-info {+ display: flex;+ flex-direction: column;+ line-height: 1;+ gap: 5px;+ transform: translateY(2px);+}+.item-name {word-break: break-all;overflow-wrap: break-word;}+.item-size {+ font-size: 12px;+ color: #586e75;+ opacity: 0.8;+}+.loading {width: calc(100% - 75px);flex-grow: 1;diff --git a/frontend/app/routes/explore/route.module.css.d.ts b/frontend/app/routes/explore/route.module.css.d.tsindex b1a037d9..a2e27103 100644--- a/frontend/app/routes/explore/route.module.css.d.ts+++ b/frontend/app/routes/explore/route.module.css.d.ts@@ -4,7 +4,9 @@ declare const styles: {readonly "file-icon": string;readonly "image-icon": string;readonly "item": string;+ readonly "item-info": string;readonly "item-name": string;+ readonly "item-size": string;readonly "video-icon": string;readonly "loading": string;readonly "hidden": string;diff --git a/frontend/app/routes/explore/route.tsx b/frontend/app/routes/explore/route.tsxindex 81dd1dbb..57130a6a 100644--- a/frontend/app/routes/explore/route.tsx+++ b/frontend/app/routes/explore/route.tsx@@ -7,6 +7,7 @@ import { useCallback } from "react";import { lookup as getMimeType } from 'mime-types';import { getDownloadKey } from "~/auth/downloads.server";import { Loading } from "../_index/components/loading/loading";+import { formatFileSize } from "~/utils/file-size";export type ExplorePageData = {parentDirectories: string[],@@ -77,7 +78,10 @@ function Body(props: ExplorePageData) {{items.filter(x => !x.isDirectory).map((x, index) =><a key={`${index}_file_item`} href={getFilePath(x as ExploreFile)} className={getClassName(x)}><div className={getIcon(x as ExploreFile)} />- <div className={styles["item-name"]}>{x.name}</div>+ <div className={styles["item-info"]}>+ <div className={styles["item-name"]}>{x.name}</div>+ <div className={styles["item-size"]}>{formatFileSize(x.size)}</div>+ </div></a>)}</div>diff --git a/frontend/app/routes/queue/components/page-table/page-table.tsx b/frontend/app/routes/queue/components/page-table/page-table.tsxindex 5f52f42d..4f690576 100644--- a/frontend/app/routes/queue/components/page-table/page-table.tsx+++ b/frontend/app/routes/queue/components/page-table/page-table.tsx@@ -4,6 +4,7 @@ import type { ReactNode } from "react";import { TriCheckbox, type TriCheckboxState } from "../tri-checkbox/tri-checkbox";import { Truncate } from "../truncate/truncate";import { StatusBadge } from "../status-badge/status-badge";+import { formatFileSize } from "~/utils/file-size";export type PageTableProps = {striped?: boolean,@@ -88,14 +89,4 @@ export function CategoryBadge({ category }: { category: string }) {if (categoryLower === 'movies') variant = 'primary';if (categoryLower === 'tv') variant = 'info';return <Badge bg={variant} style={{ width: '85px' }}>{categoryLower}</Badge>-}--export function formatFileSize(bytes: number) {- var suffix = "B";- if (bytes >= 1024) { bytes /= 1024; suffix = "KB"; }- if (bytes >= 1024) { bytes /= 1024; suffix = "MB"; }- if (bytes >= 1024) { bytes /= 1024; suffix = "GB"; }- if (bytes >= 1024) { bytes /= 1024; suffix = "TB"; }- if (bytes >= 1024) { bytes /= 1024; suffix = "PB"; }- return `${bytes.toFixed(2)} ${suffix}`;}\ No newline at end of filediff --git a/frontend/app/utils/file-size.ts b/frontend/app/utils/file-size.tsnew file mode 100644index 00000000..efa5e27c--- /dev/null+++ b/frontend/app/utils/file-size.ts@@ -0,0 +1,10 @@+export function formatFileSize(bytes: number | null | undefined) {+ var suffix = "B";+ if (bytes === null || bytes === undefined) return "unknown size"+ if (bytes >= 1024) { bytes /= 1024; suffix = "KB"; }+ if (bytes >= 1024) { bytes /= 1024; suffix = "MB"; }+ if (bytes >= 1024) { bytes /= 1024; suffix = "GB"; }+ if (bytes >= 1024) { bytes /= 1024; suffix = "TB"; }+ if (bytes >= 1024) { bytes /= 1024; suffix = "PB"; }+ return `${parseFloat(bytes.toFixed(2))} ${suffix}`;+}\ No newline at end of file