forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.go
120 lines (104 loc) · 4.14 KB
/
plugins.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Copyright (c) 2018. Abstrium SAS <team (at) pydio.com>
* This file is part of Pydio Cells.
*
* Pydio Cells is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio Cells is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio Cells. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <https://pydio.com>.
*/
// Package grpc exposes the document store api in GRPC
package grpc
import (
"context"
"path"
"github.com/golang/protobuf/jsonpb"
"github.com/micro/go-micro"
"go.uber.org/zap"
"github.com/pydio/cells/common"
"github.com/pydio/cells/common/config"
"github.com/pydio/cells/common/log"
"github.com/pydio/cells/common/plugins"
proto "github.com/pydio/cells/common/proto/docstore"
"github.com/pydio/cells/common/proto/sync"
"github.com/pydio/cells/common/proto/tree"
"github.com/pydio/cells/common/service"
"github.com/pydio/cells/data/docstore"
)
func init() {
plugins.Register(func() {
service.NewService(
service.Name(common.SERVICE_GRPC_NAMESPACE_+common.SERVICE_DOCSTORE),
service.Tag(common.SERVICE_TAG_DATA),
service.Description("Generic document store"),
service.Unique(true),
service.WithMicro(func(m micro.Service) error {
serviceDir, e := config.ServiceDataDir(common.SERVICE_GRPC_NAMESPACE_ + common.SERVICE_DOCSTORE)
if e != nil {
return e
}
store, err := docstore.NewBoltStore(path.Join(serviceDir, "docstore.db"))
if err != nil {
return err
}
indexer, err := docstore.NewBleveEngine(path.Join(serviceDir, "docstore.bleve"))
if err != nil {
return err
}
handler := &Handler{
Db: store,
Indexer: indexer,
}
for id, json := range defaults() {
if doc, e := store.GetDocument(common.DOCSTORE_ID_VIRTUALNODES, id); e == nil && doc != nil {
var reStore bool
if id == "my-files" {
// Check if my-files is up-to-date
var vNode tree.Node
if e := jsonpb.UnmarshalString(doc.Data, &vNode); e == nil {
if _, ok := vNode.MetaStore["onDelete"]; !ok {
log.Logger(m.Options().Context).Info("Upgrading my-files template path for onDelete policy")
vNode.MetaStore["onDelete"] = "rename-uuid"
m := &jsonpb.Marshaler{}
json, _ = m.MarshalToString(&vNode)
reStore = true
}
} else {
log.Logger(m.Options().Context).Info("Cannot unmarshall", zap.Error(e))
}
}
if !reStore {
continue
}
}
handler.PutDocument(context.Background(),
&proto.PutDocumentRequest{StoreID: common.DOCSTORE_ID_VIRTUALNODES, DocumentID: id, Document: &proto.Document{
ID: id,
Owner: common.PYDIO_SYSTEM_USERNAME,
Data: json,
}}, &proto.PutDocumentResponse{})
}
m.Init(micro.BeforeStop(handler.Close))
proto.RegisterDocStoreHandler(m.Options().Server, handler)
sync.RegisterSyncEndpointHandler(m.Options().Server, handler)
return nil
}),
)
})
}
func defaults() map[string]string {
return map[string]string{
"my-files": `{"Uuid":"my-files","Path":"my-files","Type":"COLLECTION","MetaStore":{"name":"my-files", "onDelete":"rename-uuid","resolution":"\/\/ Default node used for storing personal users data in separate folders. \n\/\/ Use Ctrl+Space to see the objects available for completion.\nPath = DataSources.personal + \"\/\" + User.Name;","contentType":"text\/javascript"}}`,
"cells": `{"Uuid":"cells","Path":"cells","Type":"COLLECTION","MetaStore":{"name":"cells","resolution":"\/\/ Default node used as parent for creating empty cells. \n\/\/ Use Ctrl+Space to see the objects available for completion.\nPath = DataSources.cellsdata + \"\/\" + User.Name;","contentType":"text\/javascript"}}`,
}
}