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