Skip to content

Commit

Permalink
Add image moderate feature (cf-pages#8)
Browse files Browse the repository at this point in the history
* Add content moderate
  • Loading branch information
cf-pages authored Nov 5, 2022
1 parent 8f16418 commit 693fc77
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
32 changes: 32 additions & 0 deletions block-img.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html class="no-js" lang="en-US" style="
height: 100%;
">
<head>
<title>The Image is blocked | Telegraph-Image</title>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="robots" content="noindex, nofollow">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>body{margin:0;padding:0}</style>


</head>
<body style="
height: 100%;
">
<div style="display: flex;flex-direction: column;align-content: center;justify-content: center;align-items: center;height: 100%;text-align: center;">
<div>
抱歉,当前图片未能通过审查,可能含有不良内容,故无法进行加载。
<br>
Sorry, the current image failed to pass the review and may contain undesirable content, so it cannot be loaded.
</div>
<br>
<div>Powered By: <span><a style="
color: cornflowerblue;"
href="https://github.com/cf-pages/Telegraph-Image">Telegraph-Image</a></span></div>
</div>


</body></html>
12 changes: 12 additions & 0 deletions functions/file/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ export async function onRequest(context) { // Contents of context object
} = context;
context.request
const url = new URL(request.url);

let apikey=env.ModerateContentApiKey
if(typeof apikey == "undefined" || apikey == null || apikey == ""){

}else{
const res = await fetch(`https://api.moderatecontent.com/moderate/?key=`+apikey+`&url=https://telegra.ph/` + url.pathname + url.search);
const moderate_data = await res.json();
if (moderate_data.rating_label=="adult"){
return Response.redirect(url.origin+"/block-img.html", 302)
}
}

const response = fetch('https://telegra.ph/' + url.pathname + url.search, {
method: request.method,
headers: request.headers,
Expand Down

0 comments on commit 693fc77

Please sign in to comment.