aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-12-09 06:00:51 +0100
committerPřemysl Eric Janouch <p@janouch.name>2023-12-09 06:00:51 +0100
commita9ceed1d37c5a33b5479752a866c3289838f7fc4 (patch)
treedd58f1a95c61085c8e1ba719a693391159e031fd
parent1c153a8e8ea709cfc89eda810c41b5d2c9fa8472 (diff)
downloadgallery-a9ceed1d37c5a33b5479752a866c3289838f7fc4.tar.gz
gallery-a9ceed1d37c5a33b5479752a866c3289838f7fc4.tar.xz
gallery-a9ceed1d37c5a33b5479752a866c3289838f7fc4.zip
Placeholder root handler
-rw-r--r--main.go23
-rw-r--r--public/gallery.js1
-rw-r--r--public/style.css0
3 files changed, 22 insertions, 2 deletions
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(`<!DOCTYPE html><html><head>
+ <title>Gallery</title>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <link rel=stylesheet href=style.css>
+</head><body>
+ <script src=gallery.js></script>
+ {{ . }}
+</body></html>`))
+
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)
diff --git a/public/gallery.js b/public/gallery.js
new file mode 100644
index 0000000..ccacec3
--- /dev/null
+++ b/public/gallery.js
@@ -0,0 +1 @@
+'use strict'
diff --git a/public/style.css b/public/style.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/public/style.css