mirror of
https://github.com/saltbo/zpan.git
synced 2026-08-30 17:50:07 +08:00
fix(downloader): stabilize docker runtime validation
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||
|
||||
COPY . .
|
||||
RUN pnpm build:node \
|
||||
&& pnpm prune --prod
|
||||
&& pnpm prune --prod --ignore-scripts
|
||||
|
||||
FROM golang:1.25 AS cli-builder
|
||||
WORKDIR /app/cmd
|
||||
|
||||
@@ -125,6 +125,9 @@ func (a Aria2) Check(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (a Aria2) ResetTask(ctx context.Context, task client.DownloadTask) error {
|
||||
if task.SourceType() == "http" {
|
||||
return HTTP{Dir: a.Dir}.ResetTask(ctx, task)
|
||||
}
|
||||
aria, err := a.client(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -194,6 +197,9 @@ func (a Aria2) RestoreSeed(ctx context.Context, ref SeedRef) (*Seed, error) {
|
||||
}
|
||||
|
||||
func (a Aria2) InspectTask(ctx context.Context, task client.DownloadTask) (TaskSnapshot, bool, error) {
|
||||
if task.SourceType() == "http" {
|
||||
return HTTP{Dir: a.Dir}.InspectTask(ctx, task)
|
||||
}
|
||||
aria, err := a.client(ctx)
|
||||
if err != nil {
|
||||
return TaskSnapshot{}, false, err
|
||||
@@ -207,6 +213,9 @@ func (a Aria2) InspectTask(ctx context.Context, task client.DownloadTask) (TaskS
|
||||
}
|
||||
|
||||
func (a Aria2) Download(ctx context.Context, task client.DownloadTask, progress Progress) (Result, error) {
|
||||
if task.SourceType() == "http" {
|
||||
return HTTP{Dir: a.Dir}.Download(ctx, task, progress)
|
||||
}
|
||||
taskDir := filepath.Join(a.Dir, task.ID)
|
||||
if err := os.MkdirAll(taskDir, 0o755); err != nil {
|
||||
return Result{}, err
|
||||
|
||||
@@ -98,6 +98,39 @@ func TestHTTPRejectsMagnet(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAria2DelegatesHTTPToBuiltin(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Length", "11")
|
||||
_, _ = w.Write([]byte("hello world"))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
result, err := (Aria2{
|
||||
URL: "ws://127.0.0.1:1/jsonrpc",
|
||||
Dir: t.TempDir(),
|
||||
}).Download(
|
||||
context.Background(),
|
||||
downloadTask("task-1", "http", server.URL+"/file.txt"),
|
||||
func(downloaded int64, total *int64, bps int64, detail *client.DownloadTaskRuntime) error {
|
||||
if detail != nil && detail.Engine != "builtin" {
|
||||
t.Fatalf("expected builtin HTTP runtime detail, got %#v", detail)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
data, err := os.ReadFile(result.Path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(data) != "hello world" {
|
||||
t.Fatalf("unexpected file content: %q", string(data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestAria2StartArgsForceSaveCompletedSeeds(t *testing.T) {
|
||||
stateDir := t.TempDir()
|
||||
args, err := (Aria2{Dir: t.TempDir(), StateDir: stateDir}).startArgs("6800")
|
||||
|
||||
@@ -20,6 +20,12 @@ services:
|
||||
depends_on:
|
||||
rustfs:
|
||||
condition: service_started
|
||||
healthcheck:
|
||||
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:8222/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
start_period: 10s
|
||||
restart: unless-stopped
|
||||
|
||||
downloader:
|
||||
@@ -34,7 +40,7 @@ services:
|
||||
- zpan-downloads:/downloads
|
||||
depends_on:
|
||||
zpan:
|
||||
condition: service_started
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
|
||||
rustfs:
|
||||
|
||||
@@ -13,6 +13,12 @@ services:
|
||||
- DATABASE_URL=/data/zpan.db
|
||||
volumes:
|
||||
- zpan-data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:8222/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
start_period: 10s
|
||||
restart: unless-stopped
|
||||
|
||||
downloader:
|
||||
@@ -27,7 +33,7 @@ services:
|
||||
- zpan-downloads:/downloads
|
||||
depends_on:
|
||||
zpan:
|
||||
condition: service_started
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
|
||||
+7
-1
@@ -13,6 +13,12 @@ services:
|
||||
- DATABASE_URL=/data/zpan.db
|
||||
volumes:
|
||||
- zpan-data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:8222/api/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
start_period: 10s
|
||||
restart: unless-stopped
|
||||
|
||||
downloader:
|
||||
@@ -29,7 +35,7 @@ services:
|
||||
- zpan-downloads:/downloads
|
||||
depends_on:
|
||||
zpan:
|
||||
condition: service_started
|
||||
condition: service_healthy
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
|
||||
Reference in New Issue
Block a user