github.com/artpar/rclone@v1.67.3/backend/ulozto/api/types.go (about)

     1  // Package api has type definitions for uloz.to
     2  package api
     3  
     4  import (
     5  	"errors"
     6  	"fmt"
     7  	"time"
     8  )
     9  
    10  // Error is a representation of the JSON structure returned by uloz.to for unsuccessful requests.
    11  type Error struct {
    12  	ErrorCode  int    `json:"error"`
    13  	StatusCode int    `json:"code"`
    14  	Message    string `json:"message"`
    15  }
    16  
    17  // Error implements error.Error() and returns a string representation of the error.
    18  func (e *Error) Error() string {
    19  	out := fmt.Sprintf("Error %d (%d)", e.ErrorCode, e.StatusCode)
    20  	if e.Message != "" {
    21  		out += ": " + e.Message
    22  	}
    23  	return out
    24  }
    25  
    26  // Is determines if the error is an instance of another error. It's required for the
    27  // errors package to search in causal chain.
    28  func (e *Error) Is(target error) bool {
    29  	var err *Error
    30  	ok := errors.As(target, &err)
    31  	return ok
    32  }
    33  
    34  // ListResponseMetadata groups fields common for all API List calls,
    35  // and maps to the Metadata API JSON object.
    36  type ListResponseMetadata struct {
    37  	Timestamp  time.Time `json:"RunAt"`
    38  	Offset     int32     `json:"offset"`
    39  	Limit      int32     `json:"limit"`
    40  	ItemsCount int32     `json:"items_count"`
    41  }
    42  
    43  // Folder represents a single folder, and maps to the AggregatePrivateViewFolder
    44  // JSON API object.
    45  type Folder struct {
    46  	Discriminator        string    `json:"discriminator"`
    47  	Name                 string    `json:"name"`
    48  	SanitizedName        string    `json:"name_sanitized"`
    49  	Slug                 string    `json:"slug"`
    50  	Status               string    `json:"status"`
    51  	PublicURL            string    `json:"public_url"`
    52  	IsPasswordProtected  bool      `json:"is_password_protected"`
    53  	Type                 string    `json:"type"`
    54  	FileManagerLink      string    `json:"file_manager_link"`
    55  	ParentFolderSlug     string    `json:"parent_folder_slug"`
    56  	Privacy              string    `json:"privacy"`
    57  	Created              time.Time `json:"created"`
    58  	LastUserModified     time.Time `json:"last_user_modified"`
    59  	HasSubfolder         bool      `json:"has_subfolder"`
    60  	HasTrashedSubfolders bool      `json:"has_trashed_subfolders"`
    61  }
    62  
    63  // File represents a single file, and maps to the AggregatePrivateViewFileV3
    64  // JSON API object.
    65  type File struct {
    66  	Discriminator            string `json:"discriminator"`
    67  	Slug                     string `json:"slug"`
    68  	URL                      string `json:"url"`
    69  	Realm                    string `json:"realm"`
    70  	Name                     string `json:"name"`
    71  	NameSanitized            string `json:"name_sanitized"`
    72  	Extension                string `json:"extension"`
    73  	Filesize                 int64  `json:"filesize"`
    74  	PasswordProtectedFile    bool   `json:"password_protected_file"`
    75  	Description              string `json:"description"`
    76  	DescriptionSanitized     string `json:"description_sanitized"`
    77  	IsPorn                   bool   `json:"is_porn"`
    78  	Rating                   int    `json:"rating"`
    79  	PasswordProtectedArchive bool   `json:"password_protected_archive"`
    80  	MalwareStatus            string `json:"malware_status"`
    81  	ContentStatus            string `json:"content_status"`
    82  	ContentType              string `json:"content_type"`
    83  	Format                   struct {
    84  	} `json:"format"`
    85  	DownloadTypes []interface{} `json:"download_types"`
    86  	ThumbnailInfo []interface{} `json:"thumbnail_info"`
    87  	PreviewInfo   struct {
    88  	} `json:"preview_info"`
    89  	Privacy          string    `json:"privacy"`
    90  	IsPornByUploader bool      `json:"is_porn_by_uploader"`
    91  	ExpireDownload   int       `json:"expire_download"`
    92  	ExpireTime       time.Time `json:"expire_time"`
    93  	UploadTime       time.Time `json:"upload_time"`
    94  	LastUserModified time.Time `json:"last_user_modified"`
    95  	FolderSlug       string    `json:"folder_slug"`
    96  	IsIncomplete     bool      `json:"is_incomplete"`
    97  	IsInTrash        bool      `json:"is_in_trash"`
    98  	Processing       struct {
    99  		Identify       bool `json:"identify"`
   100  		Thumbnails     bool `json:"thumbnails"`
   101  		LivePreview    bool `json:"live_preview"`
   102  		ArchiveContent bool `json:"archive_content"`
   103  		Preview        bool `json:"preview"`
   104  	} `json:"processing"`
   105  }
   106  
   107  // CreateFolderRequest represents the JSON API object
   108  // that's sent to the create folder API endpoint.
   109  type CreateFolderRequest struct {
   110  	Name             string `json:"name"`
   111  	ParentFolderSlug string `json:"parent_folder_slug"`
   112  }
   113  
   114  // ListFoldersResponse represents the JSON API object
   115  // that's received from the list folders API endpoint.
   116  type ListFoldersResponse struct {
   117  	Metadata   ListResponseMetadata `json:"metadata"`
   118  	Folder     Folder               `json:"folder"`
   119  	Subfolders []Folder             `json:"subfolders"`
   120  }
   121  
   122  // ListFilesResponse represents the JSON API object
   123  // that's received from the list files API endpoint.
   124  type ListFilesResponse struct {
   125  	Metadata ListResponseMetadata `json:"metadata"`
   126  	Items    []File               `json:"items"`
   127  }
   128  
   129  // DeleteFoldersRequest represents the JSON API object
   130  // that's sent to the delete folders API endpoint.
   131  type DeleteFoldersRequest struct {
   132  	Slugs []string `json:"slugs"`
   133  }
   134  
   135  // CreateUploadURLRequest represents the JSON API object that's
   136  // sent to the API endpoint generating URLs for new file uploads.
   137  type CreateUploadURLRequest struct {
   138  	UserLogin           string `json:"user_login"`
   139  	Realm               string `json:"realm"`
   140  	ExistingSessionSlug string `json:"private_slug"`
   141  }
   142  
   143  // CreateUploadURLResponse represents the JSON API object that's
   144  // received from the API endpoint generating URLs for new file uploads.
   145  type CreateUploadURLResponse struct {
   146  	UploadURL        string    `json:"upload_url"`
   147  	PrivateSlug      string    `json:"private_slug"`
   148  	ValidUntil       time.Time `json:"valid_until"`
   149  	ValidityInterval int64     `json:"validity_interval"`
   150  }
   151  
   152  // BatchUpdateFilePropertiesRequest represents the JSON API object that's
   153  // sent to the API endpoint moving the uploaded files from a scratch space
   154  // to their final destination.
   155  type BatchUpdateFilePropertiesRequest struct {
   156  	Name         string            `json:"name"`
   157  	FolderSlug   string            `json:"folder_slug"`
   158  	Description  string            `json:"description"`
   159  	Slugs        []string          `json:"slugs"`
   160  	UploadTokens map[string]string `json:"upload_tokens"`
   161  }
   162  
   163  // SendFilePayloadResponse represents the JSON API object that's received
   164  // in response to uploading a file's body to the CDN URL.
   165  type SendFilePayloadResponse struct {
   166  	Size        int    `json:"size"`
   167  	ContentType string `json:"contentType"`
   168  	Md5         string `json:"md5"`
   169  	Message     string `json:"message"`
   170  	ReturnCode  int    `json:"return_code"`
   171  	Slug        string `json:"slug"`
   172  }
   173  
   174  // CommitUploadBatchRequest represents the JSON API object that's
   175  // sent to the API endpoint marking the upload batch as final.
   176  type CommitUploadBatchRequest struct {
   177  	Status     string `json:"status"`
   178  	OwnerLogin string `json:"owner_login"`
   179  }
   180  
   181  // CommitUploadBatchResponse represents the JSON API object that's
   182  // received from the API endpoint marking the upload batch as final.
   183  type CommitUploadBatchResponse struct {
   184  	PrivateSlug          string    `json:"private_slug"`
   185  	PublicSlug           string    `json:"public_slug"`
   186  	Status               string    `json:"status"`
   187  	ConfirmedAt          time.Time `json:"confirmed_at"`
   188  	Discriminator        string    `json:"discriminator"`
   189  	Privacy              string    `json:"privacy"`
   190  	Name                 time.Time `json:"name"`
   191  	PublicURL            string    `json:"public_url"`
   192  	FilesCountOk         int       `json:"files_count_ok"`
   193  	FilesCountTrash      int       `json:"files_count_trash"`
   194  	FilesCountIncomplete int       `json:"files_count_incomplete"`
   195  }
   196  
   197  // UpdateDescriptionRequest represents the JSON API object that's
   198  // sent to the file modification API endpoint marking the upload batch as final.
   199  type UpdateDescriptionRequest struct {
   200  	Description string `json:"description"`
   201  }
   202  
   203  // MoveFolderRequest represents the JSON API object that's
   204  // sent to the folder moving API endpoint.
   205  type MoveFolderRequest struct {
   206  	FolderSlugs         []string `json:"slugs"`
   207  	NewParentFolderSlug string   `json:"parent_folder_slug"`
   208  }
   209  
   210  // RenameFolderRequest represents the JSON API object that's
   211  // sent to the folder moving API endpoint.
   212  type RenameFolderRequest struct {
   213  	NewName string `json:"name"`
   214  }
   215  
   216  // MoveFileRequest represents the JSON API object that's
   217  // sent to the file  moving API endpoint.
   218  type MoveFileRequest struct {
   219  	ParentFolderSlug string `json:"folder_slug,omitempty"`
   220  	NewFilename      string `json:"name,omitempty"`
   221  }
   222  
   223  // GetDownloadLinkRequest represents the JSON API object that's
   224  // sent to the API endpoint that generates CDN download links for file payloads.
   225  type GetDownloadLinkRequest struct {
   226  	Slug      string `json:"file_slug"`
   227  	UserLogin string `json:"user_login"`
   228  	DeviceID  string `json:"device_id"`
   229  }
   230  
   231  // GetDownloadLinkResponse represents the JSON API object that's
   232  // received from the API endpoint that generates CDN download links for file payloads.
   233  type GetDownloadLinkResponse struct {
   234  	Link                        string    `json:"link"`
   235  	DownloadURLValidUntil       time.Time `json:"download_url_valid_until"`
   236  	DownloadURLValidityInterval int       `json:"download_url_validity_interval"`
   237  	Hash                        string    `json:"hash"`
   238  }
   239  
   240  // AuthenticateRequest represents the JSON API object that's sent to the auth API endpoint.
   241  type AuthenticateRequest struct {
   242  	Login    string `json:"login"`
   243  	Password string `json:"password"`
   244  }
   245  
   246  // AuthenticateResponse represents the JSON API object that's received from the auth API endpoint.
   247  type AuthenticateResponse struct {
   248  	TokenID               string `json:"token_id"`
   249  	TokenValidityInterval int    `json:"token_validity_interval"`
   250  	Session               struct {
   251  		Country          string `json:"country"`
   252  		IsLimitedCountry bool   `json:"is_limited_country"`
   253  		User             struct {
   254  			Login               string `json:"login"`
   255  			UserID              int64  `json:"user_id"`
   256  			Credit              int64  `json:"credit"`
   257  			AvatarURL           string `json:"avatar_url"`
   258  			FavoritesLink       string `json:"favorites_link"`
   259  			RootFolderSlug      string `json:"root_folder_slug"`
   260  			FavoritesFolderSlug string `json:"favorites_folder_slug"`
   261  			HasCloud            bool   `json:"has_cloud"`
   262  		} `json:"user"`
   263  	} `json:"session"`
   264  }