aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-12-24 07:18:53 +0100
committerPřemysl Eric Janouch <p@janouch.name>2023-12-24 07:18:53 +0100
commit410198c3788c216d4244d093eb923f6710f39c8f (patch)
tree11f961ebd1d6bff6c66a6e24e126bff05878e671
parent0face97dc7b262986e206b5f3152e25a506f8326 (diff)
downloadgallery-410198c3788c216d4244d093eb923f6710f39c8f.tar.gz
gallery-410198c3788c216d4244d093eb923f6710f39c8f.tar.xz
gallery-410198c3788c216d4244d093eb923f6710f39c8f.zip
Cleanup
-rw-r--r--main.go23
1 files changed, 4 insertions, 19 deletions
diff --git a/main.go b/main.go
index 970330d..a89a096 100644
--- a/main.go
+++ b/main.go
@@ -82,14 +82,14 @@ func thumbPath(sha1 string) string {
nameOfThumbRoot, sha1[:2], sha1+".webp")
}
-func dbCollectStrings(query string) ([]string, error) {
- rows, err := db.Query(query)
+func dbCollectStrings(query string, a ...any) ([]string, error) {
+ rows, err := db.Query(query, a...)
if err != nil {
return nil, err
}
defer rows.Close()
- var result []string
+ result := []string{}
for rows.Next() {
var s string
if err := rows.Scan(&s); err != nil {
@@ -288,23 +288,8 @@ 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.
- rows, err := tx.Query(`SELECT name FROM node
+ return dbCollectStrings(`SELECT name FROM node
WHERE IFNULL(parent, 0) = ? AND sha1 IS NULL`, parent)
- if err != nil {
- return nil, err
- }
- defer rows.Close()
-
- names = []string{}
- for rows.Next() {
- var name string
- if err := rows.Scan(&name); err != nil {
- return nil, err
- }
- names = append(names, name)
- }
- return names, rows.Err()
}
type webEntry struct {