Skip to content

Commit

Permalink
fix(offline_download): os.create failure while the name of downloaded…
Browse files Browse the repository at this point in the history
… file is empty (#7041)
  • Loading branch information
xiaoqingwanga authored Aug 21, 2024
1 parent bcb24d6 commit 7488792
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/offline_download/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package http

import (
"fmt"
"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/offline_download/tool"
"github.com/alist-org/alist/v3/pkg/utils"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strings"

"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/internal/offline_download/tool"
"github.com/alist-org/alist/v3/pkg/utils"
)

type SimpleHttp struct {
Expand Down Expand Up @@ -63,7 +65,12 @@ func (s SimpleHttp) Run(task *tool.DownloadTask) error {
if resp.StatusCode >= 400 {
return fmt.Errorf("http status code %d", resp.StatusCode)
}
filename := path.Base(_u.Path)
// If Path is empty, use Hostname; otherwise, filePath euqals TempDir which causes os.Create to fail
urlPath := _u.Path
if urlPath == "" {
urlPath = strings.ReplaceAll(_u.Host, ".", "_")
}
filename := path.Base(urlPath)
if n, err := parseFilenameFromContentDisposition(resp.Header.Get("Content-Disposition")); err == nil {
filename = n
}
Expand Down

0 comments on commit 7488792

Please sign in to comment.