Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Direct link downloads via /dl fail when the server omits Content-Disposition header—filename remains empty, causing saves to invalid paths like /Telegram/ instead of /Telegram/file.mp4.

Changes

  • core/tasks/directlinks/util.go: Add filenameFromURL() to extract filename from URL path with URL decoding support
  • core/tasks/directlinks/execute.go: Fall back to URL-based filename extraction when Content-Disposition is empty; return error if filename cannot be determined from either source
  • core/tasks/directlinks/util_test.go: Unit tests covering encoded filenames, edge cases, and malformed URLs

Example

// Before: filename only set from Content-Disposition
if name := resp.Header.Get("Content-Disposition"); name != "" {
    file.Name = parseFilename(name)
}

// After: fallback to URL path extraction
if name := resp.Header.Get("Content-Disposition"); name != "" {
    file.Name = parseFilename(name)
}
if file.Name == "" {
    file.Name = filenameFromURL(file.URL)  // e.g., "https://example.com/video.mp4" → "video.mp4"
}
if file.Name == "" {
    return fmt.Errorf("could not determine filename for %s", file.URL)
}
Original prompt

This section details on the original issue you should resolve

<issue_title>/dl下载直链若Content-Disposition为空,则文件名为空任务失败</issue_title>
<issue_description>### 👾 Description

/dl下载直链若Content-Disposition为空,则文件名为空任务失败

Image

⚡️ Expected Behavior

文件名正常获取

📄 Configuration File

# 存储列表
[[storages]]
# 标识名, 需要唯一
name = "189cloud"
# 存储类型, 目前可用: local, alist, webdav, s3, telegram
type = "webdav"
# 启用存储
enable = true
# 文件保存根路径
url = "http://192.168.2.5:5244/dav" # Alist 的 URL
username = "admin"  # Alist 的用户名
password = "x" # Alist 的密码
base_path = "/189cloud/来自家庭共享/Telegram" # Alist 中的基础路径, 所有文件将存储在此路径下

🔍 Logs

显示传输成功,但没见到文件:INFO <webdav/webdav.go:55> webdav[189cloud]: Saving file to 08:23:27 DEBU <webdav/webdav.go:81> webdav[189cloud]: Checking if file exists at /189cloud/来自家庭共享/Telegram 08:23:31 DEBU <webdav/webdav.go:81> webdav[189cloud]: Checking if file exists at /189cloud/来自家庭共享/Telegram_1 08:23:31 DEBU <webdav/webdav.go:81> webdav[189cloud]: Checking if file exists at /189cloud/来自家庭共享/Telegram_2 08:23:31 DEBU <webdav/webdav.go:81> webdav[189cloud]: Checking if file exists at /189cloud/来自家庭共享/Telegram_3 08:23:55 ERRO <directlinks/execute.go:134> Failed to close and remove cache file: close cache/direct_d5ri8990kahs73accqpg_: file already closed 08:23:55 INFO <directlinks/execute.go:100> Directlinks task d5ri8990kahs73accqpg completed successfully 08:23:55 INFO <directlinks/progress.go:78> Parsed task d5ri8990kahs73accqpg completed successfully 08:23:56 INFO <core/core.go:50> Task d5ri8990kahs73accqpg completed successfully

翻阅日志发现是/dl没有获取到文件名,正常日志:6:19:35 DEBU <tfile/progress.go:81> Progress update: 10月17日(6).mp4, 401331932/401331932 06:19:36 INFO <tfile/execute.go:47> file[10月17日(6).mp4]: File downloaded successfully 06:19:36 INFO <webdav/webdav.go:55> webdav[189cloud]: Saving file to 10月17日(6).mp4 06:19:36 DEBU <webdav/webdav.go:81> webdav[189cloud]: Checking if file exists at /189cloud/来自家庭共享/Telegram/10月17日(6).mp4 06:20:44 DEBU <tfile/progress.go:126> Progress done for file [10月17日(6).mp4] 怎么解决
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 28, 2026 08:57
…command

Add filenameFromURL helper to extract filename from URL path when
Content-Disposition header is empty or not present. This fixes the issue
where direct link downloads fail due to empty filename.

Co-authored-by: krau <71133316+krau@users.noreply.github.com>
Co-authored-by: krau <71133316+krau@users.noreply.github.com>
Co-authored-by: krau <71133316+krau@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix filename error when Content-Disposition is empty Fix empty filename when Content-Disposition header is missing in /dl command Jan 28, 2026
Copilot AI requested a review from krau January 28, 2026 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/dl下载直链若Content-Disposition为空,则文件名为空任务失败

2 participants