github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/backend/quatrix/api/types.go (about) 1 // Package api provides types used by the Quatrix API. 2 package api 3 4 import ( 5 "strconv" 6 "time" 7 ) 8 9 // OverwriteMode is a conflict resolve mode during copy or move. Files with conflicting names will be overwritten 10 const OverwriteMode = "overwrite" 11 12 // ProfileInfo is a profile info about quota 13 type ProfileInfo struct { 14 UserUsed int64 `json:"user_used"` 15 UserLimit int64 `json:"user_limit"` 16 AccUsed int64 `json:"acc_used"` 17 AccLimit int64 `json:"acc_limit"` 18 } 19 20 // IDList is a general object that contains list of ids 21 type IDList struct { 22 IDs []string `json:"ids"` 23 } 24 25 // DeleteParams is the request to delete object 26 type DeleteParams struct { 27 IDs []string `json:"ids"` 28 DeletePermanently bool `json:"delete_permanently"` 29 } 30 31 // FileInfoParams is the request to get object's (file or directory) info 32 type FileInfoParams struct { 33 ParentID string `json:"parent_id,omitempty"` 34 Path string `json:"path"` 35 } 36 37 // FileInfo is the response to get object's (file or directory) info 38 type FileInfo struct { 39 FileID string `json:"file_id"` 40 ParentID string `json:"parent_id"` 41 Src string `json:"src"` 42 Type string `json:"type"` 43 } 44 45 // IsFile returns true if object is a file 46 // false otherwise 47 func (fi *FileInfo) IsFile() bool { 48 if fi == nil { 49 return false 50 } 51 52 return fi.Type == "F" 53 } 54 55 // IsDir returns true if object is a directory 56 // false otherwise 57 func (fi *FileInfo) IsDir() bool { 58 if fi == nil { 59 return false 60 } 61 62 return fi.Type == "D" || fi.Type == "S" || fi.Type == "T" 63 } 64 65 // CreateDirParams is the request to create a directory 66 type CreateDirParams struct { 67 Target string `json:"target,omitempty"` 68 Name string `json:"name"` 69 Resolve bool `json:"resolve"` 70 } 71 72 // File represent metadata about object in Quatrix (file or directory) 73 type File struct { 74 ID string `json:"id"` 75 Created JSONTime `json:"created"` 76 Modified JSONTime `json:"modified"` 77 Name string `json:"name"` 78 ParentID string `json:"parent_id"` 79 Size int64 `json:"size"` 80 ModifiedMS JSONTime `json:"modified_ms"` 81 Type string `json:"type"` 82 Operations int `json:"operations"` 83 SubType string `json:"sub_type"` 84 Content []File `json:"content"` 85 } 86 87 // IsFile returns true if object is a file 88 // false otherwise 89 func (f *File) IsFile() bool { 90 if f == nil { 91 return false 92 } 93 94 return f.Type == "F" 95 } 96 97 // IsDir returns true if object is a directory 98 // false otherwise 99 func (f *File) IsDir() bool { 100 if f == nil { 101 return false 102 } 103 104 return f.Type == "D" || f.Type == "S" || f.Type == "T" 105 } 106 107 // IsProjectFolder returns true if object is a project folder 108 // false otherwise 109 func (f *File) IsProjectFolder() bool { 110 if f == nil { 111 return false 112 } 113 114 return f.Type == "S" 115 } 116 117 // SetMTimeParams is the request to set modification time for object 118 type SetMTimeParams struct { 119 ID string `json:"id,omitempty"` 120 MTime JSONTime `json:"mtime"` 121 } 122 123 // JSONTime provides methods to marshal/unmarshal time.Time as Unix time 124 type JSONTime time.Time 125 126 // MarshalJSON returns time representation in Unix time 127 func (u JSONTime) MarshalJSON() ([]byte, error) { 128 return []byte(strconv.FormatFloat(float64(time.Time(u).UTC().UnixNano())/1e9, 'f', 6, 64)), nil 129 } 130 131 // UnmarshalJSON sets time from Unix time representation 132 func (u *JSONTime) UnmarshalJSON(data []byte) error { 133 f, err := strconv.ParseFloat(string(data), 64) 134 if err != nil { 135 return err 136 } 137 138 t := JSONTime(time.Unix(0, int64(f*1e9))) 139 *u = t 140 141 return nil 142 } 143 144 // String returns Unix time representation of time as string 145 func (u JSONTime) String() string { 146 return strconv.FormatInt(time.Time(u).UTC().Unix(), 10) 147 } 148 149 // DownloadLinkResponse is the response to download-link request 150 type DownloadLinkResponse struct { 151 ID string `json:"id"` 152 } 153 154 // UploadLinkParams is the request to get upload-link 155 type UploadLinkParams struct { 156 Name string `json:"name"` 157 ParentID string `json:"parent_id"` 158 Resolve bool `json:"resolve"` 159 } 160 161 // UploadLinkResponse is the response to upload-link request 162 type UploadLinkResponse struct { 163 Name string `json:"name"` 164 FileID string `json:"file_id"` 165 ParentID string `json:"parent_id"` 166 UploadKey string `json:"upload_key"` 167 } 168 169 // UploadFinalizeResponse is the response to finalize file method 170 type UploadFinalizeResponse struct { 171 FileID string `json:"id"` 172 ParentID string `json:"parent_id"` 173 Modified int64 `json:"modified"` 174 FileSize int64 `json:"size"` 175 } 176 177 // FileModifyParams is the request to get modify file link 178 type FileModifyParams struct { 179 ID string `json:"id"` 180 Truncate int64 `json:"truncate"` 181 } 182 183 // FileCopyMoveOneParams is the request to do server-side copy and move 184 // can be used for file or directory 185 type FileCopyMoveOneParams struct { 186 ID string `json:"file_id"` 187 Target string `json:"target_id"` 188 Name string `json:"name"` 189 MTime JSONTime `json:"mtime"` 190 Resolve bool `json:"resolve"` 191 ResolveMode string `json:"resolve_mode"` 192 }