forked from henrybear327/Proton-API-Bridge
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathproton_manager.go
More file actions
37 lines (29 loc) · 937 Bytes
/
proton_manager.go
File metadata and controls
37 lines (29 loc) · 937 Bytes
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
package common
import (
"github.com/rclone/go-proton-api"
"github.com/go-resty/resty/v2"
)
// Applies to all API calls made by the shared proton.Manager.
const defaultAPIRequestRetryCount = 3
type preRequestHookClient interface {
AddPreRequestHook(resty.RequestMiddleware)
}
func attachDriveSDKHeaderHook(client preRequestHookClient, driveSDKVersion string) {
if driveSDKVersion == "" {
return
}
client.AddPreRequestHook(func(_ *resty.Client, req *resty.Request) error {
req.SetHeader("x-pm-drive-sdk-version", driveSDKVersion)
return nil
})
}
func getProtonManager(appVersion string, userAgent string) *proton.Manager {
/* Notes on API calls: if the app version is not specified, the api calls will be rejected. */
options := []proton.Option{
proton.WithAppVersion(appVersion),
proton.WithRetryCount(defaultAPIRequestRetryCount),
proton.WithUserAgent(userAgent),
}
m := proton.New(options...)
return m
}