Skip to content

Commit

Permalink
add isTruncated
Browse files Browse the repository at this point in the history
  • Loading branch information
tttol committed Jul 16, 2024
1 parent ecdfea5 commit 9a87802
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
28 changes: 18 additions & 10 deletions core/amazon/awssdk/listobjects_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,15 +26,14 @@ 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")
http.Error(w, "No directory specified", http.StatusBadRequest)
return
}

// Define the target directory
rootDir := filepath.Join("upload", dir)

var items []Item
Expand All @@ -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(),
})
}
Expand All @@ -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")
Expand Down

0 comments on commit 9a87802

Please sign in to comment.