mirror of
https://github.com/MarSeventh/CloudFlare-ImgBed.git
synced 2026-04-27 07:35:07 +00:00
优化文件url显示
This commit is contained in:
@@ -142,24 +142,29 @@ export async function onRequestPost(context) { // Contents of context object
|
||||
const clonedRes = await response.clone().json(); // 等待响应克隆和解析完成
|
||||
const fileInfo = getFile(clonedRes);
|
||||
const filePath = await getFilePath(env, fileInfo.file_id);
|
||||
|
||||
const time = new Date().getTime();
|
||||
const id = fileInfo.file_id;
|
||||
//const fullId = id + '.' + fileExt;
|
||||
// 构建独一无二的 ID
|
||||
const unique_index = time + Math.floor(Math.random() * 10000);
|
||||
const fullId = fileName? unique_index + '_' + fileName : unique_index + '.' + fileExt;
|
||||
const encodedFullId = encodeURIComponent(fullId);
|
||||
// 若上传成功,将响应返回给客户端
|
||||
if (response.ok) {
|
||||
res = new Response(
|
||||
JSON.stringify([{ 'src': `/file/${fileInfo.file_id}.${fileExt}` }]),
|
||||
JSON.stringify([{ 'src': `/file/${fullId}` }]),
|
||||
{
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
}
|
||||
);
|
||||
}
|
||||
const time = new Date().getTime();
|
||||
const id = fileInfo.file_id;
|
||||
const fullId = id + '.' + fileExt;
|
||||
const apikey = env.ModerateContentApiKey;
|
||||
|
||||
if (apikey == undefined || apikey == null || apikey == "") {
|
||||
await env.img_url.put(fullId, "", {
|
||||
metadata: { FileName: fileName, FileType: fileType, ListType: "None", Label: "None", TimeStamp: time, Channel: "Telegram", TgFilePath: filePath },
|
||||
await env.img_url.put(encodedFullId, "", {
|
||||
metadata: { FileName: fileName, FileType: fileType, ListType: "None", Label: "None", TimeStamp: time, Channel: "TelegramNew", TgFilePath: filePath, TgFileId: id },
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
@@ -168,8 +173,8 @@ 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(fullId, "", {
|
||||
metadata: { FileName: fileName, FileType: fileType, ListType: "None", Label: moderate_data.rating_label, TimeStamp: time, Channel: "Telegram", TgFilePath: filePath },
|
||||
await env.img_url.put(encodedFullId, "", {
|
||||
metadata: { FileName: fileName, FileType: fileType, ListType: "None", Label: moderate_data.rating_label, TimeStamp: time, Channel: "TelegramNew", TgFilePath: filePath, TgFileId: id },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Moderate Error:', error);
|
||||
|
||||
Reference in New Issue
Block a user