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
|
- [ ] Clean up code
|
||||||
|
|
||||||
## Config
|
## Config
|
||||||
|
@ -13,4 +15,5 @@
|
||||||
- [ ] Modified
|
- [ ] Modified
|
||||||
- [ ] Size
|
- [ ] Size
|
||||||
- [ ] Admin endpoint to fetch the last `n` modified files
|
- [ ] Admin endpoint to fetch the last `n` modified files
|
||||||
|
- [ ] Add an endpoint to get info for a specific file
|
||||||
- [ ] Document API
|
- [ ] Document API
|
||||||
|
|
|
@ -106,40 +106,46 @@ func APIList(w http.ResponseWriter, r *http.Request) {
|
||||||
// Generate the listing.
|
// Generate the listing.
|
||||||
pageParam := r.URL.Query().Get("page")
|
pageParam := r.URL.Query().Get("page")
|
||||||
response := map[string]interface{}{}
|
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 len(cacheItem.Children) > 0 {
|
||||||
if resolveItemName != "" {
|
item, pages, responseError := generateListing(cacheItem, paginationLimit, sortType, pageParam)
|
||||||
var resolvedChild *responseitem.ResponseItem
|
if responseError != "" {
|
||||||
var resolvedChildPage int
|
helpers.Return400Msg(responseError, w)
|
||||||
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
|
return
|
||||||
}
|
}
|
||||||
item.Children = make([]*responseitem.ResponseItem, 1)
|
|
||||||
item.Children[0] = resolvedChild
|
resolveItemName := r.URL.Query().Get("resolve")
|
||||||
response["resolved_page"] = resolvedChildPage + 1
|
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)
|
helpers.WriteJsonResponse(response, true, w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue