9 // FolderType constances
12 FolderTypeWindowsSubsystem = 1
13 FolderTypeCloudSync = 2
15 FolderStatusErrorConfig = "ErrorConfig"
16 FolderStatusDisable = "Disable"
17 FolderStatusEnable = "Enable"
20 // FolderType is the type of sharing folder
23 // FolderConfig is the config for one folder
24 type FolderConfig struct {
25 ID string `json:"id" binding:"required"`
26 Label string `json:"label"`
27 RelativePath string `json:"path"`
28 Type FolderType `json:"type"`
29 SyncThingID string `json:"syncThingID"`
30 BuilderSThgID string `json:"builderSThgID"`
31 Status string `json:"status"`
37 // NewFolderConfig creates a new folder object
38 func NewFolderConfig(id, label, rootDir, path string) FolderConfig {
43 Type: FolderTypeCloudSync,
45 Status: FolderStatusDisable,
50 // GetFullPath returns the full path
51 func (c *FolderConfig) GetFullPath(dir string) string {
55 if filepath.IsAbs(dir) {
56 return filepath.Join(c.rootPath, dir)
58 return filepath.Join(c.rootPath, c.RelativePath, dir)
61 // FolderVerify is called to verify that a configuration is valid
62 func FolderVerify(fCfg FolderConfig) error {
65 if fCfg.Type != FolderTypeCloudSync {
66 err = fmt.Errorf("Unsupported folder type")
69 if fCfg.SyncThingID == "" {
70 err = fmt.Errorf("device id not set (SyncThingID field)")
74 fCfg.Status = FolderStatusErrorConfig
75 log.Printf("ERROR FolderVerify: %v\n", err)