1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00
documize/core/api/convert/convert.go

97 lines
2.7 KiB
Go
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
2016-10-17 14:03:20 -07:00
// This software (Documize Community Edition) is licensed under
2016-07-07 18:54:16 -07:00
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
2016-10-17 14:03:20 -07:00
// by contacting <sales@documize.com>.
2016-07-07 18:54:16 -07:00
//
// https://documize.com
// Package convert provides the gateway to document conversion native and plugin functionality, both in and out of the system.
package convert
import (
"errors"
2017-07-21 13:39:53 +01:00
2016-07-20 15:58:37 +01:00
"github.com/documize/community/core/api/convert/html"
"github.com/documize/community/core/api/plugins"
2016-10-17 14:03:20 -07:00
api "github.com/documize/community/core/convapi"
2016-07-07 18:54:16 -07:00
2022-03-16 13:32:27 -04:00
"context"
2016-07-07 18:54:16 -07:00
)
// Convert provides the entry-point into the document conversion process.
func Convert(ctx context.Context, xtn string, fileRequest *api.DocumentConversionRequest) (*api.DocumentConversionResponse, error) {
fileResultI, err := plugins.Lib.Run(ctx, "Convert", xtn, fileRequest)
if err != nil {
return nil, err
}
fileResult, ok := fileResultI.(*api.DocumentConversionResponse)
if !ok {
return nil, errors.New("interface conversion: interface {} is nil, not *api.ConversionFileResponse")
}
if fileResult.Err != "" {
return nil, errors.New(fileResult.Err)
}
err = html.SplitIfHTML(fileRequest, fileResult)
if err != nil {
return nil, err
}
/* TODO add title & body santization that keeps the images & table formatting
for p, pg := range fileResult.Pages {
fileResult.Pages[p].Title = titlePolicy.Sanitize(pg.Title)
fileResult.Pages[p].Body = bodyPolicy.SanitizeBytes(pg.Body)
}
*/
return fileResult, nil
}
/* TODO add sanitisation for body & title HTML
var titlePolicy, bodyPolicy *bluemonday.Policy
2017-07-21 13:39:53 +01:00
func xxx() {
2016-07-07 18:54:16 -07:00
policy := bluemonday.UGCPolicy()
policy.RequireNoFollowOnLinks(true)
// URLs must be parseable by net/url.Parse()
policy.RequireParseableURLs(true)
policy.AllowRelativeURLs(false)
policy.AllowURLSchemes("http", "https")
// replacement below for: policy.AllowDataURIImages()
// Supply a function to validate images contained within data URI
policy.AllowURLSchemeWithCustomPolicy(
"data",
func(url *url.URL) (allowUrl bool) {
if url.RawQuery != "" || url.Fragment != "" {
return false
}
// matched := dataURIImagePrefix.FindString(url.Opaque)
// if matched == "" {
// return false
// }
// _, err := base64.StdEncoding.DecodeString(url.Opaque[len(matched):])
// if err != nil {
// return false
// }
return true
})
policy.AllowImages()
// TODO remove links to #tags
// TODO allow DataURI of image/* for LibreOffice ppt output
bodyPolicy = policy
titlePolicy = bluemonday.StrictPolicy()
}
*/