From a9ceed1d37c5a33b5479752a866c3289838f7fc4 Mon Sep 17 00:00:00 2001
From: Přemysl Eric Janouch
Date: Sat, 9 Dec 2023 06:00:51 +0100
Subject: Placeholder root handler
---
main.go | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
(limited to 'main.go')
diff --git a/main.go b/main.go
index 7d6d311..3324ae5 100644
--- a/main.go
+++ b/main.go
@@ -7,6 +7,7 @@ import (
"encoding/hex"
"errors"
"fmt"
+ "html/template"
"io"
"io/fs"
"log"
@@ -91,14 +92,27 @@ func cmdInit(args []string) error {
var hashRE = regexp.MustCompile(`^/.*?/([0-9a-f]{40})$`)
var staticHandler http.Handler
+var page = template.Must(template.New("/").Parse(`
+ Gallery
+
+
+
+
+
+ {{ . }}
+`))
+
func handleRequest(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
staticHandler.ServeHTTP(w, r)
return
}
- // TODO: Return something.
- http.NotFound(w, r)
+ // TODO: Include the most elementary contents first.
+
+ if err := page.Execute(w, "Hello world"); err != nil {
+ http.Error(w, err.Error(), 500)
+ }
}
func handleImages(w http.ResponseWriter, r *http.Request) {
@@ -128,10 +142,14 @@ func cmdRun(args []string) error {
address := args[1]
+ // This separation is not strictly necessary,
+ // but having an elementary level of security doesn't hurt either.
staticHandler = http.FileServer(http.Dir("public"))
+
http.HandleFunc("/", handleRequest)
http.HandleFunc("/images/", handleImages)
http.HandleFunc("/thumbs/", handleThumbs)
+ // TODO: Add a few API endpoints.
host, port, err := net.SplitHostPort(address)
if err != nil {
@@ -340,6 +358,7 @@ func cmdThumbnail(args []string) error {
}
// TODO: Try to run the thumbnailer in parallel, somehow.
+ // Then run convert with `-limit thread 1`.
// TODO: Show progress in some manner. Perhaps port my propeller code.
for _, sha1 := range hexSHA1 {
pathImage := imagePath(sha1)
--
cgit v1.2.3-70-g09d2