fix file listing when there are not files in a directory

This commit is contained in:
Cyberes 2024-04-29 19:21:17 -06:00
parent 9e35ee218c
commit 51d6f2dbf2
2 changed files with 38 additions and 29 deletions

View File

@ -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

View File

@ -106,6 +106,8 @@ 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{}{}
if len(cacheItem.Children) > 0 {
item, pages, responseError := generateListing(cacheItem, paginationLimit, sortType, pageParam) item, pages, responseError := generateListing(cacheItem, paginationLimit, sortType, pageParam)
if responseError != "" { if responseError != "" {
helpers.Return400Msg(responseError, w) helpers.Return400Msg(responseError, w)
@ -138,8 +140,12 @@ func APIList(w http.ResponseWriter, r *http.Request) {
if pageParam != "" || resolveItemName != "" { if pageParam != "" || resolveItemName != "" {
response["total_pages"] = len(pages) // + 1 // We add 1 to the count because arrays are zero-indexed. response["total_pages"] = len(pages) // + 1 // We add 1 to the count because arrays are zero-indexed.
} }
response["item"] = item response["item"] = item
} else {
response["item"] = cacheItem
response["total_pages"] = 0
}
helpers.WriteJsonResponse(response, true, w, r) helpers.WriteJsonResponse(response, true, w, r)
} }