feat: show
This commit is contained in:
parent
f54ed67f0f
commit
edfb7bee2e
@ -6,6 +6,7 @@ import {useStoreBucket} from "../../store/bucket";
|
|||||||
import {Bucket, S3File} from "../../interfaces/connection";
|
import {Bucket, S3File} from "../../interfaces/connection";
|
||||||
import {useStoreFile} from "../../store/file";
|
import {useStoreFile} from "../../store/file";
|
||||||
import {useStoreConnection} from "../../store/connection";
|
import {useStoreConnection} from "../../store/connection";
|
||||||
|
import {TrimSuffix} from "../../hook/strings";
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
container: {
|
container: {
|
||||||
@ -38,11 +39,15 @@ export function ListFileComponent() {
|
|||||||
const {conn_active} = useStoreConnection();
|
const {conn_active} = useStoreConnection();
|
||||||
const {bucket_active} = useStoreBucket()
|
const {bucket_active} = useStoreBucket()
|
||||||
const {prefix, files_get, files_list} = useStoreFile()
|
const {prefix, files_get, files_list} = useStoreFile()
|
||||||
|
const filename = (key:string) => {
|
||||||
|
let strs = TrimSuffix(key, "/").split("/")
|
||||||
|
return strs[strs.length - 1]
|
||||||
|
}
|
||||||
|
|
||||||
async function handleClick(item: S3File) {
|
async function handleClick(item: S3File) {
|
||||||
if (item.type === 1) {
|
if (item.type === 1) {
|
||||||
console.log(`[DEBUG] click prefix = ${prefix} item.key = ${item.key}`)
|
console.log(`[DEBUG] click prefix = ${prefix} item.key = ${item.key}`)
|
||||||
files_get(conn_active!, bucket_active!, prefix + item.key)
|
files_get(conn_active!, bucket_active!, item.key)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +74,7 @@ export function ListFileComponent() {
|
|||||||
<MenuItem className={styles.item}
|
<MenuItem className={styles.item}
|
||||||
icon={files_list[idx].type ? <FolderRegular/> : <DocumentBulletListRegular/>}>
|
icon={files_list[idx].type ? <FolderRegular/> : <DocumentBulletListRegular/>}>
|
||||||
<Text truncate wrap={false} className={styles.text}>
|
<Text truncate wrap={false} className={styles.text}>
|
||||||
{files_list[idx].name}
|
{filename(files_list[idx].key)}
|
||||||
</Text>
|
</Text>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,6 +20,10 @@ const useStyles = makeStyles({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
},
|
},
|
||||||
|
show_line: {
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
show_text: {
|
show_text: {
|
||||||
backgroundColor: tokens.colorNeutralBackground1Hover,
|
backgroundColor: tokens.colorNeutralBackground1Hover,
|
||||||
padding: '0.5rem 0.5rem',
|
padding: '0.5rem 0.5rem',
|
||||||
@ -69,11 +73,11 @@ export function Path() {
|
|||||||
<Text className={styles.show_text}><ArchiveRegular
|
<Text className={styles.show_text}><ArchiveRegular
|
||||||
style={{marginRight: '0.5rem'}}/>{bucket_active.name}</Text>
|
style={{marginRight: '0.5rem'}}/>{bucket_active.name}</Text>
|
||||||
{prefix && (
|
{prefix && (
|
||||||
prefix.split("/").filter(item => item).map(item => {
|
prefix.split("/").filter(item => item).map((item, idx) => {
|
||||||
return <>
|
return <div className={styles.show_line} key={idx}>
|
||||||
<Text style={{marginLeft: '0.5rem'}}>/</Text>
|
<Text style={{marginLeft: '0.5rem'}}>/</Text>
|
||||||
<Text className={styles.show_text}>{item}</Text>
|
<Text className={styles.show_text}>{item}</Text>
|
||||||
</>
|
</div>
|
||||||
})
|
})
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
6
frontend/src/hook/strings.ts
Normal file
6
frontend/src/hook/strings.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export function TrimSuffix(str: string, suffix: string) {
|
||||||
|
if (str.lastIndexOf(suffix) === str.length - suffix.length) {
|
||||||
|
return str.substring(0, str.length - suffix.length);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
@ -30,7 +30,7 @@ func Init(ctx context.Context) error {
|
|||||||
register("/api/connection/connect", handler.ConnectionConnect)
|
register("/api/connection/connect", handler.ConnectionConnect)
|
||||||
register("/api/connection/disconnect", handler.ConnectionDisconnect)
|
register("/api/connection/disconnect", handler.ConnectionDisconnect)
|
||||||
register("/api/connection/buckets", handler.ConnectionBuckets)
|
register("/api/connection/buckets", handler.ConnectionBuckets)
|
||||||
register("/api/bucket/files", handler.BucketFile)
|
register("/api/bucket/files", handler.BucketFiles)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/loveuer/nf-disk/ndh"
|
"github.com/loveuer/nf-disk/ndh"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BucketFile(c *ndh.Ctx) error {
|
func BucketFiles(c *ndh.Ctx) error {
|
||||||
type Req struct {
|
type Req struct {
|
||||||
ConnId uint64 `json:"conn_id"`
|
ConnId uint64 `json:"conn_id"`
|
||||||
Bucket string `json:"bucket"`
|
Bucket string `json:"bucket"`
|
||||||
|
@ -78,7 +78,7 @@ func (c *Client) ListFile(ctx context.Context, bucket string, prefix string) ([]
|
|||||||
name := strings.TrimPrefix(*item.Prefix, prefix)
|
name := strings.TrimPrefix(*item.Prefix, prefix)
|
||||||
return &ListFileRes{
|
return &ListFileRes{
|
||||||
Name: name,
|
Name: name,
|
||||||
Key: name,
|
Key: *item.Prefix,
|
||||||
Type: ListFileTypeDir,
|
Type: ListFileTypeDir,
|
||||||
}, name != ""
|
}, name != ""
|
||||||
},
|
},
|
||||||
@ -88,7 +88,7 @@ func (c *Client) ListFile(ctx context.Context, bucket string, prefix string) ([]
|
|||||||
output.Contents,
|
output.Contents,
|
||||||
func(item types.Object, index int) *ListFileRes {
|
func(item types.Object, index int) *ListFileRes {
|
||||||
return &ListFileRes{
|
return &ListFileRes{
|
||||||
Key: *item.Key,
|
Key: strings.Clone(*item.Key),
|
||||||
Name: strings.TrimPrefix(*item.Key, prefix),
|
Name: strings.TrimPrefix(*item.Key, prefix),
|
||||||
LastModified: *item.LastModified,
|
LastModified: *item.LastModified,
|
||||||
Size: *item.Size,
|
Size: *item.Size,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user