1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-21 22:29:41 +02:00
This commit is contained in:
HarveyKandola 2018-07-28 11:43:45 -04:00
parent 743eae5aad
commit d0970c153b
8 changed files with 287 additions and 8 deletions

View file

@ -726,3 +726,36 @@ func (h *Handler) Vote(w http.ResponseWriter, r *http.Request) {
response.WriteEmpty(w)
}
// Export returns content as self-enclosed HTML file.
func (h *Handler) Export(w http.ResponseWriter, r *http.Request) {
method := "document.Export"
ctx := domain.GetRequestContext(r)
defer streamutil.Close(r.Body)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
response.WriteBadRequestError(w, method, err.Error())
h.Runtime.Log.Error(method, err)
return
}
spec := exportSpec{}
err = json.Unmarshal(body, &spec)
if err != nil {
response.WriteBadRequestError(w, method, err.Error())
h.Runtime.Log.Error(method, err)
return
}
export, err := BuildExport(ctx, *h.Store, spec)
if err != nil {
response.WriteServerError(w, method, err)
h.Runtime.Log.Error(method, err)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte(export))
w.WriteHeader(http.StatusOK)
}