1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-05 05:25:27 +02:00

removed old API

This commit is contained in:
Harvey Kandola 2017-08-02 15:26:31 +01:00
parent e284a46f86
commit 562872a4a8
105 changed files with 337 additions and 14496 deletions

View file

@ -19,13 +19,13 @@ import (
"net/http"
"strings"
"github.com/documize/community/core/api/store"
api "github.com/documize/community/core/convapi"
"github.com/documize/community/core/request"
"github.com/documize/community/core/response"
"github.com/documize/community/core/stringutil"
"github.com/documize/community/core/uniqueid"
"github.com/documize/community/domain"
"github.com/documize/community/domain/conversion/store"
"github.com/documize/community/domain/document"
"github.com/documize/community/model/activity"
"github.com/documize/community/model/attachment"
@ -36,7 +36,7 @@ import (
"github.com/pkg/errors"
)
var storageProvider store.StorageProvider
var storageProvider StorageProvider
func init() {
storageProvider = new(store.LocalStorageProvider)
@ -91,8 +91,8 @@ func (h *Handler) convert(w http.ResponseWriter, r *http.Request, job, folderID
method := "conversion.upload"
ctx := domain.GetRequestContext(r)
licenseKey := h.Store.Setting.Get(ctx, "EDITION-LICENSE", "key")
licenseSignature := h.Store.Setting.Get(ctx, "EDITION-LICENSE", "signature")
licenseKey := h.Store.Setting.Get("EDITION-LICENSE", "key")
licenseSignature := h.Store.Setting.Get("EDITION-LICENSE", "signature")
k, _ := hex.DecodeString(licenseKey)
s, _ := hex.DecodeString(licenseSignature)

View file

@ -15,14 +15,12 @@ package store
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/documize/community/core/api/convert"
api "github.com/documize/community/core/convapi"
"github.com/documize/community/core/log"
)
var folderPath string
@ -33,8 +31,7 @@ func init() {
tempDir += string(os.PathSeparator)
}
folderPath = tempDir + "documize" + string(os.PathSeparator) + "_uploads" + string(os.PathSeparator)
log.Info("Temporary upload directory: " + folderPath)
log.IfErr(os.MkdirAll(folderPath, os.ModePerm))
os.MkdirAll(folderPath, os.ModePerm)
}
// LocalStorageProvider provides an implementation of StorageProvider.
@ -48,14 +45,12 @@ func (store *LocalStorageProvider) Upload(job string, filename string, file []by
err = os.MkdirAll(destination, os.ModePerm)
if err != nil {
log.Error(fmt.Sprintf("Cannot create local folder %s", destination), err)
return err
}
err = ioutil.WriteFile(destination+filename, file, 0666)
if err != nil {
log.Error(fmt.Sprintf("Cannot write to local file %s", destination+filename), err)
return err
}
@ -85,18 +80,15 @@ func (store *LocalStorageProvider) Convert(params api.ConversionJobRequest) (fil
}
// remove temporary directory on exit
defer func() { log.IfErr(os.RemoveAll(inputFolder)) }()
defer func() { os.RemoveAll(inputFolder) }()
for _, v := range list {
if v.Size() > 0 && !strings.HasPrefix(v.Name(), ".") && v.Mode().IsRegular() {
filename = inputFolder + v.Name()
log.Info(fmt.Sprintf("Fetching document %s", filename))
fileData, err := ioutil.ReadFile(filename)
if err != nil {
log.Error(fmt.Sprintf("Unable to fetch document %s", filename), err)
return filename, fileResult, err
}

View file

@ -1,90 +0,0 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// 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
// by contacting <sales@documize.com>.
//
// https://documize.com
package store
import (
"github.com/documize/community/core/api/plugins"
"github.com/documize/community/core/api/util"
api "github.com/documize/community/core/convapi"
"github.com/documize/community/core/log"
"io/ioutil"
"os"
"strings"
"testing"
)
var lsp LocalStorageProvider
func TestUpload(t *testing.T) {
jb := "job" + uniqueid.Generate()
fn := "file.txt"
cont := "content\n"
err := lsp.Upload(jb, fn, []byte(cont))
if err != nil {
t.Error(err)
}
b, e := ioutil.ReadFile(folderPath + jb + string(os.PathSeparator) + fn)
if e != nil {
t.Error(e)
}
if string(b) != cont {
t.Error("wrong content:" + string(b))
}
}
func TestConvert(t *testing.T) {
_, _, err :=
lsp.Convert(api.ConversionJobRequest{})
if err == nil {
t.Error("there should have been a convert error")
}
err = plugins.LibSetup()
if err == nil {
// t.Error("did not error with missing config.json")
}
defer log.IfErr(plugins.Lib.KillSubProcs())
jb := "job" + uniqueid.Generate()
_, _, err =
lsp.Convert(api.ConversionJobRequest{
Job: jb,
IndexDepth: 9,
OrgID: "Documize",
})
if err == nil {
t.Error("there should have been an error - directory not found")
}
fn := "content.html"
cont := "content\n"
err = lsp.Upload(jb, fn, []byte(cont))
if err != nil {
t.Error(err)
}
filename, fileResult, err :=
lsp.Convert(api.ConversionJobRequest{
Job: jb,
IndexDepth: 9,
OrgID: "Documize",
})
if err != nil {
t.Error(err)
}
if !strings.HasSuffix(filename, fn) {
t.Error("wrong filename:" + filename)
}
if fileResult.Excerpt != "content." {
t.Error("wrong excerpt:" + fileResult.Excerpt)
}
}