Skip to content

Commit f8410ca

Browse files
committed
change(service-account-server): refactor into own package and implement for uploader
1 parent 44dd989 commit f8410ca

File tree

8 files changed

+260
-218
lines changed

8 files changed

+260
-218
lines changed

cmd/sync.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ func performSync(s *syncer.Syncer) error {
123123
s.Log.Info("Running...")
124124

125125
var gcloneParams []string
126-
if strings.Contains(s.GlobalConfig.Rclone.Path, "gclone") {
126+
if strings.Contains(s.GlobalConfig.Rclone.Path, "gclone") &&
127+
s.RemoteServiceAccountFiles.ServiceAccountsCount() > 0 {
127128
// start web-server
128129
s.Ws.Run()
129130
defer s.Ws.Stop()

cmd/upload.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"fmt"
45
"github.com/dustin/go-humanize"
56
"github.com/l3uddz/crop/cache"
67
"github.com/l3uddz/crop/config"
@@ -116,6 +117,20 @@ func init() {
116117
func performUpload(u *uploader.Uploader) error {
117118
u.Log.Info("Running...")
118119

120+
var gcloneParams []string
121+
122+
if strings.Contains(u.GlobalConfig.Rclone.Path, "gclone") &&
123+
u.RemoteServiceAccountFiles.ServiceAccountsCount() > 0 {
124+
// start web-server
125+
u.Ws.Run()
126+
defer u.Ws.Stop()
127+
128+
gcloneParams = append(gcloneParams,
129+
"--drive-service-account-url",
130+
fmt.Sprintf("http://%s:%d", u.Ws.Host, u.Ws.Port),
131+
)
132+
}
133+
119134
/* Cleans */
120135
if u.Config.Hidden.Enabled {
121136
err := performClean(u)
@@ -132,6 +147,11 @@ func performUpload(u *uploader.Uploader) error {
132147
additionalRcloneParams = u.CheckRcloneParams()
133148
}
134149

150+
// add gclone params set
151+
if len(gcloneParams) > 0 {
152+
additionalRcloneParams = append(additionalRcloneParams, gcloneParams...)
153+
}
154+
135155
/* Copies */
136156
if len(u.Config.Remotes.Copy) > 0 {
137157
u.Log.Info("Running copies...")

syncer/syncer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/l3uddz/crop/config"
55
"github.com/l3uddz/crop/logger"
66
"github.com/l3uddz/crop/rclone"
7+
"github.com/l3uddz/crop/web"
78
"github.com/pkg/errors"
89
"github.com/sirupsen/logrus"
910
)
@@ -15,7 +16,7 @@ type Syncer struct {
1516
Config *config.SyncerConfig
1617
Name string
1718
RemoteServiceAccountFiles *rclone.ServiceAccountManager
18-
Ws *WebServer
19+
Ws *web.Server
1920
}
2021

2122
func New(config *config.Configuration, syncerConfig *config.SyncerConfig, syncerName string, parallelism int) (*Syncer, error) {
@@ -40,7 +41,7 @@ func New(config *config.Configuration, syncerConfig *config.SyncerConfig, syncer
4041
Config: syncerConfig,
4142
Name: syncerName,
4243
RemoteServiceAccountFiles: sam,
43-
Ws: newWebServer("127.0.0.1", l, syncerName, sam),
44+
Ws: web.New("127.0.0.1", l, syncerName, sam),
4445
}
4546

4647
return syncer, nil

syncer/web.go

Lines changed: 0 additions & 214 deletions
This file was deleted.

uploader/uploader.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/l3uddz/crop/reutils"
1010
"github.com/l3uddz/crop/uploader/checker"
1111
"github.com/l3uddz/crop/uploader/cleaner"
12+
"github.com/l3uddz/crop/web"
1213
"github.com/pkg/errors"
1314
"github.com/sirupsen/logrus"
1415
"regexp"
@@ -34,6 +35,8 @@ type Uploader struct {
3435
LocalFilesSize uint64
3536
HiddenFiles []pathutils.Path
3637
HiddenFolders []pathutils.Path
38+
39+
Ws *web.Server
3740
}
3841

3942
func New(config *config.Configuration, uploaderConfig *config.UploaderConfig, uploaderName string) (*Uploader, error) {
@@ -100,8 +103,9 @@ func New(config *config.Configuration, uploaderConfig *config.UploaderConfig, up
100103
}
101104

102105
// init uploader
106+
l := logger.GetLogger(uploaderName)
103107
uploader := &Uploader{
104-
Log: logger.GetLogger(uploaderName),
108+
Log: l,
105109
GlobalConfig: config,
106110
Config: uploaderConfig,
107111
Name: uploaderName,
@@ -110,6 +114,7 @@ func New(config *config.Configuration, uploaderConfig *config.UploaderConfig, up
110114
IncludePatterns: includePatterns,
111115
ExcludePatterns: excludePatterns,
112116
RemoteServiceAccountFiles: sam,
117+
Ws: web.New("127.0.0.1", l, uploaderName, sam),
113118
}
114119

115120
return uploader, nil

0 commit comments

Comments
 (0)