github.com/artpar/rclone@v1.67.3/backend/putio/putio.go (about)

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