From eb5393f299eef157ad5fb2c533f586db7bdcf5f9 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Fri, 11 Sep 2026 13:21:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(attachments):=20=E6=96=87=E6=9C=AC=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E6=89=93=E5=BC=80=E4=B8=AD=E6=96=87=E4=B9=B1=E7=A0=81?= =?UTF-8?q?=E2=80=94=E2=80=94aiohttp=20FileResponse=E6=8C=89=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E5=90=8D=E7=8C=9CContent-Type=E4=B8=8D=E9=99=84charse?= =?UTF-8?q?t,text/plain=E6=97=A0charset=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E6=8C=89ISO-8859-1=E8=A7=A3UTF-8;=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E6=98=BE=E5=BC=8F=E8=AE=BEcharset=3Dutf-8,=E6=9C=AA=E7=9F=A5?= =?UTF-8?q?=E6=89=A9=E5=B1=95=E5=90=8D=E7=BA=AF=E6=96=87=E6=9C=AC=E5=BD=92?= =?UTF-8?q?text/plain=E5=86=85=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/ticket_attachment.dspy | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wwwroot/api/ticket_attachment.dspy b/wwwroot/api/ticket_attachment.dspy index 4c0606a..33270b1 100644 --- a/wwwroot/api/ticket_attachment.dspy +++ b/wwwroot/api/ticket_attachment.dspy @@ -30,4 +30,21 @@ else: headers['Content-Disposition'] = ( 'inline; filename="%s"; filename*=UTF-8\'\'%s' % (fname, safe_name)) +# 文本类显式带 charset=utf-8:aiohttp FileResponse 按扩展名猜 Content-Type 不附 +# charset,text/plain 无 charset 时浏览器按 ISO-8859-1 解 UTF-8 → 中文乱码 +# (2026-09-11 用户报障)。未知扩展名的纯文本(log/conf 等)也归入 text/plain 内联展示。 +import mimetypes as _mt +_ctype = _mt.guess_type(fname)[0] or '' +if not _ctype: + _ext = fname.rsplit('.', 1)[-1].lower() if '.' in fname else '' + if _ext in ('txt', 'log', 'md', 'csv', 'conf', 'ini', 'yml', 'yaml', + 'py', 'js', 'sh', 'sql', 'json'): + _ctype = 'text/plain' +if _ctype.startswith('text/') or _ctype in ( + 'application/json', 'application/javascript', + 'application/xml', 'image/svg+xml'): + _ctype += '; charset=utf-8' +if _ctype: + headers['Content-Type'] = _ctype + return FileResponse(full_path, headers=headers)