mirror of https://github.com/Xhofe/alist
fix(offline_download): os.create failure while the name of downloaded file is empty (#7041)
parent
bcb24d61ea
commit
74887922b4
|
@ -2,14 +2,16 @@ package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"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/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"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 {
|
type SimpleHttp struct {
|
||||||
|
@ -63,7 +65,12 @@ func (s SimpleHttp) Run(task *tool.DownloadTask) error {
|
||||||
if resp.StatusCode >= 400 {
|
if resp.StatusCode >= 400 {
|
||||||
return fmt.Errorf("http status code %d", resp.StatusCode)
|
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 {
|
if n, err := parseFilenameFromContentDisposition(resp.Header.Get("Content-Disposition")); err == nil {
|
||||||
filename = n
|
filename = n
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue