Remove UploadID field from backups (#80)

This commit is contained in:
Matthew Penner 2020-12-26 13:27:52 -07:00 committed by GitHub
parent 5be6e20b03
commit ddb683efb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,16 +2,10 @@ package api
import (
"fmt"
"github.com/patrickmn/go-cache"
"strconv"
"time"
)
// backupUploadIDs stores a cache of active S3 backups.
var backupUploadIDs = cache.New(time.Hour*3, time.Minute*5)
type BackupRemoteUploadResponse struct {
UploadID string `json:"upload_id"`
Parts []string `json:"parts"`
PartSize int64 `json:"part_size"`
}
@ -32,16 +26,10 @@ func (r *Request) GetBackupRemoteUploadURLs(backup string, size int64) (*BackupR
return nil, err
}
// Store the backup upload id for later use, this is a janky way to be able to use it later with SendBackupStatus.
// Yes, the timeout of 3 hours is intentional, if this value is removed before the backup completes,
// the backup will fail even if it uploaded properly.
backupUploadIDs.Set(backup, res.UploadID, 0)
return &res, nil
}
type BackupRequest struct {
UploadID string `json:"upload_id"`
Checksum string `json:"checksum"`
ChecksumType string `json:"checksum_type"`
Size int64 `json:"size"`
@ -51,11 +39,6 @@ type BackupRequest struct {
// Notifies the panel that a specific backup has been completed and is now
// available for a user to view and download.
func (r *Request) SendBackupStatus(backup string, data BackupRequest) error {
// Set the UploadID on the data.
if v, ok := backupUploadIDs.Get(backup); ok {
data.UploadID = v.(string)
}
resp, err := r.Post(fmt.Sprintf("/backups/%s", backup), data)
if err != nil {
return err