mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-01-31 00:53:20 +08:00
update v2.5.3
This commit is contained in:
@@ -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 数据库
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user