github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/backend/sharefile/api/types.go (about)

     1  // Package api contains definitions for using the premiumize.me API
     2  package api
     3  
     4  import (
     5  	"errors"
     6  	"fmt"
     7  	"time"
     8  )
     9  
    10  // ListRequestSelect should be used in $select for Items/Children
    11  const ListRequestSelect = "odata.count,FileCount,Name,FileName,CreationDate,IsHidden,FileSizeBytes,odata.type,Id,Hash,ClientModifiedDate"
    12  
    13  // ListResponse is returned from the Items/Children call
    14  type ListResponse struct {
    15  	OdataCount int    `json:"odata.count"`
    16  	Value      []Item `json:"value"`
    17  }
    18  
    19  // Item Types
    20  const (
    21  	ItemTypeFolder = "ShareFile.Api.Models.Folder"
    22  	ItemTypeFile   = "ShareFile.Api.Models.File"
    23  )
    24  
    25  // Item refers to a file or folder
    26  type Item struct {
    27  	FileCount  int32     `json:"FileCount,omitempty"`
    28  	Name       string    `json:"Name,omitempty"`
    29  	FileName   string    `json:"FileName,omitempty"`
    30  	CreatedAt  time.Time `json:"CreationDate,omitempty"`
    31  	ModifiedAt time.Time `json:"ClientModifiedDate,omitempty"`
    32  	IsHidden   bool      `json:"IsHidden,omitempty"`
    33  	Size       int64     `json:"FileSizeBytes,omitempty"`
    34  	Type       string    `json:"odata.type,omitempty"`
    35  	ID         string    `json:"Id,omitempty"`
    36  	Hash       string    `json:"Hash,omitempty"`
    37  }
    38  
    39  // Error is an odata error return
    40  type Error struct {
    41  	Code    string `json:"code"`
    42  	Message struct {
    43  		Lang  string `json:"lang"`
    44  		Value string `json:"value"`
    45  	} `json:"message"`
    46  	Reason string `json:"reason"`
    47  }
    48  
    49  // Satisfy error interface
    50  func (e *Error) Error() string {
    51  	return fmt.Sprintf("%s: %s: %s", e.Message.Value, e.Code, e.Reason)
    52  }
    53  
    54  // Check Error satisfies error interface
    55  var _ error = &Error{}
    56  
    57  // DownloadSpecification is the response to /Items/Download
    58  type DownloadSpecification struct {
    59  	Token    string `json:"DownloadToken"`
    60  	URL      string `json:"DownloadUrl"`
    61  	Metadata string `json:"odata.metadata"`
    62  	Type     string `json:"odata.type"`
    63  }
    64  
    65  // UploadRequest is set to /Items/Upload2 to receive an UploadSpecification
    66  type UploadRequest struct {
    67  	Method         string    `json:"method"`                   // Upload method: one of: standard, streamed or threaded
    68  	Raw            bool      `json:"raw"`                      // Raw post if true or MIME upload if false
    69  	Filename       string    `json:"fileName"`                 // Uploaded item file name.
    70  	Filesize       *int64    `json:"fileSize,omitempty"`       // Uploaded item file size.
    71  	Overwrite      bool      `json:"overwrite"`                // Indicates whether items with the same name will be overwritten or not.
    72  	CreatedDate    time.Time `json:"ClientCreatedDate"`        // Created Date of this Item.
    73  	ModifiedDate   time.Time `json:"ClientModifiedDate"`       // Modified Date of this Item.
    74  	BatchID        string    `json:"batchId,omitempty"`        // Indicates part of a batch. Batched uploads do not send notification until the whole batch is completed.
    75  	BatchLast      *bool     `json:"batchLast,omitempty"`      // Indicates is the last in a batch. Upload notifications for the whole batch are sent after this upload.
    76  	CanResume      *bool     `json:"canResume,omitempty"`      // Indicates uploader supports resume.
    77  	StartOver      *bool     `json:"startOver,omitempty"`      // Indicates uploader wants to restart the file - i.e., ignore previous failed upload attempts.
    78  	Tool           string    `json:"tool,omitempty"`           // Identifies the uploader tool.
    79  	Title          string    `json:"title,omitempty"`          // Item Title
    80  	Details        string    `json:"details,omitempty"`        // Item description
    81  	IsSend         *bool     `json:"isSend,omitempty"`         // Indicates that this upload is part of a Send operation
    82  	SendGUID       string    `json:"sendGuid,omitempty"`       // Used if IsSend is true. Specifies which Send operation this upload is part of.
    83  	OpID           string    `json:"opid,omitempty"`           // Used for Asynchronous copy/move operations - called by Zones to push files to other Zones
    84  	ThreadCount    *int      `json:"threadCount,omitempty"`    // Specifies the number of threads the threaded uploader will use. Only used is method is threaded, ignored otherwise
    85  	Notify         *bool     `json:"notify,omitempty"`         // Indicates whether users will be notified of this upload - based on folder preferences
    86  	ExpirationDays *int      `json:"expirationDays,omitempty"` // File expiration days
    87  	BaseFileID     string    `json:"baseFileId,omitempty"`     // Used to check conflict in file during File Upload.
    88  }
    89  
    90  // UploadSpecification is returned from /Items/Upload
    91  type UploadSpecification struct {
    92  	Method             string `json:"Method"`             // The Upload method that must be used for this upload
    93  	PrepareURI         string `json:"PrepareUri"`         // If provided, clients must issue a request to this Uri before uploading any data.
    94  	ChunkURI           string `json:"ChunkUri"`           // Specifies the URI the client must send the file data to
    95  	FinishURI          string `json:"FinishUri"`          // If provided, specifies the final call the client must perform to finish the upload process
    96  	ProgressData       string `json:"ProgressData"`       // Allows the client to check progress of standard uploads
    97  	IsResume           bool   `json:"IsResume"`           // Specifies a Resumable upload is supported.
    98  	ResumeIndex        int64  `json:"ResumeIndex"`        // Specifies the initial index for resuming, if IsResume is true.
    99  	ResumeOffset       int64  `json:"ResumeOffset"`       // Specifies the initial file offset by bytes, if IsResume is true
   100  	ResumeFileHash     string `json:"ResumeFileHash"`     // Specifies the MD5 hash of the first ResumeOffset bytes of the partial file found at the server
   101  	MaxNumberOfThreads int    `json:"MaxNumberOfThreads"` // Specifies the max number of chunks that can be sent simultaneously for threaded uploads
   102  }
   103  
   104  // UploadFinishResponse is returns from calling UploadSpecification.FinishURI
   105  type UploadFinishResponse struct {
   106  	Error        bool   `json:"error"`
   107  	ErrorMessage string `json:"errorMessage"`
   108  	ErrorCode    int    `json:"errorCode"`
   109  	Value        []struct {
   110  		UploadID    string `json:"uploadid"`
   111  		ParentID    string `json:"parentid"`
   112  		ID          string `json:"id"`
   113  		StreamID    string `json:"streamid"`
   114  		FileName    string `json:"filename"`
   115  		DisplayName string `json:"displayname"`
   116  		Size        int    `json:"size"`
   117  		Md5         string `json:"md5"`
   118  	} `json:"value"`
   119  }
   120  
   121  // ID returns the ID of the first response if available
   122  func (finish *UploadFinishResponse) ID() (string, error) {
   123  	if finish.Error {
   124  		return "", fmt.Errorf("upload failed: %s (%d)", finish.ErrorMessage, finish.ErrorCode)
   125  	}
   126  	if len(finish.Value) == 0 {
   127  		return "", errors.New("upload failed: no results returned")
   128  	}
   129  	return finish.Value[0].ID, nil
   130  }
   131  
   132  // Parent is the ID of the parent folder
   133  type Parent struct {
   134  	ID string `json:"Id,omitempty"`
   135  }
   136  
   137  // Zone is where the data is stored
   138  type Zone struct {
   139  	ID string `json:"Id,omitempty"`
   140  }
   141  
   142  // UpdateItemRequest is sent to PATCH /v3/Items(id)
   143  type UpdateItemRequest struct {
   144  	Name           string     `json:"Name,omitempty"`
   145  	FileName       string     `json:"FileName,omitempty"`
   146  	Description    string     `json:"Description,omitempty"`
   147  	ExpirationDate *time.Time `json:"ExpirationDate,omitempty"`
   148  	Parent         *Parent    `json:"Parent,omitempty"`
   149  	Zone           *Zone      `json:"Zone,omitempty"`
   150  	ModifiedAt     *time.Time `json:"ClientModifiedDate,omitempty"`
   151  }