diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2023-12-15 22:43:58 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2023-12-15 22:55:12 +0100 |
commit | 11f637e43c120e528a94cb3073883187a8d696b2 (patch) | |
tree | 157ddaafa8b20b929b36de2f3980c79bff10dfd1 /main.go | |
parent | 80136f48c9c91ba0bdcd9911a0eaa0aeae565b8a (diff) | |
download | gallery-11f637e43c120e528a94cb3073883187a8d696b2.tar.gz gallery-11f637e43c120e528a94cb3073883187a8d696b2.tar.xz gallery-11f637e43c120e528a94cb3073883187a8d696b2.zip |
Improve web views
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -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 } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |