mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-10-30 01:26:43 +08:00
59 lines
2.2 KiB
Go
59 lines
2.2 KiB
Go
package router
|
|
|
|
import (
|
|
"github.com/mickael-kerjean/mux"
|
|
. "github.com/mickael-kerjean/nuage/server/common"
|
|
. "github.com/mickael-kerjean/nuage/server/ctrl"
|
|
"log"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
func Init(a *App) *http.Server {
|
|
r := mux.NewRouter()
|
|
|
|
// API
|
|
session := r.PathPrefix("/api/session").Subrouter()
|
|
session.HandleFunc("", APIHandler(SessionGet, *a)).Methods("GET")
|
|
session.HandleFunc("", APIHandler(SessionAuthenticate, *a)).Methods("POST")
|
|
session.HandleFunc("", APIHandler(SessionLogout, *a)).Methods("DELETE")
|
|
session.Handle("/auth/{service}", APIHandler(SessionOAuthBackend, *a)).Methods("GET")
|
|
|
|
files := r.PathPrefix("/api/files").Subrouter()
|
|
files.HandleFunc("/ls", APIHandler(LoggedInOnly(FileLs), *a)).Methods("GET")
|
|
files.HandleFunc("/cat", APIHandler(LoggedInOnly(FileCat), *a)).Methods("GET")
|
|
files.HandleFunc("/cat", APIHandler(LoggedInOnly(FileSave), *a)).Methods("POST")
|
|
files.HandleFunc("/mv", APIHandler(LoggedInOnly(FileMv), *a)).Methods("GET")
|
|
files.HandleFunc("/rm", APIHandler(LoggedInOnly(FileRm), *a)).Methods("GET")
|
|
files.HandleFunc("/mkdir", APIHandler(LoggedInOnly(FileMkdir), *a)).Methods("GET")
|
|
files.HandleFunc("/touch", APIHandler(LoggedInOnly(FileTouch), *a)).Methods("GET")
|
|
|
|
share := r.PathPrefix("/api/share").Subrouter()
|
|
share.HandleFunc("", APIHandler(ShareList, *a)).Methods("GET")
|
|
share.HandleFunc("/{id}", APIHandler(ShareGet, *a)).Methods("GET")
|
|
share.HandleFunc("/{id}", APIHandler(ShareUpsert, *a)).Methods("POST")
|
|
share.HandleFunc("/{id}", APIHandler(ShareDelete, *a)).Methods("DELETE")
|
|
share.HandleFunc("/{id}/proof", APIHandler(ShareVerifyProof, *a)).Methods("POST")
|
|
|
|
// WEBDAV
|
|
r.PathPrefix("/s/{id}").Handler(APIHandler(WebdavHandler, *a))
|
|
|
|
// APP
|
|
r.HandleFunc("/api/config", CtxInjector(ConfigHandler, *a)).Methods("GET")
|
|
r.PathPrefix("/assets").Handler(StaticHandler("./data/public/", *a)).Methods("GET")
|
|
r.PathPrefix("/").Handler(DefaultHandler("./data/public/index.html", *a)).Methods("GET")
|
|
|
|
srv := &http.Server{
|
|
Addr: ":" + strconv.Itoa(a.Config.General.Port),
|
|
Handler: r,
|
|
}
|
|
go func() {
|
|
if err := srv.ListenAndServe(); err != nil {
|
|
log.Fatal("SERVER START ERROR ", err)
|
|
return
|
|
}
|
|
log.Println("SERVER START OK")
|
|
}()
|
|
return srv
|
|
}
|