2022-08-28 19:21:57 +08:00
|
|
|
// Package putio provides an interface to the put.io storage system.
|
2019-08-06 20:47:52 +08:00
|
|
|
package putio
|
|
|
|
|
|
|
|
import (
|
2020-11-06 02:02:26 +08:00
|
|
|
"context"
|
2019-08-06 20:47:52 +08:00
|
|
|
"regexp"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/rclone/rclone/fs"
|
2020-01-15 01:33:35 +08:00
|
|
|
"github.com/rclone/rclone/fs/config"
|
2019-08-06 20:47:52 +08:00
|
|
|
"github.com/rclone/rclone/fs/config/configmap"
|
|
|
|
"github.com/rclone/rclone/fs/config/obscure"
|
|
|
|
"github.com/rclone/rclone/lib/dircache"
|
2020-01-15 01:33:35 +08:00
|
|
|
"github.com/rclone/rclone/lib/encoder"
|
2019-08-06 20:47:52 +08:00
|
|
|
"github.com/rclone/rclone/lib/oauthutil"
|
|
|
|
)
|
|
|
|
|
2019-10-02 18:23:10 +08:00
|
|
|
/*
|
|
|
|
// TestPutio
|
|
|
|
stringNeedsEscaping = []rune{
|
|
|
|
'/', '\x00'
|
|
|
|
}
|
|
|
|
maxFileLength = 255
|
|
|
|
canWriteUnnormalized = true
|
|
|
|
canReadUnnormalized = true
|
|
|
|
canReadRenormalized = true
|
|
|
|
canStream = false
|
|
|
|
*/
|
|
|
|
|
2019-08-06 20:47:52 +08:00
|
|
|
// Constants
|
|
|
|
const (
|
|
|
|
rcloneClientID = "4131"
|
|
|
|
rcloneObscuredClientSecret = "cMwrjWVmrHZp3gf1ZpCrlyGAmPpB-YY5BbVnO1fj-G9evcd8"
|
|
|
|
minSleep = 10 * time.Millisecond
|
|
|
|
maxSleep = 2 * time.Second
|
2022-03-22 16:40:49 +08:00
|
|
|
decayConstant = 1 // bigger for slower decay, exponential
|
2021-03-03 03:11:57 +08:00
|
|
|
defaultChunkSize = 48 * fs.Mebi
|
2022-03-22 16:40:49 +08:00
|
|
|
defaultRateLimitSleep = 60 * time.Second
|
2019-08-06 20:47:52 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
// Description of how to auth for this app
|
2022-07-26 14:28:37 +08:00
|
|
|
putioConfig = &oauthutil.Config{
|
|
|
|
Scopes: []string{},
|
|
|
|
AuthURL: "https://api.put.io/v2/oauth2/authenticate",
|
|
|
|
TokenURL: "https://api.put.io/v2/oauth2/access_token",
|
2019-08-06 20:47:52 +08:00
|
|
|
ClientID: rcloneClientID,
|
|
|
|
ClientSecret: obscure.MustReveal(rcloneObscuredClientSecret),
|
|
|
|
RedirectURL: oauthutil.RedirectLocalhostURL,
|
|
|
|
}
|
|
|
|
// A regexp matching path names for ignoring unnecessary files
|
|
|
|
ignoredFiles = regexp.MustCompile(`(?i)(^|/)(desktop\.ini|thumbs\.db|\.ds_store|icon\r)$`)
|
|
|
|
)
|
|
|
|
|
|
|
|
// Register with Fs
|
|
|
|
func init() {
|
|
|
|
fs.Register(&fs.RegInfo{
|
|
|
|
Name: "putio",
|
|
|
|
Description: "Put.io",
|
|
|
|
NewFs: NewFs,
|
2021-04-29 16:28:18 +08:00
|
|
|
Config: func(ctx context.Context, name string, m configmap.Mapper, config fs.ConfigIn) (*fs.ConfigOut, error) {
|
|
|
|
return oauthutil.ConfigOut("", &oauthutil.Options{
|
|
|
|
OAuth2Config: putioConfig,
|
|
|
|
NoOffline: true,
|
|
|
|
})
|
2019-08-06 20:47:52 +08:00
|
|
|
},
|
2023-07-07 00:55:53 +08:00
|
|
|
Options: append(oauthutil.SharedOptions, []fs.Option{{
|
2020-01-15 01:33:35 +08:00
|
|
|
Name: config.ConfigEncoding,
|
|
|
|
Help: config.ConfigEncodingHelp,
|
|
|
|
Advanced: true,
|
2020-01-15 05:51:49 +08:00
|
|
|
// Note that \ is renamed to -
|
|
|
|
//
|
|
|
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
|
|
|
Default: (encoder.Display |
|
|
|
|
encoder.EncodeBackSlash |
|
|
|
|
encoder.EncodeInvalidUtf8),
|
2023-07-07 00:55:53 +08:00
|
|
|
}}...),
|
2019-08-06 20:47:52 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-01-15 01:33:35 +08:00
|
|
|
// Options defines the configuration for this backend
|
|
|
|
type Options struct {
|
|
|
|
Enc encoder.MultiEncoder `config:"encoding"`
|
|
|
|
}
|
|
|
|
|
2019-08-06 20:47:52 +08:00
|
|
|
// Check the interfaces are satisfied
|
|
|
|
var (
|
|
|
|
_ fs.Fs = (*Fs)(nil)
|
|
|
|
_ fs.Purger = (*Fs)(nil)
|
|
|
|
_ fs.PutUncheckeder = (*Fs)(nil)
|
|
|
|
_ fs.Abouter = (*Fs)(nil)
|
|
|
|
_ fs.Mover = (*Fs)(nil)
|
|
|
|
_ fs.DirMover = (*Fs)(nil)
|
|
|
|
_ dircache.DirCacher = (*Fs)(nil)
|
|
|
|
_ fs.DirCacheFlusher = (*Fs)(nil)
|
|
|
|
_ fs.CleanUpper = (*Fs)(nil)
|
|
|
|
_ fs.Copier = (*Fs)(nil)
|
|
|
|
_ fs.Object = (*Object)(nil)
|
|
|
|
_ fs.MimeTyper = (*Object)(nil)
|
|
|
|
_ fs.IDer = (*Object)(nil)
|
|
|
|
)
|