feat: initial commit

This commit is contained in:
eric
2026-03-12 22:16:34 +01:00
parent 8555b02752
commit f13f4a9a69
155 changed files with 11988 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package updates
import (
"context"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"net/http"
"os"
)
type HTTPDownloader struct {
client *http.Client
}
func NewHTTPDownloader(client *http.Client) *HTTPDownloader {
if client == nil {
client = http.DefaultClient
}
return &HTTPDownloader{client: client}
}
func (downloader *HTTPDownloader) Download(ctx context.Context, artifact Artifact) (DownloadedFile, error) {
request, err := http.NewRequestWithContext(ctx, http.MethodGet, artifact.URL, nil)
if err != nil {
return DownloadedFile{}, err
}
response, err := downloader.client.Do(request)
if err != nil {
return DownloadedFile{}, err
}
defer response.Body.Close()
if response.StatusCode < 200 || response.StatusCode >= 300 {
return DownloadedFile{}, fmt.Errorf("unexpected download status: %s", response.Status)
}
file, err := os.CreateTemp("", "wails3kit-download-*")
if err != nil {
return DownloadedFile{}, err
}
defer file.Close()
hash := sha256.New()
written, err := io.Copy(io.MultiWriter(file, hash), response.Body)
if err != nil {
_ = os.Remove(file.Name())
return DownloadedFile{}, err
}
return DownloadedFile{
Path: file.Name(),
Size: written,
SHA256: hex.EncodeToString(hash.Sum(nil)),
}, nil
}