apps/blobs/routes.go 1.3 K raw
1
package main
2
3
import (
4
	"net/http"
5
6
	"github.com/stevedylandev/andromeda/pkg/darkmatter"
7
	"github.com/stevedylandev/andromeda/pkg/web"
8
)
9
10
func (a *App) routes() *http.ServeMux {
11
	mux := http.NewServeMux()
12
13
	requireSession := func(next http.HandlerFunc) http.HandlerFunc {
14
		return a.Sessions.RequireSession("/login", next)
15
	}
16
17
	mux.HandleFunc("GET /static/", web.EmbeddedHandler(appFS, "static"))
18
	darkmatter.Mount(mux, "/assets")
19
20
	mux.HandleFunc("GET /login", a.loginGet)
21
	mux.HandleFunc("POST /login", a.loginPost)
22
	mux.HandleFunc("POST /logout", a.logout)
23
24
	mux.HandleFunc("GET /{$}", requireSession(a.rootRedirect))
25
	mux.HandleFunc("GET /buckets", requireSession(a.listBuckets))
26
27
	mux.HandleFunc("GET /b/{bucket}", requireSession(a.bucketRoot))
28
	mux.HandleFunc("GET /b/{bucket}/browse/{prefix...}", requireSession(a.browse))
29
	mux.HandleFunc("GET /b/{bucket}/object/{key...}", requireSession(a.detail))
30
	mux.HandleFunc("GET /b/{bucket}/preview/{key...}", requireSession(a.preview))
31
32
	mux.HandleFunc("POST /b/{bucket}/upload", requireSession(a.upload))
33
	mux.HandleFunc("POST /b/{bucket}/replace", requireSession(a.replace))
34
	mux.HandleFunc("POST /b/{bucket}/delete", requireSession(a.deleteObject))
35
	mux.HandleFunc("POST /b/{bucket}/mkdir", requireSession(a.mkdir))
36
37
	return mux
38
}