diff --git a/html/src/Components/ShareComponent.tsx b/html/src/Components/ShareComponent.tsx index 0089137..371d15a 100644 --- a/html/src/Components/ShareComponent.tsx +++ b/html/src/Components/ShareComponent.tsx @@ -1,5 +1,5 @@ import { ActionIcon, Anchor, Button, CopyButton, Group, Paper, Popover, Text, Tooltip } from "@mantine/core"; -import { Share } from "../hupload"; +import { humanFileSize, Share } from "../hupload"; import { Link } from "react-router-dom"; import classes from './ShareComponent.module.css'; import { IconLink, IconTrash } from "@tabler/icons-react"; @@ -16,6 +16,7 @@ export function ShareComponent(props: {share: Share}) { // Constants const key = share.name const name = share.name + const size = share.size // Function const deleteShare = () => { @@ -30,28 +31,31 @@ export function ShareComponent(props: {share: Share}) { {name} - - {({ copied, copy }) => ( - - - - - - )} - - - - - - + {humanFileSize(size)} + + + {({ copied, copy }) => ( + + + - - - Delete this share ? - - - + )} + + + + + + + + + + + Delete this share ? + + + + diff --git a/html/src/hupload.ts b/html/src/hupload.ts index 2b4cb18..8aaa7c3 100644 --- a/html/src/hupload.ts +++ b/html/src/hupload.ts @@ -1,6 +1,7 @@ export interface Share { name: string; owner: string; + size: number; } export interface Item { diff --git a/hupload/pkg/apiws/storageservice/storageservice.go b/hupload/pkg/apiws/storageservice/storageservice.go index d0665c8..f455c86 100644 --- a/hupload/pkg/apiws/storageservice/storageservice.go +++ b/hupload/pkg/apiws/storageservice/storageservice.go @@ -9,6 +9,7 @@ type Share struct { Name string `json:"name"` Created time.Time `json:"created"` Owner string `json:"owner"` + Size int64 `json:"size"` } type Item struct { diff --git a/hupload/pkg/apiws/storageservice/storageservicefile.go b/hupload/pkg/apiws/storageservice/storageservicefile.go index f7679d7..9afbd2b 100644 --- a/hupload/pkg/apiws/storageservice/storageservicefile.go +++ b/hupload/pkg/apiws/storageservice/storageservicefile.go @@ -108,7 +108,23 @@ func (b *FileBackend) ListShares() ([]Share, error) { continue } defer fm.Close() + + sd, err := os.ReadDir(path.Join(b.Options["path"].(string), f.Name())) + if err != nil { + continue + } m := Share{} + + for _, i := range sd { + if strings.HasPrefix(i.Name(), ".") { + continue + } + info, err := i.Info() + if err != nil { + continue + } + m.Size += info.Size() + } err = json.NewDecoder(fm).Decode(&m) if err != nil { return nil, err