add features: object based control, and GC(periodic delete) zombie object
This commit is contained in:
1 parent
6ad039c536
commit
4da7d4e42d
18 files changed
+939
-75
No files matched your search
@@ -1,9 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
mw "pageswiki/internal/server/middleware"
|
||||
routespkg "pageswiki/internal/server/routes"
|
||||
@@ -30,9 +33,27 @@ func New(
|
||||
|
||||
s.registerStaticRoutes()
|
||||
|
||||
s.mux.HandleFunc(
|
||||
"/o/e/",
|
||||
s.handleObjectEdit,
|
||||
)
|
||||
|
||||
s.mux.HandleFunc(
|
||||
"/o/r/",
|
||||
s.handleObjectRevisionHistory,
|
||||
)
|
||||
|
||||
s.mux.HandleFunc(
|
||||
"/o/",
|
||||
s.handleObjectRoute,
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if strings.HasPrefix(r.URL.Path, "/o/uuid:") {
|
||||
s.handleObjectView(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
s.handleObjectRoute(w, r)
|
||||
},
|
||||
)
|
||||
|
||||
s.mux.HandleFunc(
|
||||
@@ -52,6 +73,8 @@ func New(
|
||||
|
||||
s.registerRoutes()
|
||||
|
||||
s.startGCWorker()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -94,6 +117,28 @@ func (s *Server) mustLoadTemplates() {
|
||||
|
||||
return out
|
||||
},
|
||||
|
||||
"formatBytes": func(n int) string {
|
||||
|
||||
if n < 1024 {
|
||||
return fmt.Sprintf("%d B", n)
|
||||
}
|
||||
|
||||
if n < 1024*1024 {
|
||||
return fmt.Sprintf("%.1f KiB", float64(n)/1024.0)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%.1f MiB", float64(n)/(1024.0*1024.0))
|
||||
},
|
||||
|
||||
"formatUnix": func(ts int64) string {
|
||||
|
||||
if ts <= 0 {
|
||||
return "-"
|
||||
}
|
||||
|
||||
return time.Unix(ts, 0).Format("2006-01-02 15:04")
|
||||
},
|
||||
}
|
||||
|
||||
tmpl := template.New("").Funcs(funcs)
|
||||
@@ -130,6 +175,7 @@ func (s *Server) registerRoutes() {
|
||||
routespkg.APIHandlers{
|
||||
CreateObject: s.handleCreateObjectAPI,
|
||||
ListObjects: s.handleListObjectsAPI,
|
||||
DeleteObject: s.handleDeleteObjectAPI,
|
||||
SaveRevision: s.handleSaveRevisionAPI,
|
||||
ListRevisions: s.handleRevisionListAPI,
|
||||
RestoreRevision: s.handleRestoreRevisionAPI,
|
||||
@@ -139,6 +185,8 @@ func (s *Server) registerRoutes() {
|
||||
RenamePath: s.handleRenamePath,
|
||||
RenamePreview: s.handleRenamePreview,
|
||||
RemovePath: s.handleRemovePathAPI,
|
||||
ZombieList: s.handleZombieListAPI,
|
||||
ZombiePurge: s.handleZombiePurgeAPI,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user