restore
This commit is contained in:
@@ -238,6 +238,7 @@ func (s *Server) HandleUpload(w http.ResponseWriter, r *http.Request) {
|
||||
Message: "Ready to receive snapshot",
|
||||
UploadMethod: "zfs-receive",
|
||||
StorageKey: snapshotName,
|
||||
UploadURL: fmt.Sprintf("/upload-stream/%s", req.ClientID),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -280,23 +281,48 @@ func (s *Server) HandleUploadStream(w http.ResponseWriter, r *http.Request) {
|
||||
size = -1 // Use streaming upload for unknown size
|
||||
}
|
||||
|
||||
if s.s3Backend == nil {
|
||||
log.Printf("Error: S3 backend not initialized")
|
||||
http.Error(w, "S3 backend not configured", http.StatusInternalServerError)
|
||||
if s.s3Backend == nil && s.localBackend == nil {
|
||||
log.Printf("Error: No storage backend configured")
|
||||
http.Error(w, "No storage backend configured", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err := s.s3Backend.Upload(ctx, storageKey, r.Body, size); err != nil {
|
||||
log.Printf("Error uploading to S3: %v", err)
|
||||
http.Error(w, "Upload failed", http.StatusInternalServerError)
|
||||
// Determine storage type based on client configuration
|
||||
client, err := s.db.GetClient(clientID)
|
||||
if err != nil || client == nil {
|
||||
http.Error(w, "Client not found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
// Get actual size after upload
|
||||
actualSize, err := s.s3Backend.GetSize(ctx, storageKey)
|
||||
if err != nil {
|
||||
log.Printf("Error getting object size: %v", err)
|
||||
var actualSize int64
|
||||
|
||||
// Handle based on storage type
|
||||
if client.StorageType == "s3" && s.s3Backend != nil {
|
||||
// Upload to S3
|
||||
if err := s.s3Backend.Upload(ctx, storageKey, r.Body, size); err != nil {
|
||||
log.Printf("Error uploading to S3: %v", err)
|
||||
http.Error(w, "Upload failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Get actual size after upload
|
||||
actualSize, err = s.s3Backend.GetSize(ctx, storageKey)
|
||||
if err != nil {
|
||||
log.Printf("Error getting object size: %v", err)
|
||||
actualSize = size
|
||||
}
|
||||
} else if client.StorageType == "local" && s.localBackend != nil {
|
||||
// Upload to local ZFS
|
||||
if err := s.localBackend.Receive(storageKey, r.Body, compressedStr == "true"); err != nil {
|
||||
log.Printf("Error uploading to local ZFS: %v", err)
|
||||
http.Error(w, "Upload failed", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
actualSize = size
|
||||
} else {
|
||||
log.Printf("Error: Storage type %s not configured", client.StorageType)
|
||||
http.Error(w, "Storage type not configured", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// Save metadata to database
|
||||
|
||||
Reference in New Issue
Block a user