diff --git a/frontend/src/component/file/list_file.tsx b/frontend/src/component/file/list_file.tsx
index 32e801f..875a9da 100644
--- a/frontend/src/component/file/list_file.tsx
+++ b/frontend/src/component/file/list_file.tsx
@@ -6,6 +6,7 @@ import {useStoreBucket} from "../../store/bucket";
import {Bucket, S3File} from "../../interfaces/connection";
import {useStoreFile} from "../../store/file";
import {useStoreConnection} from "../../store/connection";
+import {TrimSuffix} from "../../hook/strings";
const useStyles = makeStyles({
container: {
@@ -38,11 +39,15 @@ export function ListFileComponent() {
const {conn_active} = useStoreConnection();
const {bucket_active} = useStoreBucket()
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) {
if (item.type === 1) {
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
}
}
@@ -69,7 +74,7 @@ export function ListFileComponent() {
: }>
- {files_list[idx].name}
+ {filename(files_list[idx].key)}
diff --git a/frontend/src/component/file/path.tsx b/frontend/src/component/file/path.tsx
index c4e1308..518acf5 100644
--- a/frontend/src/component/file/path.tsx
+++ b/frontend/src/component/file/path.tsx
@@ -20,6 +20,10 @@ const useStyles = makeStyles({
display: 'flex',
alignItems: 'center',
},
+ show_line: {
+ display: 'flex',
+ alignItems: 'center',
+ },
show_text: {
backgroundColor: tokens.colorNeutralBackground1Hover,
padding: '0.5rem 0.5rem',
@@ -69,11 +73,11 @@ export function Path() {
{bucket_active.name}
{prefix && (
- prefix.split("/").filter(item => item).map(item => {
- return <>
+ prefix.split("/").filter(item => item).map((item, idx) => {
+ return
/
{item}
- >
+
})
)}
diff --git a/frontend/src/hook/strings.ts b/frontend/src/hook/strings.ts
new file mode 100644
index 0000000..c90cdca
--- /dev/null
+++ b/frontend/src/hook/strings.ts
@@ -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;
+}
\ No newline at end of file
diff --git a/internal/api/api.go b/internal/api/api.go
index 510a5f8..cf42813 100644
--- a/internal/api/api.go
+++ b/internal/api/api.go
@@ -30,7 +30,7 @@ func Init(ctx context.Context) error {
register("/api/connection/connect", handler.ConnectionConnect)
register("/api/connection/disconnect", handler.ConnectionDisconnect)
register("/api/connection/buckets", handler.ConnectionBuckets)
- register("/api/bucket/files", handler.BucketFile)
+ register("/api/bucket/files", handler.BucketFiles)
return nil
}
diff --git a/internal/handler/bucket.go b/internal/handler/bucket.go
index 23b579a..f6d9f75 100644
--- a/internal/handler/bucket.go
+++ b/internal/handler/bucket.go
@@ -6,7 +6,7 @@ import (
"github.com/loveuer/nf-disk/ndh"
)
-func BucketFile(c *ndh.Ctx) error {
+func BucketFiles(c *ndh.Ctx) error {
type Req struct {
ConnId uint64 `json:"conn_id"`
Bucket string `json:"bucket"`
diff --git a/internal/s3/list.go b/internal/s3/list.go
index 7df9965..085d35e 100644
--- a/internal/s3/list.go
+++ b/internal/s3/list.go
@@ -78,7 +78,7 @@ func (c *Client) ListFile(ctx context.Context, bucket string, prefix string) ([]
name := strings.TrimPrefix(*item.Prefix, prefix)
return &ListFileRes{
Name: name,
- Key: name,
+ Key: *item.Prefix,
Type: ListFileTypeDir,
}, name != ""
},
@@ -88,7 +88,7 @@ func (c *Client) ListFile(ctx context.Context, bucket string, prefix string) ([]
output.Contents,
func(item types.Object, index int) *ListFileRes {
return &ListFileRes{
- Key: *item.Key,
+ Key: strings.Clone(*item.Key),
Name: strings.TrimPrefix(*item.Key, prefix),
LastModified: *item.LastModified,
Size: *item.Size,