fix: 店铺二维码下载拒绝异常大文件

超过2MB的OSS对象视为路径错误,提示重新生成而非原样返回。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
XingQue
2026-07-10 00:04:21 +08:00
parent df49631401
commit 65dae4f3ab

View File

@@ -499,6 +499,14 @@ class QrcodeDownloadView(APIView):
if not image_data:
return Response({'code': 404, 'msg': '二维码文件不存在'}, status=404)
# 店铺二维码正常仅数十 KB超过 2MB 视为 OSS 路径异常
if len(image_data) > 2 * 1024 * 1024:
logger.error(
'店铺二维码文件体积异常 dianpu=%s key=%s size=%s',
dianpu.id, oss_key, len(image_data),
)
return Response({'code': 500, 'msg': '二维码文件异常,请重新生成'}, status=500)
# 4. 返回图片inline 供页面展示attachment 供下载)
filename = f"shop_qrcode_{dianpu.id}.png"
disposition_type = 'inline' if request.GET.get('disposition') == 'inline' else 'attachment'