2020-04-14 05:01:07 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-31 23:47:41 +00:00
|
|
|
"strconv"
|
2020-04-14 05:01:07 +00:00
|
|
|
)
|
|
|
|
|
2020-10-31 23:47:41 +00:00
|
|
|
type BackupRemoteUploadResponse struct {
|
2020-11-01 17:30:25 +00:00
|
|
|
CompleteMultipartUpload string `json:"complete_multipart_upload"`
|
|
|
|
AbortMultipartUpload string `json:"abort_multipart_upload"`
|
|
|
|
Parts []string `json:"parts"`
|
|
|
|
PartSize int64 `json:"part_size"`
|
2020-10-31 23:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Request) GetBackupRemoteUploadURLs(backup string, size int64) (*BackupRemoteUploadResponse, error) {
|
|
|
|
resp, err := r.Get(fmt.Sprintf("/backups/%s", backup), Q{"size": strconv.FormatInt(size, 10)})
|
|
|
|
if err != nil {
|
2020-11-28 23:57:10 +00:00
|
|
|
return nil, err
|
2020-10-31 23:47:41 +00:00
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
if resp.HasError() {
|
|
|
|
return nil, resp.Error()
|
|
|
|
}
|
|
|
|
|
|
|
|
var res BackupRemoteUploadResponse
|
|
|
|
if err := resp.Bind(&res); err != nil {
|
2020-11-28 23:57:10 +00:00
|
|
|
return nil, err
|
2020-10-31 23:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &res, nil
|
|
|
|
}
|
|
|
|
|
2020-04-14 05:01:07 +00:00
|
|
|
type BackupRequest struct {
|
2020-08-24 00:52:46 +00:00
|
|
|
Checksum string `json:"checksum"`
|
|
|
|
ChecksumType string `json:"checksum_type"`
|
|
|
|
Size int64 `json:"size"`
|
|
|
|
Successful bool `json:"successful"`
|
2020-04-14 05:01:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Notifies the panel that a specific backup has been completed and is now
|
|
|
|
// available for a user to view and download.
|
2020-10-31 17:04:20 +00:00
|
|
|
func (r *Request) SendBackupStatus(backup string, data BackupRequest) error {
|
2020-11-01 22:04:57 +00:00
|
|
|
resp, err := r.Post(fmt.Sprintf("/backups/%s", backup), data)
|
2020-04-14 05:01:07 +00:00
|
|
|
if err != nil {
|
2020-11-28 23:57:10 +00:00
|
|
|
return err
|
2020-04-14 05:01:07 +00:00
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2020-10-31 17:04:20 +00:00
|
|
|
return resp.Error()
|
2020-04-14 05:01:07 +00:00
|
|
|
}
|