From 563a0bee64cddc6fd115abdba649e84eb9f4c3b9 Mon Sep 17 00:00:00 2001 From: MarSeventh <1193267292@qq.com> Date: Sat, 17 Jan 2026 15:50:58 +0800 Subject: [PATCH] update v2.5.3 --- functions/upload/index.js | 27 ++++++++++++++++++++------- functions/upload/uploadTools.js | 9 +++++++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/functions/upload/index.js b/functions/upload/index.js index 1729909..c006440 100644 --- a/functions/upload/index.js +++ b/functions/upload/index.js @@ -760,13 +760,26 @@ async function uploadFileToHuggingFace(context, fullId, metadata, returnLink) { metadata.HfIsPrivate = hfChannel.isPrivate || false; metadata.HfFileUrl = result.fileUrl; - // 图像审查(公开仓库直接访问,私有仓库需要代理) - let moderateUrl = result.fileUrl; - if (!hfChannel.isPrivate) { - metadata.Label = await moderateContent(env, moderateUrl); - } else { - // 私有仓库暂不支持图像审查,标记为 None - metadata.Label = "None"; + // 图像审查 + const securityConfig = context.securityConfig; + const uploadModerate = securityConfig.upload?.moderate; + + if (uploadModerate && uploadModerate.enabled) { + if (!hfChannel.isPrivate) { + // 公开仓库:直接通过公开URL访问进行审查,只写入1次KV + metadata.Label = await moderateContent(env, result.fileUrl); + } else { + // 私有仓库:先写入KV,再通过自己的域名访问进行审查 + try { + await db.put(fullId, "", { metadata }); + } catch (error) { + return createResponse('Error: Failed to write to KV database', { status: 500 }); + } + + const moderateUrl = `https://${context.url.hostname}/file/${fullId}`; + await purgeCDNCache(env, moderateUrl, context.url); + metadata.Label = await moderateContent(env, moderateUrl); + } } // 写入 KV 数据库 diff --git a/functions/upload/uploadTools.js b/functions/upload/uploadTools.js index d1d8eb8..3e5ce0c 100644 --- a/functions/upload/uploadTools.js +++ b/functions/upload/uploadTools.js @@ -102,7 +102,12 @@ export async function moderateContent(env, url) { label = "None"; } else { try { - const fetchResponse = await fetch(`https://api.moderatecontent.com/moderate/?key=${apikey}&url=${url}`); + const params = new URLSearchParams({ key: apikey, url: url }); + const fetchResponse = await fetch('https://api.moderatecontent.com/moderate/', { + method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: params.toString() + }); if (!fetchResponse.ok) { throw new Error(`HTTP error! status: ${fetchResponse.status}`); } @@ -119,7 +124,7 @@ export async function moderateContent(env, url) { return label; } - // nsfw 渠道 和 默认渠道 + // nsfw 渠道 if (uploadModerate.channel === 'nsfwjs') { const nsfwApiPath = securityConfig.upload.moderate.nsfwApiPath;