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
@@ -0,0 +1,137 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func objectUUIDFromURI(uri string) (string, bool) {
|
||||
|
||||
if !strings.HasPrefix(uri, "uuid:") {
|
||||
return "", false
|
||||
}
|
||||
|
||||
uuid := strings.TrimPrefix(uri, "uuid:")
|
||||
|
||||
if uuid == "" {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return uuid, true
|
||||
}
|
||||
|
||||
func (s *Server) handleObjectView(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
) {
|
||||
|
||||
uri := strings.TrimPrefix(r.URL.Path, "/o/")
|
||||
|
||||
objectUUID, ok := objectUUIDFromURI(uri)
|
||||
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
latest, err :=
|
||||
s.store.GetLatestRevision(objectUUID)
|
||||
|
||||
if err != nil {
|
||||
|
||||
http.Error(
|
||||
w,
|
||||
err.Error(),
|
||||
500,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
s.render(
|
||||
w,
|
||||
"object_view.gohtml",
|
||||
map[string]any{
|
||||
"Title": "Object View",
|
||||
"ObjectUUID": objectUUID,
|
||||
"ObjectURI": uri,
|
||||
"RenderedHTML": template.HTML(latest.Body),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (s *Server) handleObjectEdit(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
) {
|
||||
|
||||
uri := strings.TrimPrefix(r.URL.Path, "/o/e/")
|
||||
|
||||
objectUUID, ok := objectUUIDFromURI(uri)
|
||||
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
latest, err :=
|
||||
s.store.GetLatestRevision(objectUUID)
|
||||
|
||||
body := ""
|
||||
|
||||
if err == nil && latest != nil {
|
||||
body = latest.Body
|
||||
}
|
||||
|
||||
s.render(
|
||||
w,
|
||||
"object_editor.gohtml",
|
||||
map[string]any{
|
||||
"Title": "Object Edit",
|
||||
"ObjectUUID": objectUUID,
|
||||
"ObjectURI": uri,
|
||||
"Body": body,
|
||||
"EditType": "html",
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (s *Server) handleObjectRevisionHistory(
|
||||
w http.ResponseWriter,
|
||||
r *http.Request,
|
||||
) {
|
||||
|
||||
uri := strings.TrimPrefix(r.URL.Path, "/o/r/")
|
||||
|
||||
objectUUID, ok := objectUUIDFromURI(uri)
|
||||
|
||||
if !ok {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
revisions, err :=
|
||||
s.store.ListRevisions(objectUUID)
|
||||
|
||||
if err != nil {
|
||||
|
||||
http.Error(
|
||||
w,
|
||||
err.Error(),
|
||||
500,
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
s.render(
|
||||
w,
|
||||
"revisions.gohtml",
|
||||
map[string]any{
|
||||
"Title": "Object Revision History",
|
||||
"ObjectUUID": objectUUID,
|
||||
"Revisions": revisions,
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user