Consistent WebDav file sorting (#62)
* style: Sort webdav file lists by name * style: Consistent sorting on the get torrents route
This commit is contained in:
committed by
GitHub
parent
130433203f
commit
ef820b5bf4
@@ -2,6 +2,10 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
"github.com/sirrobot01/decypharr/internal/config"
|
"github.com/sirrobot01/decypharr/internal/config"
|
||||||
@@ -11,9 +15,6 @@ import (
|
|||||||
"github.com/sirrobot01/decypharr/pkg/qbit"
|
"github.com/sirrobot01/decypharr/pkg/qbit"
|
||||||
"github.com/sirrobot01/decypharr/pkg/service"
|
"github.com/sirrobot01/decypharr/pkg/service"
|
||||||
"github.com/sirrobot01/decypharr/pkg/version"
|
"github.com/sirrobot01/decypharr/pkg/version"
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ui *Handler) handleGetArrs(w http.ResponseWriter, r *http.Request) {
|
func (ui *Handler) handleGetArrs(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -142,7 +143,7 @@ func (ui *Handler) handleGetVersion(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ui *Handler) handleGetTorrents(w http.ResponseWriter, r *http.Request) {
|
func (ui *Handler) handleGetTorrents(w http.ResponseWriter, r *http.Request) {
|
||||||
request.JSONResponse(w, ui.qbit.Storage.GetAll("", "", nil), http.StatusOK)
|
request.JSONResponse(w, ui.qbit.Storage.GetAllSorted("", "", nil, "added_on", false), http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *Handler) handleDeleteTorrent(w http.ResponseWriter, r *http.Request) {
|
func (ui *Handler) handleDeleteTorrent(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -221,7 +221,17 @@ func (h *Handler) Stat(ctx context.Context, name string) (os.FileInfo, error) {
|
|||||||
func (h *Handler) getFileInfos(torrent *types.Torrent) []os.FileInfo {
|
func (h *Handler) getFileInfos(torrent *types.Torrent) []os.FileInfo {
|
||||||
files := make([]os.FileInfo, 0, len(torrent.Files))
|
files := make([]os.FileInfo, 0, len(torrent.Files))
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
|
// Sort by file name since the order is lost when using the map
|
||||||
|
sortedFiles := make([]*types.File, 0, len(torrent.Files))
|
||||||
for _, file := range torrent.Files {
|
for _, file := range torrent.Files {
|
||||||
|
sortedFiles = append(sortedFiles, &file)
|
||||||
|
}
|
||||||
|
slices.SortFunc(sortedFiles, func(a, b *types.File) int {
|
||||||
|
return strings.Compare(a.Name, b.Name)
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, file := range sortedFiles {
|
||||||
files = append(files, &FileInfo{
|
files = append(files, &FileInfo{
|
||||||
name: file.Name,
|
name: file.Name,
|
||||||
size: file.Size,
|
size: file.Size,
|
||||||
|
|||||||
Reference in New Issue
Block a user