Skip to content

Commit

Permalink
优化代码逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
cf-pages committed Jan 17, 2023
1 parent b287a26 commit 54ae9cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions functions/api/manage/_middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ async function errorHandling(context) {
//context.env.BASIC_USER="admin"
//context.env.BASIC_PASS="admin"
//check if the env variables Disable_Dashboard are set
if (context.env.DISABLE_DASHBOARD == "true") {
return new Response('Dashboard is disabled. Please enable to use this feature.', { status: 200 });
if (typeof context.env.img_url == "undefined" || context.env.img_url == null || context.env.img_url == "") {
return new Response('Dashboard is disabled. Please bind a KV namespace to use this feature.', { status: 200 });
}

console.log(context.env.BASIC_USER)
Expand Down
12 changes: 6 additions & 6 deletions functions/file/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ export async function onRequest(context) { // Contents of context object
//show the image
return response;
}
console.log("env.Disable_Dashboard:")
console.log(env.Disable_Dashboard)
if (env.Disable_Dashboard){}else{

if (env.img_url){}else{
//check the record from kv
const record = await env.img_url.getWithMetadata(params.id);
console.log(record)
Expand All @@ -36,6 +35,8 @@ export async function onRequest(context) { // Contents of context object
return response;
}else if (record.metadata.ListType=="Block"){
return Response.redirect(url.origin+"/block-img.html", 302)
}else if (record.metadata.Label=="adult"){
return Response.redirect(url.origin+"/block-img.html", 302)
}
//check if the env variables WhiteList_Mode are set
if (env.WhiteList_Mode=="true"){
Expand All @@ -52,9 +53,8 @@ export async function onRequest(context) { // Contents of context object
let apikey=env.ModerateContentApiKey

if(typeof apikey == "undefined" || apikey == null || apikey == ""){
//check if the env variables Disable_Dashboard are set

if (env.Disable_Dashboard){console.log(1)}else{
if (env.img_url){console.log(1)}else{
//add image to kv
await env.img_url.put(params.id, "",{
metadata: { ListType: "None", rating_label: "None",TimeStamp: time },
Expand All @@ -65,7 +65,7 @@ export async function onRequest(context) { // Contents of context object
then(async (response) => {
let moderate_data = await response.json();
console.log(moderate_data)
if (env.Disable_Dashboard=="true"){}else{
if (env.img_url=="true"){}else{
//add image to kv
await env.img_url.put(params.id, "",{
metadata: { ListType: "None", Label: moderate_data.rating_label,TimeStamp: time },
Expand Down

0 comments on commit 54ae9cf

Please sign in to comment.