fix crash when trying handle a file as a directory

This commit is contained in:
Cyberes 2024-04-12 21:40:26 -06:00
parent 6001894b0b
commit 9e35ee218c
4 changed files with 32 additions and 8 deletions

2
.gitignore vendored
View File

@ -15,6 +15,8 @@ dist/
*.so
*.dylib
pkg/
# Test binary, built with `go test -c`
*.test

16
release checklist.md Normal file
View File

@ -0,0 +1,16 @@
- [ ] Clean up code
## Config
- [ ] Add a wildcard option to restricted_download_paths to block all sub-directories
- [ ] Add a dict to each restricted_download_paths item to specify how many levels recursive the block should be applied
## API
- [ ] Convert JSON to camelCase
- [ ] On the client health page, show the time the initial crawl started
- [ ] New sort options:
- [ ] Modified
- [ ] Size
- [ ] Admin endpoint to fetch the last `n` modified files
- [ ] Document API

View File

@ -144,6 +144,10 @@ func APIList(w http.ResponseWriter, r *http.Request) {
}
func generateListing(cacheItem *cacheitem.Item, paginationLimit int, sortType string, pageParam string) (*responseitem.ResponseItem, [][]*responseitem.ResponseItem, string) {
if !cacheItem.IsDir {
return nil, nil, "path is not a directory"
}
if sortType == "" {
panic("sortType was an empty string")
}
@ -196,6 +200,16 @@ func generateListing(cacheItem *cacheitem.Item, paginationLimit int, sortType st
pages = append(pages, item.Children[i:end])
}
// Handle case when there are fewer children than the paginationLimit
if len(pages) == 0 && len(item.Children) > 0 {
pages = append(pages, item.Children)
}
// Handle case when there are no pages or children
if len(pages) == 0 {
return nil, nil, "no pages available"
}
paginatedChildren := pages[page]
// Erase the children of the children so we aren't displaying things recursively.

View File

@ -1,8 +0,0 @@
- on the client health page, show the time the initial crawl started
Later:
- Add a wildcard option to restricted_download_paths to block all sub-directories
- Add a dict to each restricted_download_paths item to specify how many levels recursive the block should be applied
- add a "last modified" to "sort" https://chub-archive.evulid.cc/api/file/list?path=/chub.ai/characters&page=1&limit=50&sort=folders
- add an admin endpoint to fetch the last n modified files.