Skip to content

Commit 67bb3ba

Browse files
Merge pull request #162 from documize/export-html
Export spaces, categories, documents to self-enclosed HTML file
2 parents 743eae5 + 3967779 commit 67bb3ba

File tree

19 files changed

+1355
-722
lines changed

19 files changed

+1355
-722
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ Space view.
5858

5959
## Latest version
6060

61-
[Community edition: v1.67.0](https://github.com/documize/community/releases)
61+
[Community edition: v1.68.0](https://github.com/documize/community/releases)
6262

63-
[Enterprise edition: v1.69.0](https://documize.com/downloads)
63+
[Enterprise edition: v1.70.0](https://documize.com/downloads)
6464

6565
## OS support
6666

domain/document/endpoint.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,3 +726,48 @@ func (h *Handler) Vote(w http.ResponseWriter, r *http.Request) {
726726

727727
response.WriteEmpty(w)
728728
}
729+
730+
// Export returns content as self-enclosed HTML file.
731+
func (h *Handler) Export(w http.ResponseWriter, r *http.Request) {
732+
method := "document.Export"
733+
ctx := domain.GetRequestContext(r)
734+
735+
// Deduce ORG if anon user.
736+
if len(ctx.OrgID) == 0 {
737+
ctx.Subdomain = organization.GetSubdomainFromHost(r)
738+
org, err := h.Store.Organization.GetOrganizationByDomain(ctx.Subdomain)
739+
if err != nil {
740+
response.WriteServerError(w, method, err)
741+
h.Runtime.Log.Error(method, err)
742+
return
743+
}
744+
ctx.OrgID = org.RefID
745+
}
746+
747+
defer streamutil.Close(r.Body)
748+
body, err := ioutil.ReadAll(r.Body)
749+
if err != nil {
750+
response.WriteBadRequestError(w, method, err.Error())
751+
h.Runtime.Log.Error(method, err)
752+
return
753+
}
754+
755+
spec := exportSpec{}
756+
err = json.Unmarshal(body, &spec)
757+
if err != nil {
758+
response.WriteBadRequestError(w, method, err.Error())
759+
h.Runtime.Log.Error(method, err)
760+
return
761+
}
762+
763+
export, err := BuildExport(ctx, *h.Store, spec)
764+
if err != nil {
765+
response.WriteServerError(w, method, err)
766+
h.Runtime.Log.Error(method, err)
767+
return
768+
}
769+
770+
w.Header().Set("Content-Type", "text/html; charset=utf-8")
771+
w.WriteHeader(http.StatusOK)
772+
w.Write([]byte(export))
773+
}

0 commit comments

Comments
 (0)