mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-04-25 06:35:21 +00: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.HfIsPrivate = hfChannel.isPrivate || false;
|
||||||
metadata.HfFileUrl = result.fileUrl;
|
metadata.HfFileUrl = result.fileUrl;
|
||||||
|
|
||||||
// 图像审查(公开仓库直接访问,私有仓库需要代理)
|
// 图像审查
|
||||||
let moderateUrl = result.fileUrl;
|
const securityConfig = context.securityConfig;
|
||||||
if (!hfChannel.isPrivate) {
|
const uploadModerate = securityConfig.upload?.moderate;
|
||||||
metadata.Label = await moderateContent(env, moderateUrl);
|
|
||||||
} else {
|
if (uploadModerate && uploadModerate.enabled) {
|
||||||
// 私有仓库暂不支持图像审查,标记为 None
|
if (!hfChannel.isPrivate) {
|
||||||
metadata.Label = "None";
|
// 公开仓库:直接通过公开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 数据库
|
// 写入 KV 数据库
|
||||||
|
|||||||
@@ -102,7 +102,12 @@ export async function moderateContent(env, url) {
|
|||||||
label = "None";
|
label = "None";
|
||||||
} else {
|
} else {
|
||||||
try {
|
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) {
|
if (!fetchResponse.ok) {
|
||||||
throw new Error(`HTTP error! status: ${fetchResponse.status}`);
|
throw new Error(`HTTP error! status: ${fetchResponse.status}`);
|
||||||
}
|
}
|
||||||
@@ -119,7 +124,7 @@ export async function moderateContent(env, url) {
|
|||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
||||||
// nsfw 渠道 和 默认渠道
|
// nsfw 渠道
|
||||||
if (uploadModerate.channel === 'nsfwjs') {
|
if (uploadModerate.channel === 'nsfwjs') {
|
||||||
const nsfwApiPath = securityConfig.upload.moderate.nsfwApiPath;
|
const nsfwApiPath = securityConfig.upload.moderate.nsfwApiPath;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user