Skip to content

Commit

Permalink
优化后端url存储
Browse files Browse the repository at this point in the history
  • Loading branch information
MarSeventh committed Sep 13, 2024
1 parent 8e8f68b commit 87c74f7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions functions/api/manage/block/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export async function onRequest(context) {
next, // used for middleware or to fetch assets
data, // arbitrary space for passing data between middlewares
} = context;
console.log(env)
console.log(params.id)
// 解码params.id
params.id = decodeURIComponent(params.id);

//read the metadata
const value = await env.img_url.getWithMetadata(params.id);
console.log(value)
//"metadata":{"TimeStamp":19876541,"ListType":"None","rating_label":"None"}

//change the metadata
value.metadata.ListType = "Block"
await env.img_url.put(params.id,"",{metadata: value.metadata});
Expand Down
3 changes: 3 additions & 0 deletions functions/api/manage/delete/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export async function onRequest(context) {
next, // used for middleware or to fetch assets
data, // arbitrary space for passing data between middlewares
} = context;
// 解码params.id
params.id = decodeURIComponent(params.id);

await env.img_url.delete(params.id);
const info = JSON.stringify(params.id);
return new Response(info);
Expand Down
8 changes: 4 additions & 4 deletions functions/api/manage/white/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export async function onRequest(context) {
next, // used for middleware or to fetch assets
data, // arbitrary space for passing data between middlewares
} = context;
console.log(env)
console.log(params.id)
// 解码params.id
params.id = decodeURIComponent(params.id);

//read the metadata
const value = await env.img_url.getWithMetadata(params.id);
console.log(value)
//"metadata":{"TimeStamp":19876541,"ListType":"None","rating_label":"None"}

//change the metadata
value.metadata.ListType = "White"
await env.img_url.put(params.id,"",{metadata: value.metadata});
Expand Down
4 changes: 3 additions & 1 deletion functions/file/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export async function onRequest(context) { // Contents of context object
next, // used for middleware or to fetch assets
data, // arbitrary space for passing data between middlewares
} = context;

// 解码params.id
params.id = decodeURIComponent(params.id);

const url = new URL(request.url);
let Referer = request.headers.get('Referer')
if (Referer) {
Expand Down
4 changes: 2 additions & 2 deletions functions/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export async function onRequestPost(context) { // Contents of context object
const apikey = env.ModerateContentApiKey;

if (apikey == undefined || apikey == null || apikey == "") {
await env.img_url.put(encodedFullId, "", {
await env.img_url.put(fullId, "", {
metadata: { FileName: fileName, FileType: fileType, ListType: "None", Label: "None", TimeStamp: time, Channel: "TelegramNew", TgFilePath: filePath, TgFileId: id },
});
} else {
Expand All @@ -173,7 +173,7 @@ export async function onRequestPost(context) { // Contents of context object
throw new Error(`HTTP error! status: ${fetchResponse.status}`);
}
const moderate_data = await fetchResponse.json();
await env.img_url.put(encodedFullId, "", {
await env.img_url.put(fullId, "", {
metadata: { FileName: fileName, FileType: fileType, ListType: "None", Label: moderate_data.rating_label, TimeStamp: time, Channel: "TelegramNew", TgFilePath: filePath, TgFileId: id },
});
} catch (error) {
Expand Down

0 comments on commit 87c74f7

Please sign in to comment.