From 9a878026303dbd06fada7e384b93dbb02d85e8ab Mon Sep 17 00:00:00 2001 From: t-takahashi Date: Tue, 16 Jul 2024 23:04:47 +0900 Subject: [PATCH] add isTruncated --- .github/workflows/go.yml | 2 +- core/amazon/awssdk/listobjects_v2.go | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index db3e764..49aa950 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.22.4' + go-version: '1.22.5' - name: Build run: go build -v ./... diff --git a/core/amazon/awssdk/listobjects_v2.go b/core/amazon/awssdk/listobjects_v2.go index ea55d9f..7220714 100644 --- a/core/amazon/awssdk/listobjects_v2.go +++ b/core/amazon/awssdk/listobjects_v2.go @@ -10,11 +10,12 @@ import ( ) type ListBucketResult struct { - XMLName xml.Name `xml:"ListBucketResult"` - Name string `xml:"Name"` - Prefix string `xml:"Prefix"` - Marker string `xml:"Marker"` - Items []Item `xml:"Contents"` + XMLName xml.Name `xml:"ListBucketResult"` + Name string `xml:"Name"` + Prefix string `xml:"Prefix"` + Marker string `xml:"Marker"` + Items []Item `xml:"Contents"` + IsTruncated bool `xml:"IsTruncated"` } type Item struct { @@ -25,7 +26,7 @@ type Item struct { func ListObjectsV2(w http.ResponseWriter, r *http.Request) { slog.Info("ListObjectsV2 is called.") - path := strings.Split(r.URL.Path, "?list-type=2")[0] // It has been confirmed in the previous process controller.go that `?list-type=2` is included. + path := strings.Split(r.URL.Path, "?list-type=2")[0] dir := strings.TrimPrefix(path, "/") if dir == "" { slog.Error("No directory specified in the query parameter") @@ -33,7 +34,6 @@ func ListObjectsV2(w http.ResponseWriter, r *http.Request) { return } - // Define the target directory rootDir := filepath.Join("upload", dir) var items []Item @@ -43,7 +43,7 @@ func ListObjectsV2(w http.ResponseWriter, r *http.Request) { } if !info.IsDir() { items = append(items, Item{ - Key: filepath.ToSlash(path[len("upload/"):]), // Convert to a relative path + Key: filepath.ToSlash(path[len("upload/"):]), Size: info.Size(), }) } @@ -57,9 +57,17 @@ func ListObjectsV2(w http.ResponseWriter, r *http.Request) { slog.Info("Files are below", "files", items) + isTruncated := false + // Add logic to determine if the result is truncated + if len(items) > 1000 { + isTruncated = true + items = items[:1000] + } + response := ListBucketResult{ - Name: dir, - Items: items, + Name: dir, + Items: items, + IsTruncated: isTruncated, } w.Header().Set("Content-Type", "application/xml")