Check ~name parameter for file downloader
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2023-01-29 17:56:11 -08:00
parent d4396756d6
commit 2c8eb6be48
1 changed files with 18 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"crypto/sha256"
"io"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
@ -35,12 +36,27 @@ func (FileDownloader) MatchURL(string) bool {
// Download downloads a file using HTTP. If the file is
// compressed using a supported format, it will be extracted
func (FileDownloader) Download(opts Options) (Type, string, error) {
res, err := http.Get(opts.URL)
u, err := url.Parse(opts.URL)
if err != nil {
return 0, "", err
}
name := getFilename(res)
query := u.Query()
name := query.Get("~name")
query.Del("~name")
u.RawQuery = query.Encode()
res, err := http.Get(u.String())
if err != nil {
return 0, "", err
}
if name == "" {
name = getFilename(res)
}
path := filepath.Join(opts.Destination, name)
fl, err := os.Create(path)
if err != nil {