feat: route registration
This commit is contained in:
@@ -3,9 +3,11 @@ package server
|
|||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"yoresee_dropbox/internal/store"
|
"yoresee_dropbox/internal/store"
|
||||||
|
"yoresee_dropbox/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
@@ -36,3 +38,36 @@ func generateUUID() string {
|
|||||||
rand.Read(b)
|
rand.Read(b)
|
||||||
return hex.EncodeToString(b)
|
return hex.EncodeToString(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) Handler() http.Handler {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
mux.HandleFunc("POST /api/login", s.handleLogin)
|
||||||
|
mux.HandleFunc("POST /api/logout", s.requireAuth(s.handleLogout))
|
||||||
|
mux.HandleFunc("POST /api/upload", s.requireAuth(s.handleUpload))
|
||||||
|
mux.HandleFunc("GET /api/files", s.requireAuth(s.handleListFiles))
|
||||||
|
mux.HandleFunc("GET /api/files/{id}/download", s.requireAuth(s.handleDownload))
|
||||||
|
mux.HandleFunc("DELETE /api/files/{id}", s.requireAuth(s.handleDeleteFile))
|
||||||
|
mux.HandleFunc("POST /api/files/{id}/share", s.requireAuth(s.handleCreateShare))
|
||||||
|
mux.HandleFunc("GET /api/shares", s.requireAuth(s.handleListShares))
|
||||||
|
mux.HandleFunc("DELETE /api/shares/{id}", s.requireAuth(s.handleDeleteShare))
|
||||||
|
|
||||||
|
mux.HandleFunc("GET /s/{token}", s.handleShareAccess)
|
||||||
|
mux.HandleFunc("POST /s/{token}", s.handleSharePassword)
|
||||||
|
|
||||||
|
mux.HandleFunc("GET /login", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
data, _ := web.FS.ReadFile("login.html")
|
||||||
|
w.Write(data)
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.HandleFunc("GET /{$}", s.requireAuthPage(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
data, _ := web.FS.ReadFile("index.html")
|
||||||
|
w.Write(data)
|
||||||
|
}))
|
||||||
|
|
||||||
|
mux.Handle("GET /style.css", http.FileServerFS(web.FS))
|
||||||
|
mux.Handle("GET /app.js", http.FileServerFS(web.FS))
|
||||||
|
mux.Handle("GET /alpine.min.js", http.FileServerFS(web.FS))
|
||||||
|
|
||||||
|
return mux
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
// placeholder
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
// placeholder
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html><head><title>yDropbox</title></head><body><h1>yDropbox</h1></body></html>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html><head><title>Login</title></head><body><h1>Login</h1></body></html>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
/* placeholder */
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed login.html index.html style.css app.js alpine.min.js
|
||||||
|
var FS embed.FS
|
||||||
Reference in New Issue
Block a user