github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/backend/mailru/api/m1.go (about)

     1  package api
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // M1 protocol constants and structures
     8  const (
     9  	APIServerURL      = "https://cloud.mail.ru"
    10  	PublicLinkURL     = "https://cloud.mail.ru/public/"
    11  	DispatchServerURL = "https://dispatcher.cloud.mail.ru"
    12  	OAuthURL          = "https://o2.mail.ru/token"
    13  	OAuthClientID     = "cloud-win"
    14  )
    15  
    16  // ServerErrorResponse represents erroneous API response.
    17  type ServerErrorResponse struct {
    18  	Message string `json:"body"`
    19  	Time    int64  `json:"time"`
    20  	Status  int    `json:"status"`
    21  }
    22  
    23  func (e *ServerErrorResponse) Error() string {
    24  	return fmt.Sprintf("server error %d (%s)", e.Status, e.Message)
    25  }
    26  
    27  // FileErrorResponse represents erroneous API response for a file
    28  type FileErrorResponse struct {
    29  	Body struct {
    30  		Home struct {
    31  			Value string `json:"value"`
    32  			Error string `json:"error"`
    33  		} `json:"home"`
    34  	} `json:"body"`
    35  	Status  int    `json:"status"`
    36  	Account string `json:"email,omitempty"`
    37  	Time    int64  `json:"time,omitempty"`
    38  	Message string // non-json, calculated field
    39  }
    40  
    41  func (e *FileErrorResponse) Error() string {
    42  	return fmt.Sprintf("file error %d (%s)", e.Status, e.Body.Home.Error)
    43  }
    44  
    45  // UserInfoResponse contains account metadata
    46  type UserInfoResponse struct {
    47  	Body struct {
    48  		AccountType     string `json:"account_type"`
    49  		AccountVerified bool   `json:"account_verified"`
    50  		Cloud           struct {
    51  			Beta struct {
    52  				Allowed bool `json:"allowed"`
    53  				Asked   bool `json:"asked"`
    54  			} `json:"beta"`
    55  			Billing struct {
    56  				ActiveCostID string `json:"active_cost_id"`
    57  				ActiveRateID string `json:"active_rate_id"`
    58  				AutoProlong  bool   `json:"auto_prolong"`
    59  				Basequota    int64  `json:"basequota"`
    60  				Enabled      bool   `json:"enabled"`
    61  				Expires      int    `json:"expires"`
    62  				Prolong      bool   `json:"prolong"`
    63  				Promocodes   struct {
    64  				} `json:"promocodes"`
    65  				Subscription []interface{} `json:"subscription"`
    66  				Version      string        `json:"version"`
    67  			} `json:"billing"`
    68  			Bonuses struct {
    69  				CameraUpload bool `json:"camera_upload"`
    70  				Complete     bool `json:"complete"`
    71  				Desktop      bool `json:"desktop"`
    72  				Feedback     bool `json:"feedback"`
    73  				Links        bool `json:"links"`
    74  				Mobile       bool `json:"mobile"`
    75  				Registration bool `json:"registration"`
    76  			} `json:"bonuses"`
    77  			Enable struct {
    78  				Sharing bool `json:"sharing"`
    79  			} `json:"enable"`
    80  			FileSizeLimit int64 `json:"file_size_limit"`
    81  			Space         struct {
    82  				BytesTotal int64 `json:"bytes_total"`
    83  				BytesUsed  int   `json:"bytes_used"`
    84  				Overquota  bool  `json:"overquota"`
    85  			} `json:"space"`
    86  		} `json:"cloud"`
    87  		Cloudflags struct {
    88  			Exists bool `json:"exists"`
    89  		} `json:"cloudflags"`
    90  		Domain string `json:"domain"`
    91  		Login  string `json:"login"`
    92  		Newbie bool   `json:"newbie"`
    93  		UI     struct {
    94  			ExpandLoader bool   `json:"expand_loader"`
    95  			Kind         string `json:"kind"`
    96  			Sidebar      bool   `json:"sidebar"`
    97  			Sort         struct {
    98  				Order string `json:"order"`
    99  				Type  string `json:"type"`
   100  			} `json:"sort"`
   101  			Thumbs bool `json:"thumbs"`
   102  		} `json:"ui"`
   103  	} `json:"body"`
   104  	Email  string `json:"email"`
   105  	Status int    `json:"status"`
   106  	Time   int64  `json:"time"`
   107  }
   108  
   109  // ListItem ...
   110  type ListItem struct {
   111  	Count struct {
   112  		Folders int `json:"folders"`
   113  		Files   int `json:"files"`
   114  	} `json:"count,omitempty"`
   115  	Kind      string `json:"kind"`
   116  	Type      string `json:"type"`
   117  	Name      string `json:"name"`
   118  	Home      string `json:"home"`
   119  	Size      int64  `json:"size"`
   120  	Mtime     int64  `json:"mtime,omitempty"`
   121  	Hash      string `json:"hash,omitempty"`
   122  	VirusScan string `json:"virus_scan,omitempty"`
   123  	Tree      string `json:"tree,omitempty"`
   124  	Grev      int    `json:"grev,omitempty"`
   125  	Rev       int    `json:"rev,omitempty"`
   126  }
   127  
   128  // ItemInfoResponse ...
   129  type ItemInfoResponse struct {
   130  	Email  string   `json:"email"`
   131  	Body   ListItem `json:"body"`
   132  	Time   int64    `json:"time"`
   133  	Status int      `json:"status"`
   134  }
   135  
   136  // FolderInfoResponse ...
   137  type FolderInfoResponse struct {
   138  	Body struct {
   139  		Count struct {
   140  			Folders int `json:"folders"`
   141  			Files   int `json:"files"`
   142  		} `json:"count"`
   143  		Tree string `json:"tree"`
   144  		Name string `json:"name"`
   145  		Grev int    `json:"grev"`
   146  		Size int64  `json:"size"`
   147  		Sort struct {
   148  			Order string `json:"order"`
   149  			Type  string `json:"type"`
   150  		} `json:"sort"`
   151  		Kind string     `json:"kind"`
   152  		Rev  int        `json:"rev"`
   153  		Type string     `json:"type"`
   154  		Home string     `json:"home"`
   155  		List []ListItem `json:"list"`
   156  	} `json:"body,omitempty"`
   157  	Time   int64  `json:"time"`
   158  	Status int    `json:"status"`
   159  	Email  string `json:"email"`
   160  }
   161  
   162  // ShardInfoResponse ...
   163  type ShardInfoResponse struct {
   164  	Email string `json:"email"`
   165  	Body  struct {
   166  		Video []struct {
   167  			Count string `json:"count"`
   168  			URL   string `json:"url"`
   169  		} `json:"video"`
   170  		ViewDirect []struct {
   171  			Count string `json:"count"`
   172  			URL   string `json:"url"`
   173  		} `json:"view_direct"`
   174  		WeblinkView []struct {
   175  			Count string `json:"count"`
   176  			URL   string `json:"url"`
   177  		} `json:"weblink_view"`
   178  		WeblinkVideo []struct {
   179  			Count string `json:"count"`
   180  			URL   string `json:"url"`
   181  		} `json:"weblink_video"`
   182  		WeblinkGet []struct {
   183  			Count int    `json:"count"`
   184  			URL   string `json:"url"`
   185  		} `json:"weblink_get"`
   186  		Stock []struct {
   187  			Count string `json:"count"`
   188  			URL   string `json:"url"`
   189  		} `json:"stock"`
   190  		WeblinkThumbnails []struct {
   191  			Count string `json:"count"`
   192  			URL   string `json:"url"`
   193  		} `json:"weblink_thumbnails"`
   194  		PublicUpload []struct {
   195  			Count string `json:"count"`
   196  			URL   string `json:"url"`
   197  		} `json:"public_upload"`
   198  		Auth []struct {
   199  			Count string `json:"count"`
   200  			URL   string `json:"url"`
   201  		} `json:"auth"`
   202  		Web []struct {
   203  			Count string `json:"count"`
   204  			URL   string `json:"url"`
   205  		} `json:"web"`
   206  		View []struct {
   207  			Count string `json:"count"`
   208  			URL   string `json:"url"`
   209  		} `json:"view"`
   210  		Upload []struct {
   211  			Count string `json:"count"`
   212  			URL   string `json:"url"`
   213  		} `json:"upload"`
   214  		Get []struct {
   215  			Count string `json:"count"`
   216  			URL   string `json:"url"`
   217  		} `json:"get"`
   218  		Thumbnails []struct {
   219  			Count string `json:"count"`
   220  			URL   string `json:"url"`
   221  		} `json:"thumbnails"`
   222  	} `json:"body"`
   223  	Time   int64 `json:"time"`
   224  	Status int   `json:"status"`
   225  }
   226  
   227  // CleanupResponse ...
   228  type CleanupResponse struct {
   229  	Email     string `json:"email"`
   230  	Time      int64  `json:"time"`
   231  	StatusStr string `json:"status"`
   232  }
   233  
   234  // GenericResponse ...
   235  type GenericResponse struct {
   236  	Email  string `json:"email"`
   237  	Time   int64  `json:"time"`
   238  	Status int    `json:"status"`
   239  	// ignore other fields
   240  }
   241  
   242  // GenericBodyResponse ...
   243  type GenericBodyResponse struct {
   244  	Email  string `json:"email"`
   245  	Body   string `json:"body"`
   246  	Time   int64  `json:"time"`
   247  	Status int    `json:"status"`
   248  }