mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 00:43:49 +01:00
premiumizeme: use lib/encoder
This commit is contained in:
parent
1dc8bcd48c
commit
4615343b73
@ -2,9 +2,7 @@
|
|||||||
// object storage system.
|
// object storage system.
|
||||||
package premiumizeme
|
package premiumizeme
|
||||||
|
|
||||||
/* FIXME
|
/*
|
||||||
escaping needs fixing
|
|
||||||
|
|
||||||
Run of rclone info
|
Run of rclone info
|
||||||
stringNeedsEscaping = []rune{
|
stringNeedsEscaping = []rune{
|
||||||
0x00, 0x0A, 0x0D, 0x22, 0x2F, 0x5C, 0xBF, 0xFE
|
0x00, 0x0A, 0x0D, 0x22, 0x2F, 0x5C, 0xBF, 0xFE
|
||||||
@ -36,6 +34,7 @@ import (
|
|||||||
"github.com/rclone/rclone/fs/config/configmap"
|
"github.com/rclone/rclone/fs/config/configmap"
|
||||||
"github.com/rclone/rclone/fs/config/configstruct"
|
"github.com/rclone/rclone/fs/config/configstruct"
|
||||||
"github.com/rclone/rclone/fs/config/obscure"
|
"github.com/rclone/rclone/fs/config/obscure"
|
||||||
|
"github.com/rclone/rclone/fs/encodings"
|
||||||
"github.com/rclone/rclone/fs/fserrors"
|
"github.com/rclone/rclone/fs/fserrors"
|
||||||
"github.com/rclone/rclone/fs/fshttp"
|
"github.com/rclone/rclone/fs/fshttp"
|
||||||
"github.com/rclone/rclone/fs/hash"
|
"github.com/rclone/rclone/fs/hash"
|
||||||
@ -47,6 +46,8 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const enc = encodings.PremiumizeMe
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rcloneClientID = "658922194"
|
rcloneClientID = "658922194"
|
||||||
rcloneEncryptedClientSecret = "B5YIvQoRIhcpAYs8HYeyjb9gK-ftmZEbqdh_gNfc4RgO9Q"
|
rcloneEncryptedClientSecret = "B5YIvQoRIhcpAYs8HYeyjb9gK-ftmZEbqdh_gNfc4RgO9Q"
|
||||||
@ -170,24 +171,6 @@ func shouldRetry(resp *http.Response, err error) (bool, error) {
|
|||||||
return fserrors.ShouldRetry(err) || fserrors.ShouldRetryHTTP(resp, retryErrorCodes), err
|
return fserrors.ShouldRetry(err) || fserrors.ShouldRetryHTTP(resp, retryErrorCodes), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// substitute reserved characters
|
|
||||||
func replaceReservedChars(x string) string {
|
|
||||||
// Backslash for FULLWIDTH REVERSE SOLIDUS
|
|
||||||
x = strings.Replace(x, "\\", "\", -1)
|
|
||||||
// Double quote for FULLWIDTH QUOTATION MARK
|
|
||||||
x = strings.Replace(x, `"`, """, -1)
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
|
||||||
// restore reserved characters
|
|
||||||
func restoreReservedChars(x string) string {
|
|
||||||
// FULLWIDTH QUOTATION MARK for Double quote
|
|
||||||
x = strings.Replace(x, """, `"`, -1)
|
|
||||||
// FULLWIDTH REVERSE SOLIDUS for Backslash
|
|
||||||
x = strings.Replace(x, "\", "\\", -1)
|
|
||||||
return x
|
|
||||||
}
|
|
||||||
|
|
||||||
// readMetaDataForPath reads the metadata from the path
|
// readMetaDataForPath reads the metadata from the path
|
||||||
func (f *Fs) readMetaDataForPath(ctx context.Context, path string, directoriesOnly bool, filesOnly bool) (info *api.Item, err error) {
|
func (f *Fs) readMetaDataForPath(ctx context.Context, path string, directoriesOnly bool, filesOnly bool) (info *api.Item, err error) {
|
||||||
// defer fs.Trace(f, "path=%q", path)("info=%+v, err=%v", &info, &err)
|
// defer fs.Trace(f, "path=%q", path)("info=%+v, err=%v", &info, &err)
|
||||||
@ -381,7 +364,7 @@ func (f *Fs) CreateDir(ctx context.Context, pathID, leaf string) (newID string,
|
|||||||
Path: "/folder/create",
|
Path: "/folder/create",
|
||||||
Parameters: f.baseParams(),
|
Parameters: f.baseParams(),
|
||||||
MultipartParams: url.Values{
|
MultipartParams: url.Values{
|
||||||
"name": {replaceReservedChars(leaf)},
|
"name": {enc.FromStandardName(leaf)},
|
||||||
"parent_id": {pathID},
|
"parent_id": {pathID},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -446,7 +429,7 @@ func (f *Fs) listAll(ctx context.Context, dirID string, directoriesOnly bool, fi
|
|||||||
fs.Debugf(f, "Ignoring %q - unknown type %q", item.Name, item.Type)
|
fs.Debugf(f, "Ignoring %q - unknown type %q", item.Name, item.Type)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
item.Name = restoreReservedChars(item.Name)
|
item.Name = enc.ToStandardName(item.Name)
|
||||||
if fn(item) {
|
if fn(item) {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
@ -654,8 +637,8 @@ func (f *Fs) Purge(ctx context.Context) error {
|
|||||||
// between directories and a separate one to rename them. We try to
|
// between directories and a separate one to rename them. We try to
|
||||||
// call the minimum number of API calls.
|
// call the minimum number of API calls.
|
||||||
func (f *Fs) move(ctx context.Context, isFile bool, id, oldLeaf, newLeaf, oldDirectoryID, newDirectoryID string) (err error) {
|
func (f *Fs) move(ctx context.Context, isFile bool, id, oldLeaf, newLeaf, oldDirectoryID, newDirectoryID string) (err error) {
|
||||||
newLeaf = replaceReservedChars(newLeaf)
|
newLeaf = enc.FromStandardName(newLeaf)
|
||||||
oldLeaf = replaceReservedChars(oldLeaf)
|
oldLeaf = enc.FromStandardName(oldLeaf)
|
||||||
doRenameLeaf := oldLeaf != newLeaf
|
doRenameLeaf := oldLeaf != newLeaf
|
||||||
doMove := oldDirectoryID != newDirectoryID
|
doMove := oldDirectoryID != newDirectoryID
|
||||||
|
|
||||||
@ -686,7 +669,7 @@ func (f *Fs) move(ctx context.Context, isFile bool, id, oldLeaf, newLeaf, oldDir
|
|||||||
} else {
|
} else {
|
||||||
opts.MultipartParams.Set("folders[]", id)
|
opts.MultipartParams.Set("folders[]", id)
|
||||||
}
|
}
|
||||||
//replacedLeaf := replaceReservedChars(leaf)
|
//replacedLeaf := enc.FromStandardName(leaf)
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var result api.Response
|
var result api.Response
|
||||||
err = f.pacer.Call(func() (bool, error) {
|
err = f.pacer.Call(func() (bool, error) {
|
||||||
@ -908,7 +891,7 @@ func (o *Object) Remote() string {
|
|||||||
|
|
||||||
// srvPath returns a path for use in server
|
// srvPath returns a path for use in server
|
||||||
func (o *Object) srvPath() string {
|
func (o *Object) srvPath() string {
|
||||||
return replaceReservedChars(o.fs.rootSlash() + o.remote)
|
return enc.FromStandardPath(o.fs.rootSlash() + o.remote)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hash returns the SHA-1 of an object returning a lowercase hex string
|
// Hash returns the SHA-1 of an object returning a lowercase hex string
|
||||||
@ -1023,7 +1006,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
leaf = replaceReservedChars(leaf)
|
leaf = enc.FromStandardName(leaf)
|
||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
var info api.FolderUploadinfoResponse
|
var info api.FolderUploadinfoResponse
|
||||||
|
@ -88,6 +88,19 @@ premiumize.me does not support modification times or hashes, therefore
|
|||||||
syncing will default to `--size-only` checking. Note that using
|
syncing will default to `--size-only` checking. Note that using
|
||||||
`--update` will work.
|
`--update` will work.
|
||||||
|
|
||||||
|
#### Restricted filename characters
|
||||||
|
|
||||||
|
In addition to the [default restricted characters set](/overview/#restricted-characters)
|
||||||
|
the following characters are also replaced:
|
||||||
|
|
||||||
|
| Character | Value | Replacement |
|
||||||
|
| --------- |:-----:|:-----------:|
|
||||||
|
| \ | 0x5C | \ |
|
||||||
|
| " | 0x22 | " |
|
||||||
|
|
||||||
|
Invalid UTF-8 bytes will also be [replaced](/overview/#invalid-utf8),
|
||||||
|
as they can't be used in JSON strings.
|
||||||
|
|
||||||
<!--- autogenerated options start - DO NOT EDIT, instead edit fs.RegInfo in backend/premiumizeme/premiumizeme.go then run make backenddocs -->
|
<!--- autogenerated options start - DO NOT EDIT, instead edit fs.RegInfo in backend/premiumizeme/premiumizeme.go then run make backenddocs -->
|
||||||
### Standard Options
|
### Standard Options
|
||||||
|
|
||||||
|
@ -219,6 +219,15 @@ const OpenDrive = encoder.MultiEncoder(
|
|||||||
encoder.EncodeRightSpace |
|
encoder.EncodeRightSpace |
|
||||||
encoder.EncodeInvalidUtf8)
|
encoder.EncodeInvalidUtf8)
|
||||||
|
|
||||||
|
// PremiumizeMe is the encoding used by the premiumizeme backend
|
||||||
|
//
|
||||||
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
|
const PremiumizeMe = encoder.MultiEncoder(
|
||||||
|
uint(Display) |
|
||||||
|
encoder.EncodeBackSlash |
|
||||||
|
encoder.EncodeDoubleQuote |
|
||||||
|
encoder.EncodeInvalidUtf8)
|
||||||
|
|
||||||
// Pcloud is the encoding used by the pcloud backend
|
// Pcloud is the encoding used by the pcloud backend
|
||||||
//
|
//
|
||||||
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
// Encode invalid UTF-8 bytes as json doesn't handle them properly.
|
||||||
@ -359,6 +368,8 @@ func ByName(name string) encoder.Encoder {
|
|||||||
return OneDrive
|
return OneDrive
|
||||||
case "opendrive":
|
case "opendrive":
|
||||||
return OpenDrive
|
return OpenDrive
|
||||||
|
case "premiumizeme":
|
||||||
|
return PremiumizeMe
|
||||||
case "pcloud":
|
case "pcloud":
|
||||||
return Pcloud
|
return Pcloud
|
||||||
case "qingstor":
|
case "qingstor":
|
||||||
@ -405,6 +416,7 @@ func Names() []string {
|
|||||||
"mega",
|
"mega",
|
||||||
"onedrive",
|
"onedrive",
|
||||||
"opendrive",
|
"opendrive",
|
||||||
|
"premiumizeme",
|
||||||
"pcloud",
|
"pcloud",
|
||||||
"sharefile",
|
"sharefile",
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user