Phase4
Some checks failed
CI / Node — lint, typecheck, test, build (push) Failing after 9s
CI / Go — node-agent tests (push) Failing after 9s
CI / Go — edge-gateway build (push) Successful in 13s

This commit is contained in:
smueller
2026-06-26 12:32:27 +02:00
parent 9b061c3ee7
commit 4262464cd5
101 changed files with 4024 additions and 74 deletions

View File

@@ -0,0 +1,73 @@
package transfer
import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"time"
)
// UploadFile PUTs a local file to a presigned URL.
func UploadFile(localPath, uploadURL string) error {
file, err := os.Open(localPath)
if err != nil {
return err
}
defer file.Close()
stat, err := file.Stat()
if err != nil {
return err
}
request, err := http.NewRequest(http.MethodPut, uploadURL, file)
if err != nil {
return err
}
request.ContentLength = stat.Size()
request.Header.Set("Content-Type", "application/gzip")
client := &http.Client{Timeout: 30 * time.Minute}
response, err := client.Do(request)
if err != nil {
return err
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode >= 300 {
body, _ := io.ReadAll(io.LimitReader(response.Body, 4096))
return fmt.Errorf("upload failed with status %d: %s", response.StatusCode, string(body))
}
return nil
}
// DownloadFile GETs a remote file to a local path.
func DownloadFile(downloadURL, localPath string) error {
if err := os.MkdirAll(filepath.Dir(localPath), 0o755); err != nil {
return err
}
client := &http.Client{Timeout: 30 * time.Minute}
response, err := client.Get(downloadURL)
if err != nil {
return err
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode >= 300 {
body, _ := io.ReadAll(io.LimitReader(response.Body, 4096))
return fmt.Errorf("download failed with status %d: %s", response.StatusCode, string(body))
}
file, err := os.Create(localPath)
if err != nil {
return err
}
defer file.Close()
_, err = io.Copy(file, response.Body)
return err
}