update v2.5.3

This commit is contained in:
MarSeventh
2026-01-17 15:50:58 +08:00
parent baa1bf8929
commit 563a0bee64
2 changed files with 27 additions and 9 deletions

View File

@@ -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 数据库

View File

@@ -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;