github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/backend/putio/putio.go (about) 1 package putio 2 3 import ( 4 "log" 5 "regexp" 6 "time" 7 8 "github.com/rclone/rclone/fs" 9 "github.com/rclone/rclone/fs/config" 10 "github.com/rclone/rclone/fs/config/configmap" 11 "github.com/rclone/rclone/fs/config/obscure" 12 "github.com/rclone/rclone/lib/dircache" 13 "github.com/rclone/rclone/lib/encoder" 14 "github.com/rclone/rclone/lib/oauthutil" 15 "golang.org/x/oauth2" 16 ) 17 18 /* 19 // TestPutio 20 stringNeedsEscaping = []rune{ 21 '/', '\x00' 22 } 23 maxFileLength = 255 24 canWriteUnnormalized = true 25 canReadUnnormalized = true 26 canReadRenormalized = true 27 canStream = false 28 */ 29 30 // Constants 31 const ( 32 rcloneClientID = "4131" 33 rcloneObscuredClientSecret = "cMwrjWVmrHZp3gf1ZpCrlyGAmPpB-YY5BbVnO1fj-G9evcd8" 34 minSleep = 10 * time.Millisecond 35 maxSleep = 2 * time.Second 36 decayConstant = 2 // bigger for slower decay, exponential 37 defaultChunkSize = 48 * fs.MebiByte 38 ) 39 40 var ( 41 // Description of how to auth for this app 42 putioConfig = &oauth2.Config{ 43 Scopes: []string{}, 44 Endpoint: oauth2.Endpoint{ 45 AuthURL: "https://api.put.io/v2/oauth2/authenticate", 46 TokenURL: "https://api.put.io/v2/oauth2/access_token", 47 }, 48 ClientID: rcloneClientID, 49 ClientSecret: obscure.MustReveal(rcloneObscuredClientSecret), 50 RedirectURL: oauthutil.RedirectLocalhostURL, 51 } 52 // A regexp matching path names for ignoring unnecessary files 53 ignoredFiles = regexp.MustCompile(`(?i)(^|/)(desktop\.ini|thumbs\.db|\.ds_store|icon\r)$`) 54 ) 55 56 // Register with Fs 57 func init() { 58 fs.Register(&fs.RegInfo{ 59 Name: "putio", 60 Description: "Put.io", 61 NewFs: NewFs, 62 Config: func(name string, m configmap.Mapper) { 63 opt := oauthutil.Options{ 64 NoOffline: true, 65 } 66 err := oauthutil.Config("putio", name, m, putioConfig, &opt) 67 if err != nil { 68 log.Fatalf("Failed to configure token: %v", err) 69 } 70 }, 71 Options: []fs.Option{{ 72 Name: config.ConfigEncoding, 73 Help: config.ConfigEncodingHelp, 74 Advanced: true, 75 // Note that \ is renamed to - 76 // 77 // Encode invalid UTF-8 bytes as json doesn't handle them properly. 78 Default: (encoder.Display | 79 encoder.EncodeBackSlash | 80 encoder.EncodeInvalidUtf8), 81 }}, 82 }) 83 } 84 85 // Options defines the configuration for this backend 86 type Options struct { 87 Enc encoder.MultiEncoder `config:"encoding"` 88 } 89 90 // Check the interfaces are satisfied 91 var ( 92 _ fs.Fs = (*Fs)(nil) 93 _ fs.Purger = (*Fs)(nil) 94 _ fs.PutUncheckeder = (*Fs)(nil) 95 _ fs.Abouter = (*Fs)(nil) 96 _ fs.Mover = (*Fs)(nil) 97 _ fs.DirMover = (*Fs)(nil) 98 _ dircache.DirCacher = (*Fs)(nil) 99 _ fs.DirCacheFlusher = (*Fs)(nil) 100 _ fs.CleanUpper = (*Fs)(nil) 101 _ fs.Copier = (*Fs)(nil) 102 _ fs.Object = (*Object)(nil) 103 _ fs.MimeTyper = (*Object)(nil) 104 _ fs.IDer = (*Object)(nil) 105 )