Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
64 lines
1.1 KiB
Go
64 lines
1.1 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
)
|
|
|
|
func (s *Server) handleRestoreRevisionAPI(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
if r.Method != http.MethodPost {
|
|
w.Header().Set("Allow", "POST")
|
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
|
return
|
|
}
|
|
|
|
revisionUUID :=
|
|
r.URL.Query().Get("revision")
|
|
|
|
metadata, err :=
|
|
s.store.GetRevisionMetadata(
|
|
revisionUUID,
|
|
)
|
|
|
|
if err != nil {
|
|
http.Error(
|
|
w,
|
|
err.Error(),
|
|
500,
|
|
)
|
|
return
|
|
}
|
|
if s.authorizeObjectForRequest(r, "write", metadata.ObjectUUID) != nil {
|
|
http.Error(w, "forbidden", http.StatusForbidden)
|
|
return
|
|
}
|
|
// Authorize metadata before hydrating the potentially large source body.
|
|
revision, err := s.store.GetRevision(revisionUUID)
|
|
if err != nil {
|
|
http.Error(w, "revision unavailable", http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
_, err = s.store.SaveRevisionContent(
|
|
revision.ObjectUUID,
|
|
[]byte(revision.Body),
|
|
"restore revision",
|
|
revision.Language,
|
|
revision.ContentType,
|
|
revision.Filename,
|
|
)
|
|
|
|
if err != nil {
|
|
http.Error(
|
|
w,
|
|
err.Error(),
|
|
500,
|
|
)
|
|
return
|
|
}
|
|
|
|
_, _ = w.Write([]byte("ok"))
|
|
}
|