mirror of
https://github.com/rclone/rclone.git
synced 2025-12-11 22:14:05 +01:00
Move all backends into backend directory
This commit is contained in:
153
backend/pcloud/api/types.go
Normal file
153
backend/pcloud/api/types.go
Normal file
@@ -0,0 +1,153 @@
|
||||
// Package api has type definitions for pcloud
|
||||
//
|
||||
// Converted from the API docs with help from https://mholt.github.io/json-to-go/
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// Sun, 16 Mar 2014 17:26:04 +0000
|
||||
timeFormat = `"` + time.RFC1123Z + `"`
|
||||
)
|
||||
|
||||
// Time represents represents date and time information for the
|
||||
// pcloud API, by using RFC1123Z
|
||||
type Time time.Time
|
||||
|
||||
// MarshalJSON turns a Time into JSON (in UTC)
|
||||
func (t *Time) MarshalJSON() (out []byte, err error) {
|
||||
timeString := (*time.Time)(t).Format(timeFormat)
|
||||
return []byte(timeString), nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON turns JSON into a Time
|
||||
func (t *Time) UnmarshalJSON(data []byte) error {
|
||||
newT, err := time.Parse(timeFormat, string(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = Time(newT)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Error is returned from pcloud when things go wrong
|
||||
//
|
||||
// If result is 0 then everything is OK
|
||||
type Error struct {
|
||||
Result int `json:"result"`
|
||||
ErrorString string `json:"error"`
|
||||
}
|
||||
|
||||
// Error returns a string for the error and statistifes the error interface
|
||||
func (e *Error) Error() string {
|
||||
return fmt.Sprintf("pcloud error: %s (%d)", e.ErrorString, e.Result)
|
||||
}
|
||||
|
||||
// Update returns err directly if it was != nil, otherwise it returns
|
||||
// an Error or nil if no error was detected
|
||||
func (e *Error) Update(err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if e.Result == 0 {
|
||||
return nil
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
// Check Error statisfies the error interface
|
||||
var _ error = (*Error)(nil)
|
||||
|
||||
// Item describes a folder or a file as returned by Get Folder Items and others
|
||||
type Item struct {
|
||||
Path string `json:"path"`
|
||||
Name string `json:"name"`
|
||||
Created Time `json:"created"`
|
||||
IsMine bool `json:"ismine"`
|
||||
Thumb bool `json:"thumb"`
|
||||
Modified Time `json:"modified"`
|
||||
Comments int `json:"comments"`
|
||||
ID string `json:"id"`
|
||||
IsShared bool `json:"isshared"`
|
||||
IsDeleted bool `json:"isdeleted"`
|
||||
Icon string `json:"icon"`
|
||||
IsFolder bool `json:"isfolder"`
|
||||
ParentFolderID int64 `json:"parentfolderid"`
|
||||
FolderID int64 `json:"folderid,omitempty"`
|
||||
Height int `json:"height,omitempty"`
|
||||
FileID int64 `json:"fileid,omitempty"`
|
||||
Width int `json:"width,omitempty"`
|
||||
Hash uint64 `json:"hash,omitempty"`
|
||||
Category int `json:"category,omitempty"`
|
||||
Size int64 `json:"size,omitempty"`
|
||||
ContentType string `json:"contenttype,omitempty"`
|
||||
Contents []Item `json:"contents"`
|
||||
}
|
||||
|
||||
// ModTime returns the modification time of the item
|
||||
func (i *Item) ModTime() (t time.Time) {
|
||||
t = time.Time(i.Modified)
|
||||
if t.IsZero() {
|
||||
t = time.Time(i.Created)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// ItemResult is returned from the /listfolder, /createfolder, /deletefolder, /deletefile etc methods
|
||||
type ItemResult struct {
|
||||
Error
|
||||
Metadata Item `json:"metadata"`
|
||||
}
|
||||
|
||||
// Hashes contains the supported hashes
|
||||
type Hashes struct {
|
||||
SHA1 string `json:"sha1"`
|
||||
MD5 string `json:"md5"`
|
||||
}
|
||||
|
||||
// UploadFileResponse is the response from /uploadfile
|
||||
type UploadFileResponse struct {
|
||||
Error
|
||||
Items []Item `json:"metadata"`
|
||||
Checksums []Hashes `json:"checksums"`
|
||||
Fileids []int64 `json:"fileids"`
|
||||
}
|
||||
|
||||
// GetFileLinkResult is returned from /getfilelink
|
||||
type GetFileLinkResult struct {
|
||||
Error
|
||||
Dwltag string `json:"dwltag"`
|
||||
Hash uint64 `json:"hash"`
|
||||
Size int64 `json:"size"`
|
||||
Expires Time `json:"expires"`
|
||||
Path string `json:"path"`
|
||||
Hosts []string `json:"hosts"`
|
||||
}
|
||||
|
||||
// IsValid returns whether the link is valid and has not expired
|
||||
func (g *GetFileLinkResult) IsValid() bool {
|
||||
if g == nil {
|
||||
return false
|
||||
}
|
||||
if len(g.Hosts) == 0 {
|
||||
return false
|
||||
}
|
||||
return time.Time(g.Expires).Sub(time.Now()) > 30*time.Second
|
||||
}
|
||||
|
||||
// URL returns a URL from the Path and Hosts. Check with IsValid
|
||||
// before calling.
|
||||
func (g *GetFileLinkResult) URL() string {
|
||||
// FIXME rotate the hosts?
|
||||
return "https://" + g.Hosts[0] + g.Path
|
||||
}
|
||||
|
||||
// ChecksumFileResult is returned from /checksumfile
|
||||
type ChecksumFileResult struct {
|
||||
Error
|
||||
Hashes
|
||||
Metadata Item `json:"metadata"`
|
||||
}
|
||||
1111
backend/pcloud/pcloud.go
Normal file
1111
backend/pcloud/pcloud.go
Normal file
File diff suppressed because it is too large
Load Diff
73
backend/pcloud/pcloud_test.go
Normal file
73
backend/pcloud/pcloud_test.go
Normal file
@@ -0,0 +1,73 @@
|
||||
// Test Pcloud filesystem interface
|
||||
//
|
||||
// Automatically generated - DO NOT EDIT
|
||||
// Regenerate with: make gen_tests
|
||||
package pcloud_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/ncw/rclone/backend/pcloud"
|
||||
"github.com/ncw/rclone/fs"
|
||||
"github.com/ncw/rclone/fstest/fstests"
|
||||
)
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
fstests.NilObject = fs.Object((*pcloud.Object)(nil))
|
||||
fstests.RemoteName = "TestPcloud:"
|
||||
}
|
||||
|
||||
// Generic tests for the Fs
|
||||
func TestInit(t *testing.T) { fstests.TestInit(t) }
|
||||
func TestFsString(t *testing.T) { fstests.TestFsString(t) }
|
||||
func TestFsName(t *testing.T) { fstests.TestFsName(t) }
|
||||
func TestFsRoot(t *testing.T) { fstests.TestFsRoot(t) }
|
||||
func TestFsRmdirEmpty(t *testing.T) { fstests.TestFsRmdirEmpty(t) }
|
||||
func TestFsRmdirNotFound(t *testing.T) { fstests.TestFsRmdirNotFound(t) }
|
||||
func TestFsMkdir(t *testing.T) { fstests.TestFsMkdir(t) }
|
||||
func TestFsMkdirRmdirSubdir(t *testing.T) { fstests.TestFsMkdirRmdirSubdir(t) }
|
||||
func TestFsListEmpty(t *testing.T) { fstests.TestFsListEmpty(t) }
|
||||
func TestFsListDirEmpty(t *testing.T) { fstests.TestFsListDirEmpty(t) }
|
||||
func TestFsListRDirEmpty(t *testing.T) { fstests.TestFsListRDirEmpty(t) }
|
||||
func TestFsNewObjectNotFound(t *testing.T) { fstests.TestFsNewObjectNotFound(t) }
|
||||
func TestFsPutFile1(t *testing.T) { fstests.TestFsPutFile1(t) }
|
||||
func TestFsPutError(t *testing.T) { fstests.TestFsPutError(t) }
|
||||
func TestFsPutFile2(t *testing.T) { fstests.TestFsPutFile2(t) }
|
||||
func TestFsUpdateFile1(t *testing.T) { fstests.TestFsUpdateFile1(t) }
|
||||
func TestFsListDirFile2(t *testing.T) { fstests.TestFsListDirFile2(t) }
|
||||
func TestFsListRDirFile2(t *testing.T) { fstests.TestFsListRDirFile2(t) }
|
||||
func TestFsListDirRoot(t *testing.T) { fstests.TestFsListDirRoot(t) }
|
||||
func TestFsListRDirRoot(t *testing.T) { fstests.TestFsListRDirRoot(t) }
|
||||
func TestFsListSubdir(t *testing.T) { fstests.TestFsListSubdir(t) }
|
||||
func TestFsListRSubdir(t *testing.T) { fstests.TestFsListRSubdir(t) }
|
||||
func TestFsListLevel2(t *testing.T) { fstests.TestFsListLevel2(t) }
|
||||
func TestFsListRLevel2(t *testing.T) { fstests.TestFsListRLevel2(t) }
|
||||
func TestFsListFile1(t *testing.T) { fstests.TestFsListFile1(t) }
|
||||
func TestFsNewObject(t *testing.T) { fstests.TestFsNewObject(t) }
|
||||
func TestFsListFile1and2(t *testing.T) { fstests.TestFsListFile1and2(t) }
|
||||
func TestFsNewObjectDir(t *testing.T) { fstests.TestFsNewObjectDir(t) }
|
||||
func TestFsCopy(t *testing.T) { fstests.TestFsCopy(t) }
|
||||
func TestFsMove(t *testing.T) { fstests.TestFsMove(t) }
|
||||
func TestFsDirMove(t *testing.T) { fstests.TestFsDirMove(t) }
|
||||
func TestFsRmdirFull(t *testing.T) { fstests.TestFsRmdirFull(t) }
|
||||
func TestFsPrecision(t *testing.T) { fstests.TestFsPrecision(t) }
|
||||
func TestFsDirChangeNotify(t *testing.T) { fstests.TestFsDirChangeNotify(t) }
|
||||
func TestObjectString(t *testing.T) { fstests.TestObjectString(t) }
|
||||
func TestObjectFs(t *testing.T) { fstests.TestObjectFs(t) }
|
||||
func TestObjectRemote(t *testing.T) { fstests.TestObjectRemote(t) }
|
||||
func TestObjectHashes(t *testing.T) { fstests.TestObjectHashes(t) }
|
||||
func TestObjectModTime(t *testing.T) { fstests.TestObjectModTime(t) }
|
||||
func TestObjectMimeType(t *testing.T) { fstests.TestObjectMimeType(t) }
|
||||
func TestObjectSetModTime(t *testing.T) { fstests.TestObjectSetModTime(t) }
|
||||
func TestObjectSize(t *testing.T) { fstests.TestObjectSize(t) }
|
||||
func TestObjectOpen(t *testing.T) { fstests.TestObjectOpen(t) }
|
||||
func TestObjectOpenSeek(t *testing.T) { fstests.TestObjectOpenSeek(t) }
|
||||
func TestObjectPartialRead(t *testing.T) { fstests.TestObjectPartialRead(t) }
|
||||
func TestObjectUpdate(t *testing.T) { fstests.TestObjectUpdate(t) }
|
||||
func TestObjectStorable(t *testing.T) { fstests.TestObjectStorable(t) }
|
||||
func TestFsIsFile(t *testing.T) { fstests.TestFsIsFile(t) }
|
||||
func TestFsIsFileNotFound(t *testing.T) { fstests.TestFsIsFileNotFound(t) }
|
||||
func TestObjectRemove(t *testing.T) { fstests.TestObjectRemove(t) }
|
||||
func TestFsPutStream(t *testing.T) { fstests.TestFsPutStream(t) }
|
||||
func TestObjectPurge(t *testing.T) { fstests.TestObjectPurge(t) }
|
||||
func TestFinalise(t *testing.T) { fstests.TestFinalise(t) }
|
||||
Reference in New Issue
Block a user