From 11f637e43c120e528a94cb3073883187a8d696b2 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Fri, 15 Dec 2023 22:43:58 +0100 Subject: Improve web views --- main.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index b01e687..8c154e8 100644 --- a/main.go +++ b/main.go @@ -183,7 +183,6 @@ func handleThumbs(w http.ResponseWriter, r *http.Request) { func getSubdirectories(tx *sql.Tx, parent int64) (names []string, err error) { // TODO: This is like dbCollectStrings(), just needs an argument. - // TODO: Should this return full paths, or not? Clean it up. rows, err := tx.Query( `SELECT name FROM directory WHERE IFNULL(parent, 0) = ?`, parent) if err != nil { @@ -282,7 +281,7 @@ func getImagePaths(sha1 string) (paths []string, err error) { UNION ALL SELECT d.parent, d.name || '/' || p.path FROM directory AS d JOIN paths AS p ON d.id = p.parent - ) SELECT '/' || path FROM paths WHERE parent IS NULL`, sha1) + ) SELECT path FROM paths WHERE parent IS NULL`, sha1) if err != nil { return nil, err } @@ -430,16 +429,15 @@ func idForPath(tx *sql.Tx, path []string, create bool) (int64, error) { } func decodeWebPath(path string) []string { - // Trailing slashes don't provide information. - path = strings.TrimSuffix(path, "/") - // Relative paths could be handled differently, // but right now, they're assumed to start at the root. - list := strings.Split(path, "/") - if len(list) > 0 && list[0] == "" { - list = list[1:] + result := []string{} + for _, crumb := range strings.Split(path, "/") { + if crumb != "" { + result = append(result, crumb) + } } - return list + return result } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3-70-g09d2