diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -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) |