Address code review feedback: add validation and improve error handling
Co-authored-by: krau <71133316+krau@users.noreply.github.com>
This commit is contained in:
@@ -49,10 +49,13 @@ func (t *Task) Execute(ctx context.Context) error {
|
|||||||
filename := parseFilename(name)
|
filename := parseFilename(name)
|
||||||
file.Name = filename
|
file.Name = filename
|
||||||
}
|
}
|
||||||
// Fallback: extract filename from URL if Content-Disposition is empty
|
// Fallback: extract filename from URL if no filename was determined from Content-Disposition
|
||||||
if file.Name == "" {
|
if file.Name == "" {
|
||||||
file.Name = filenameFromURL(file.URL)
|
file.Name = filenameFromURL(file.URL)
|
||||||
}
|
}
|
||||||
|
if file.Name == "" {
|
||||||
|
return fmt.Errorf("could not determine filename for %s", file.URL)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ func TestFilenameFromURL(t *testing.T) {
|
|||||||
url: "https://cdn.example.com/a/b/c/d/e/video.mkv",
|
url: "https://cdn.example.com/a/b/c/d/e/video.mkv",
|
||||||
expected: "video.mkv",
|
expected: "video.mkv",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "malformed url with invalid characters",
|
||||||
|
url: "://invalid url",
|
||||||
|
expected: "",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user