Skip to content

Commit

Permalink
new: display share total size
Browse files Browse the repository at this point in the history
  • Loading branch information
ybizeul committed Aug 3, 2024
1 parent 06c8b4b commit ccfee5b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
46 changes: 25 additions & 21 deletions html/src/Components/ShareComponent.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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 = () => {
Expand All @@ -30,28 +31,31 @@ export function ShareComponent(props: {share: Share}) {
<Group justify="space-between" h={45}>
<Anchor component={Link} to={'/'+name}><Text>{name}</Text></Anchor>
<Group>
<CopyButton value={window.location.protocol + '//' + window.location.host + '/' + name}>
{({ copied, copy }) => (
<Tooltip withArrow arrowOffset={10} arrowSize={4} label="Copy URL">
<ActionIcon variant="light" color={copied ? 'teal' : 'blue'} onClick={copy} >
<IconLink style={{ width: '70%', height: '70%' }} stroke={1.5}/>
</ActionIcon>
</Tooltip>
)}
</CopyButton>
<Popover width={200} position="bottom" withArrow shadow="md">
<Popover.Target>
<Tooltip withArrow arrowOffset={10} arrowSize={4} label="Delete Share">
<ActionIcon variant="light" color="red" >
<IconTrash style={{ width: '70%', height: '70%' }} stroke={1.5}/>
<Text size="xs" c="gray">{humanFileSize(size)}</Text>
<Group>
<CopyButton value={window.location.protocol + '//' + window.location.host + '/' + name}>
{({ copied, copy }) => (
<Tooltip withArrow arrowOffset={10} arrowSize={4} label="Copy URL">
<ActionIcon variant="light" color={copied ? 'teal' : 'blue'} onClick={copy} >
<IconLink style={{ width: '70%', height: '70%' }} stroke={1.5}/>
</ActionIcon>
</Tooltip>
</Popover.Target>
<Popover.Dropdown className={classes.popover}>
<Text ta="center" size="xs" mb="xs">Delete this share ?</Text>
<Button aria-description="delete" w="100%" variant='default' c='red' size="xs" onClick={deleteShare}>Delete</Button>
</Popover.Dropdown>
</Popover>
)}
</CopyButton>
<Popover width={200} position="bottom" withArrow shadow="md">
<Popover.Target>
<Tooltip withArrow arrowOffset={10} arrowSize={4} label="Delete Share">
<ActionIcon variant="light" color="red" >
<IconTrash style={{ width: '70%', height: '70%' }} stroke={1.5}/>
</ActionIcon>
</Tooltip>
</Popover.Target>
<Popover.Dropdown className={classes.popover}>
<Text ta="center" size="xs" mb="xs">Delete this share ?</Text>
<Button aria-description="delete" w="100%" variant='default' c='red' size="xs" onClick={deleteShare}>Delete</Button>
</Popover.Dropdown>
</Popover>
</Group>
</Group>
</Group>
</Paper>
Expand Down
1 change: 1 addition & 0 deletions html/src/hupload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface Share {
name: string;
owner: string;
size: number;
}

export interface Item {
Expand Down
1 change: 1 addition & 0 deletions hupload/pkg/apiws/storageservice/storageservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions hupload/pkg/apiws/storageservice/storageservicefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ccfee5b

Please sign in to comment.