From 7eee7041eac0a471b9d0be9e99e78f524042d0cf Mon Sep 17 00:00:00 2001 From: eoao Date: Fri, 5 Sep 2025 16:24:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=B9=E9=87=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=82=AE=E4=BB=B6=E6=97=B6=E6=BC=8F=E6=8E=89=E9=99=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mail-worker/src/service/att-service.js | 34 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/mail-worker/src/service/att-service.js b/mail-worker/src/service/att-service.js index f6f22bd..2881c4b 100644 --- a/mail-worker/src/service/att-service.js +++ b/mail-worker/src/service/att-service.js @@ -7,6 +7,7 @@ import fileUtils from '../utils/file-utils'; import { attConst } from '../const/entity-const'; import { parseHTML } from 'linkedom'; import domainUtils from '../utils/domain-uitls'; +import BizError from '../error/biz-error'; const attService = { @@ -19,13 +20,14 @@ const attService = { } if (!attachment.contentId) { - metadate.contentDisposition = `attachment; filename="${attachment.filename}"` + metadate.contentDisposition = `attachment;filename=${attachment.filename}` } else { - metadate.contentDisposition = `inline; filename="${attachment.filename}"` + metadate.contentDisposition = `inline;filename=${attachment.filename}` metadate.cacheControl = `max-age=259200` } await r2Service.putObj(c, attachment.key, attachment.content, metadate); + } await orm(c).insert(att).values(attachments).run(); @@ -104,7 +106,7 @@ const attService = { for (let att of attList) { await r2Service.putObj(c, att.key, att.buff, { contentType: att.type, - contentDisposition: `attachment; filename="${att.filename}"` + contentDisposition: `attachment;filename=${att.filename}` }); } @@ -120,7 +122,7 @@ const attService = { await r2Service.putObj(c, attData.key, attData.buff, { contentType: attData.mimeType, cacheControl: `max-age=259200`, - contentDisposition: `inline; filename="${attData.filename}"` + contentDisposition: `inline;filename=${attData.filename}` }); } @@ -147,26 +149,36 @@ const attService = { async removeAttByField(c, fieldName, fieldValues) { - const queryAttSql = fieldValues.map(value => - c.env.db.prepare(`SELECT a.key, a.att_id + const sqlList = []; + + fieldValues.forEach(value => { + + sqlList.push( + + c.env.db.prepare( + `SELECT a.key, a.att_id FROM attachments a JOIN (SELECT key FROM attachments GROUP BY key HAVING COUNT (*) = 1) t ON a.key = t.key - WHERE a.${fieldName} = ?;`).bind(value)); + WHERE a.${fieldName} = ?;` + ).bind(value) + ) - const attListResult = await c.env.db.batch(queryAttSql); + sqlList.push(c.env.db.prepare(`DELETE FROM attachments WHERE ${fieldName} = ?`).bind(value)) - const delKeyList = attListResult.flatMap(r => r.results.map(row => row.key)); + }); + + const attListResult = await c.env.db.batch(sqlList); + + const delKeyList = attListResult.flatMap(r => r.results ? r.results.map(row => row.key) : []); if (delKeyList.length > 0) { await this.batchDelete(c, delKeyList); } - const delAttSql = fieldValues.map(value => c.env.db.prepare(`DELETE FROM attachments WHERE ${fieldName} = ?`).bind(value)); - await c.env.db.batch(delAttSql); }, async batchDelete(c, keys) {