-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
管理端支持拉黑上传ip;管理端批量操作支持按照用户选择的顺序进行;random接口优化
- Loading branch information
1 parent
6d0ecd1
commit 303a80f
Showing
61 changed files
with
282 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export async function onRequestPost(context) { | ||
// Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context; | ||
//从POST请求中获取authCode | ||
const jsonRequest = await request.json(); | ||
const authCode = jsonRequest.authCode; | ||
//验证authCode | ||
if (env.AUTH_CODE !== undefined && authCode !== env.AUTH_CODE) { | ||
return new Response('Unauthorized', { status: 401 }) | ||
} | ||
//返回登录成功 | ||
return new Response('Login success', { status: 200 }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export async function onRequest(context) { | ||
// Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context; | ||
try { | ||
// 检查是否配置了KV数据库 | ||
if (typeof env.img_url == "undefined" || env.img_url == null || env.img_url == "") { | ||
return new Response('Error: Please configure KV database', { status: 500 }); | ||
} | ||
|
||
const kv = env.img_url; | ||
let list = await kv.get("manage@blockipList"); | ||
if (list == null) { | ||
list = []; | ||
} else { | ||
list = list.split(","); | ||
} | ||
|
||
//从请求body中获取要block的ip | ||
const ip = await request.text(); | ||
if (ip == null || ip == "") { | ||
return new Response('Error: Please input ip', { status: 400 }); | ||
} | ||
|
||
//将ip添加到list中 | ||
list.push(ip); | ||
await kv.put("manage@blockipList", list.join(",")); | ||
return new Response('Add ip to block list successfully', { status: 200 }); | ||
} catch (e) { | ||
return new Response('Add ip to block list failed', { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export async function onRequest(context) { | ||
// Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context; | ||
try { | ||
// 检查是否配置了KV数据库 | ||
if (typeof env.img_url == "undefined" || env.img_url == null || env.img_url == "") { | ||
return new Response('Error: Please configure KV database', { status: 500 }); | ||
} | ||
|
||
const kv = env.img_url; | ||
const list = await kv.get("manage@blockipList"); | ||
if (list == null) { | ||
return new Response('', { status: 200 }); | ||
} else { | ||
return new Response(list, { status: 200 }); | ||
} | ||
} catch (e) { | ||
return new Response('fetch block ip list failed', { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
export async function onRequest(context) { | ||
// Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context; | ||
try { | ||
// 检查是否配置了KV数据库 | ||
if (typeof env.img_url == "undefined" || env.img_url == null || env.img_url == "") { | ||
return new Response('Error: Please configure KV database', { status: 500 }); | ||
} | ||
|
||
const kv = env.img_url; | ||
let list = await kv.get("manage@blockipList"); | ||
if (list == null) { | ||
list = []; | ||
} else { | ||
list = list.split(","); | ||
} | ||
|
||
//从请求body中获取要white的ip | ||
const ip = await request.text(); | ||
if (ip == null || ip == "") { | ||
return new Response('Error: Please input ip', { status: 400 }); | ||
} | ||
|
||
//将ip从list中删除 | ||
list = list.filter(item => item !== ip); | ||
await kv.put("manage@blockipList", list.join(",")); | ||
return new Response('delete ip from block ip list successfully', { status: 200 }); | ||
} catch (e) { | ||
return new Response('delete ip from block ip list failed', { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
export async function onRequest(context) { | ||
// Contents of context object | ||
const { | ||
request, // same as existing Worker API | ||
env, // same as existing Worker API | ||
params, // if filename includes [id] or [[path]] | ||
waitUntil, // same as ctx.waitUntil in existing Worker API | ||
next, // used for middleware or to fetch assets | ||
data, // arbitrary space for passing data between middlewares | ||
} = context; | ||
|
||
// 检查是否启用了随机图功能 | ||
if (env.AllowRandom != "true") { | ||
return new Response(JSON.stringify({ error: "Random is disabled" }), { status: 403 }); | ||
} | ||
|
||
// 检查是否配置了KV数据库 | ||
if (typeof env.img_url == "undefined" || env.img_url == null || env.img_url == "") { | ||
return new Response('Error: Please configure KV database', { status: 500 }); | ||
} | ||
|
||
let allRecords = []; | ||
let cursor = null; | ||
|
||
do { | ||
const records = await env.img_url.list({ | ||
limit: 1000, | ||
cursor, | ||
}); | ||
// 除去records中key以manage@开头的记录 | ||
records.keys = records.keys.filter(item => !item.name.startsWith("manage@")); | ||
// 保留metadata中fileType为image或video的记录 | ||
records.keys = records.keys.filter(item => item.metadata?.FileType?.includes("image") || item.metadata?.FileType?.includes("video")); | ||
allRecords.push(...records.keys); | ||
cursor = records.cursor; | ||
} while (cursor); | ||
|
||
// 仅保留记录的name和metadata中的FileType字段 | ||
allRecords = allRecords.map(item => { | ||
return { | ||
name: item.name, | ||
FileType: item.metadata?.FileType | ||
} | ||
}); | ||
|
||
// 返回所有记录,设置缓存时间为1天 | ||
const info = JSON.stringify(allRecords); | ||
return new Response(info, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Cache-Control": "public, max-age=86400", | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.