github.com/jancarloviray/community@v0.41.1-0.20170124221257-33a66c87cf2f/core/api/store/store.go (about) 1 // Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved. 2 // 3 // This software (Documize Community Edition) is licensed under 4 // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html 5 // 6 // You can operate outside the AGPL restrictions by purchasing 7 // Documize Enterprise Edition and obtaining a commercial license 8 // by contacting <sales@documize.com>. 9 // 10 // https://documize.com 11 12 package store 13 14 import ( 15 "errors" 16 "strings" 17 18 "github.com/documize/community/core/api/entity" 19 api "github.com/documize/community/core/convapi" 20 "github.com/documize/community/core/utility" 21 ) 22 23 // StorageProvider describes the interface for document conversion and take-on. 24 type StorageProvider interface { 25 Upload(job string, filename string, file []byte) (err error) 26 Convert(api.ConversionJobRequest) (filename string, fileResult *api.DocumentConversionResponse, err error) 27 } 28 29 // ConvertFileResult takes the results of a document upload and convert, 30 // and creates the outline of a database record suitable for inserting into the document 31 // table. 32 func ConvertFileResult(filename string, fileResult *api.DocumentConversionResponse) (document entity.Document) { 33 34 document = entity.Document{} 35 36 document.RefID = "" 37 document.OrgID = "" 38 document.LabelID = "" 39 document.Job = "" 40 document.Location = filename 41 42 if fileResult != nil { 43 if len(fileResult.Pages) > 0 { 44 document.Title = fileResult.Pages[0].Title 45 document.Slug = utility.MakeSlug(fileResult.Pages[0].Title) 46 } 47 document.Excerpt = fileResult.Excerpt 48 } 49 50 document.Tags = "" // now a # separated list of tag-words, rather than JSON 51 52 return document 53 } 54 55 // ExportAs takes a target extension name and html to create an exported file. 56 // If the target extension is "html" it simply returns the given html suitably wrapped, 57 // otherwise it runs the "Export" plugin for the given target extension name. 58 func ExportAs(xtn, html string) (*api.DocumentExport, error) { 59 60 if strings.ToLower(xtn) == "html" { 61 return &api.DocumentExport{File: []byte(html), Format: "html"}, nil 62 } 63 return nil, errors.New("Only 'HTML' export is supported") 64 65 /* This functionality removed for now 66 fileI, err := plugins.Lib.Run(nil, "Export", xtn, []byte(html)) 67 if err != nil { 68 log.Error("ExportAs failed", err) 69 return nil, err 70 } 71 return fileI.(*api.DocumentExport), nil 72 */ 73 }