fix file listing when there are not files in a directory
This commit is contained in:
parent
9e35ee218c
commit
51d6f2dbf2
|
@ -1,3 +1,5 @@
|
|||
- [ ] Fix directory zip download incorrect file modification dates
|
||||
- [ ] Set systemd service to deny access outside of the root file path
|
||||
- [ ] Clean up code
|
||||
|
||||
## Config
|
||||
|
@ -13,4 +15,5 @@
|
|||
- [ ] Modified
|
||||
- [ ] Size
|
||||
- [ ] Admin endpoint to fetch the last `n` modified files
|
||||
- [ ] Add an endpoint to get info for a specific file
|
||||
- [ ] Document API
|
||||
|
|
|
@ -106,40 +106,46 @@ func APIList(w http.ResponseWriter, r *http.Request) {
|
|||
// Generate the listing.
|
||||
pageParam := r.URL.Query().Get("page")
|
||||
response := map[string]interface{}{}
|
||||
item, pages, responseError := generateListing(cacheItem, paginationLimit, sortType, pageParam)
|
||||
if responseError != "" {
|
||||
helpers.Return400Msg(responseError, w)
|
||||
return
|
||||
}
|
||||
|
||||
resolveItemName := r.URL.Query().Get("resolve")
|
||||
if resolveItemName != "" {
|
||||
var resolvedChild *responseitem.ResponseItem
|
||||
var resolvedChildPage int
|
||||
outer:
|
||||
for i, page := range pages {
|
||||
for _, child := range page {
|
||||
if child.Name == resolveItemName {
|
||||
resolvedChild = child
|
||||
resolvedChildPage = i
|
||||
break outer
|
||||
}
|
||||
}
|
||||
}
|
||||
if resolvedChild == nil {
|
||||
helpers.Return400Msg("failed to find item", w)
|
||||
if len(cacheItem.Children) > 0 {
|
||||
item, pages, responseError := generateListing(cacheItem, paginationLimit, sortType, pageParam)
|
||||
if responseError != "" {
|
||||
helpers.Return400Msg(responseError, w)
|
||||
return
|
||||
}
|
||||
item.Children = make([]*responseitem.ResponseItem, 1)
|
||||
item.Children[0] = resolvedChild
|
||||
response["resolved_page"] = resolvedChildPage + 1
|
||||
|
||||
resolveItemName := r.URL.Query().Get("resolve")
|
||||
if resolveItemName != "" {
|
||||
var resolvedChild *responseitem.ResponseItem
|
||||
var resolvedChildPage int
|
||||
outer:
|
||||
for i, page := range pages {
|
||||
for _, child := range page {
|
||||
if child.Name == resolveItemName {
|
||||
resolvedChild = child
|
||||
resolvedChildPage = i
|
||||
break outer
|
||||
}
|
||||
}
|
||||
}
|
||||
if resolvedChild == nil {
|
||||
helpers.Return400Msg("failed to find item", w)
|
||||
return
|
||||
}
|
||||
item.Children = make([]*responseitem.ResponseItem, 1)
|
||||
item.Children[0] = resolvedChild
|
||||
response["resolved_page"] = resolvedChildPage + 1
|
||||
}
|
||||
|
||||
if pageParam != "" || resolveItemName != "" {
|
||||
response["total_pages"] = len(pages) // + 1 // We add 1 to the count because arrays are zero-indexed.
|
||||
}
|
||||
response["item"] = item
|
||||
} else {
|
||||
response["item"] = cacheItem
|
||||
response["total_pages"] = 0
|
||||
}
|
||||
|
||||
if pageParam != "" || resolveItemName != "" {
|
||||
response["total_pages"] = len(pages) // + 1 // We add 1 to the count because arrays are zero-indexed.
|
||||
}
|
||||
|
||||
response["item"] = item
|
||||
helpers.WriteJsonResponse(response, true, w, r)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue