2020-04-14 05:01:07 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-10-31 23:47:41 +00:00
|
|
|
"strconv"
|
2020-12-06 20:56:17 +00:00
|
|
|
)
|
|
|
|
|
2020-10-31 23:47:41 +00:00
|
|
|
type BackupRemoteUploadResponse struct {
|
2020-12-06 20:56:17 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-19 05:20:58 +00:00
|
|
|
// SendBackupStatus 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
|
|
|
}
|
2021-01-19 05:20:58 +00:00
|
|
|
|
|
|
|
// SendRestorationStatus triggers a request to the Panel to notify it that a
|
|
|
|
// restoration has been completed and the server should be marked as being
|
|
|
|
// activated again.
|
|
|
|
func (r *Request) SendRestorationStatus(backup string, successful bool) error {
|
|
|
|
resp, err := r.Post(fmt.Sprintf("/backups/%s/restore", backup), D{"successful": successful})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
return resp.Error()
|
|
|
|
}
|