dropboxfs.go 787 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dropboxfs
  2. import (
  3. "time"
  4. "dev.hexasoftware.com/hxs/cloudmount/internal/core"
  5. "dev.hexasoftware.com/hxs/cloudmount/internal/fs/basefs"
  6. "dev.hexasoftware.com/hxs/prettylog"
  7. )
  8. var (
  9. log = prettylog.New("dropboxfs")
  10. )
  11. type DropboxFS struct {
  12. *basefs.BaseFS
  13. serviceConfig *Config
  14. nextRefresh time.Time
  15. }
  16. func New(core *core.Core) core.DriverFS {
  17. fs := &DropboxFS{basefs.New(core), &Config{}, time.Now()}
  18. client := fs.initClient() // Init Oauth2 client
  19. //client.Verbose = true
  20. // Set necesary service
  21. fs.BaseFS.Service = &Service{client}
  22. return fs
  23. }
  24. func (fs *DropboxFS) Start() {
  25. Service := fs.Service.(*Service)
  26. // Fill root container and do changes
  27. go func() {
  28. fs.Refresh()
  29. for {
  30. Service.Changes()
  31. time.Sleep(fs.Config.RefreshTime)
  32. }
  33. }()
  34. }