feat(img): /ai/img dl=1 支持 ?name= 自定义下载名(filename* UTF-8,缺省磁盘名不变)

This commit is contained in:
jinghui committed 2026-11-15 22:06:55 +08:00
1 parent 3ee96dd741
commit 1c6bbf3018
1 file changed
+9 -1
+9 -1
View File
@@ -4118,7 +4118,15 @@ class Handler(BaseHTTPRequestHandler):
self.send_header("Content-Length", str(len(raw)))
self.send_header("Cache-Control", "private, max-age=86400")
if dl == "1":
self.send_header("Content-Disposition", f'attachment; filename="{iid}{ext}"')
# 下载名:?name= 优先(UTF-8 文件名,浏览器全部支持 filename*),缺省用磁盘名
nm = str((qs.get("name") or [""])[0] or "")
nm = os.path.basename(nm.replace("\\", "/")).strip()[:180]
nm = re.sub(r'[\x00-\x1f\x7f"]', "", nm)
if nm and nm not in (".", ".."):
self.send_header("Content-Disposition",
"attachment; filename*=UTF-8''" + parse.quote(nm))
else:
self.send_header("Content-Disposition", f'attachment; filename="{iid}{ext}"')
self.end_headers()
try:
self.wfile.write(raw)