32088696d08c0e24e55a7dd4b5ddaa3f5b452af6
[src/xds/xds-server.git] / lib / folder / folder-interface.go
1 package folder
2
3 // FolderType definition
4 type FolderType string
5
6 const (
7         TypePathMap   = "PathMap"
8         TypeCloudSync = "CloudSync"
9         TypeCifsSmb   = "CIFS"
10 )
11
12 // Folder Status definition
13 const (
14         StatusErrorConfig = "ErrorConfig"
15         StatusDisable     = "Disable"
16         StatusEnable      = "Enable"
17         StatusPause       = "Pause"
18         StatusSyncing     = "Syncing"
19 )
20
21 type EventCBData map[string]interface{}
22 type EventCB func(cfg *FolderConfig, data *EventCBData)
23
24 // IFOLDER Folder interface
25 type IFOLDER interface {
26         NewUID(suffix string) string                              // Get a new folder UUID
27         Add(cfg FolderConfig) (*FolderConfig, error)              // Add a new folder
28         GetConfig() FolderConfig                                  // Get folder public configuration
29         GetFullPath(dir string) string                            // Get folder full path
30         ConvPathCli2Svr(s string) string                          // Convert path from Client to Server
31         ConvPathSvr2Cli(s string) string                          // Convert path from Server to Client
32         Remove() error                                            // Remove a folder
33         Update(cfg FolderConfig) (*FolderConfig, error)           // Update a new folder
34         RegisterEventChange(cb *EventCB, data *EventCBData) error // Request events registration (sent through WS)
35         UnRegisterEventChange() error                             // Un-register events
36         Sync() error                                              // Force folder files synchronization
37         IsInSync() (bool, error)                                  // Check if folder files are in-sync
38 }
39
40 // FolderConfig is the config for one folder
41 type FolderConfig struct {
42         ID         string     `json:"id"`
43         Label      string     `json:"label"`
44         ClientPath string     `json:"path"`
45         Type       FolderType `json:"type"`
46         Status     string     `json:"status"`
47         IsInSync   bool       `json:"isInSync"`
48         DefaultSdk string     `json:"defaultSdk"`
49         ClientData string     `json:"clientData"` // free form field that can used by client
50
51         // Not exported fields from REST API point of view
52         RootPath string `json:"-"`
53
54         // FIXME: better to define an equivalent to union data and then implement
55         // UnmarshalJSON/MarshalJSON to decode/encode according to Type value
56         // Data interface{} `json:"data"`
57
58         // Specific data depending on which Type is used
59         DataPathMap   PathMapConfig   `json:"dataPathMap,omitempty"`
60         DataCloudSync CloudSyncConfig `json:"dataCloudSync,omitempty"`
61 }
62
63 // FolderConfigUpdatableFields List fields that can be updated using Update function
64 var FolderConfigUpdatableFields = []string{
65         "Label", "DefaultSdk", "ClientData",
66 }
67
68 // PathMapConfig Path mapping specific data
69 type PathMapConfig struct {
70         ServerPath string `json:"serverPath"`
71
72         // Don't keep temporary file name (IOW we don't want to save it and reuse it)
73         CheckFile    string `json:"checkFile" xml:"-"`
74         CheckContent string `json:"checkContent" xml:"-"`
75 }
76
77 // CloudSyncConfig CloudSync (AKA Syncthing) specific data
78 type CloudSyncConfig struct {
79         SyncThingID string `json:"syncThingID"`
80 }