From e6494bb7be3ce85a0e6db2435d75b8a54dcc9f79 Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:06:41 +0800 Subject: [PATCH 01/12] Update [id].js --- functions/file/[id].js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/functions/file/[id].js b/functions/file/[id].js index 48f8f586d..601b33e1e 100644 --- a/functions/file/[id].js +++ b/functions/file/[id].js @@ -34,11 +34,20 @@ export async function onRequest(context) { // Log response details console.log(response.ok, response.status); + // 获取文件扩展名 + const fileExtension = url.pathname.split('.').pop().toLowerCase(); + + // 创建新的Response对象,添加正确的Content-Type + const newResponse = new Response(response.body, response); + const contentType = getContentType(fileExtension); + newResponse.headers.set('Content-Type', contentType); + newResponse.headers.set('Content-Disposition', 'inline'); + // If the response is OK, proceed with further checks if (response.ok) { // Allow the admin page to directly view the image if (request.headers.get('Referer') === `${url.origin}/admin`) { - return response; + return newResponse; } // Fetch KV metadata if available @@ -57,7 +66,7 @@ export async function onRequest(context) { // Handle based on ListType and Label if (metadata.ListType === "White") { - return response; + return newResponse; } else if (metadata.ListType === "Block" || metadata.Label === "adult") { const referer = request.headers.get('Referer'); const redirectUrl = referer ? "https://static-res.pages.dev/teleimage/img-block-compressed.png" : `${url.origin}/block-img.html`; @@ -101,8 +110,7 @@ export async function onRequest(context) { } } - return response; - + return newResponse; } async function getFilePath(env, file_id) { @@ -130,4 +138,19 @@ async function getFilePath(env, file_id) { console.error('Error fetching file path:', error.message); return null; } -} \ No newline at end of file +} + +// 添加getContentType辅助函数 +function getContentType(extension) { + const contentTypes = { + 'png': 'image/png', + 'jpg': 'image/jpeg', + 'jpeg': 'image/jpeg', + 'gif': 'image/gif', + 'webp': 'image/webp', + 'svg': 'image/svg+xml', + 'ico': 'image/x-icon', + 'bmp': 'image/bmp' + }; + return contentTypes[extension] || 'application/octet-stream'; +} From 287218dac1f07a61944ed7d7f4b2eaff1b5ea1ff Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:36:22 +0800 Subject: [PATCH 02/12] Update [id].js --- functions/file/[id].js | 106 +++++++++++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 19 deletions(-) diff --git a/functions/file/[id].js b/functions/file/[id].js index 601b33e1e..a7a5fd357 100644 --- a/functions/file/[id].js +++ b/functions/file/[id].js @@ -6,23 +6,36 @@ export async function onRequest(context) { } = context; const url = new URL(request.url); - let fileUrl = 'https://telegra.ph/' + url.pathname + url.search - if (url.pathname.length > 39) { + let fileUrl = 'https://telegra.ph/' + url.pathname + url.search; + let originalId = params.id; + + // 检查是否是短链接格式(6位字符) + if (originalId.length === 6) { + // 从KV中获取原始ID + if (env.img_url) { + const originalData = await env.img_url.get(`short_${originalId}`); + if (originalData) { + originalId = originalData; + } + } + } + + if (originalId.length > 39) { const formdata = new FormData(); - formdata.append("file_id", url.pathname); + formdata.append("file_id", originalId); const requestOptions = { method: "POST", body: formdata, redirect: "follow" }; - // /file/AgACAgEAAxkDAAMDZt1Gzs4W8dQPWiQJxO5YSH5X-gsAAt-sMRuWNelGOSaEM_9lHHgBAAMCAANtAAM2BA.png - //get the AgACAgEAAxkDAAMDZt1Gzs4W8dQPWiQJxO5YSH5X-gsAAt-sMRuWNelGOSaEM_9lHHgBAAMCAANtAAM2BA - console.log(url.pathname.split(".")[0].split("/")[2]) - const filePath = await getFilePath(env, url.pathname.split(".")[0].split("/")[2]); - console.log(filePath) - fileUrl = `https://api.telegram.org/file/bot${env.TG_Bot_Token}/${filePath}`; - + + console.log(originalId.split(".")[0]); + const filePath = await getFilePath(env, originalId.split(".")[0]); + console.log(filePath); + if (filePath) { + fileUrl = `https://api.telegram.org/file/bot${env.TG_Bot_Token}/${filePath}`; + } } const response = await fetch(fileUrl, { @@ -35,7 +48,7 @@ export async function onRequest(context) { console.log(response.ok, response.status); // 获取文件扩展名 - const fileExtension = url.pathname.split('.').pop().toLowerCase(); + const fileExtension = originalId.split('.').pop().toLowerCase(); // 创建新的Response对象,添加正确的Content-Type const newResponse = new Response(response.body, response); @@ -52,16 +65,37 @@ export async function onRequest(context) { // Fetch KV metadata if available if (env.img_url) { - const record = await env.img_url.getWithMetadata(params.id); + const record = await env.img_url.getWithMetadata(originalId); console.log("Record:", record); + // 如果是新的长链接,创建短链接 + if (originalId.length > 39 && (!record || !record.metadata || !record.metadata.shortId)) { + const shortId = generateShortId(); + const metadata = record && record.metadata ? record.metadata : { + ListType: "None", + Label: "None", + TimeStamp: Date.now(), + liked: false + }; + + // 保存短链接映射 + await env.img_url.put(`short_${shortId}`, originalId); + + // 更新原始记录,添加shortId + metadata.shortId = shortId; + await env.img_url.put(originalId, "", { + metadata: metadata + }); + } + // Ensure metadata exists and add default values for missing properties if (record && record.metadata) { const metadata = { ListType: record.metadata.ListType || "None", Label: record.metadata.Label || "None", TimeStamp: record.metadata.TimeStamp || Date.now(), - liked: record.metadata.liked !== undefined ? record.metadata.liked : false + liked: record.metadata.liked !== undefined ? record.metadata.liked : false, + shortId: record.metadata.shortId }; // Handle based on ListType and Label @@ -79,8 +113,16 @@ export async function onRequest(context) { } } else { // If metadata does not exist, initialize it in KV with default values - await env.img_url.put(params.id, "", { - metadata: { ListType: "None", Label: "None", TimeStamp: Date.now(), liked: false }, + const shortId = generateShortId(); + await env.img_url.put(`short_${shortId}`, originalId); + await env.img_url.put(originalId, "", { + metadata: { + ListType: "None", + Label: "None", + TimeStamp: Date.now(), + liked: false, + shortId: shortId + }, }); } } @@ -93,8 +135,16 @@ export async function onRequest(context) { console.log("Moderate Data:", moderateData); if (env.img_url) { - await env.img_url.put(params.id, "", { - metadata: { ListType: "None", Label: moderateData.rating_label, TimeStamp: time, liked: false }, + const shortId = generateShortId(); + await env.img_url.put(`short_${shortId}`, originalId); + await env.img_url.put(originalId, "", { + metadata: { + ListType: "None", + Label: moderateData.rating_label, + TimeStamp: time, + liked: false, + shortId: shortId + }, }); } @@ -104,8 +154,16 @@ export async function onRequest(context) { } else if (env.img_url) { // Add image to KV with default metadata if ModerateContentApiKey is not available console.log("KV not enabled for moderation, adding default metadata."); - await env.img_url.put(params.id, "", { - metadata: { ListType: "None", Label: "None", TimeStamp: time, liked: false }, + const shortId = generateShortId(); + await env.img_url.put(`short_${shortId}`, originalId); + await env.img_url.put(originalId, "", { + metadata: { + ListType: "None", + Label: "None", + TimeStamp: time, + liked: false, + shortId: shortId + }, }); } } @@ -154,3 +212,13 @@ function getContentType(extension) { }; return contentTypes[extension] || 'application/octet-stream'; } + +// 生成6位短链接ID +function generateShortId() { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let result = ''; + for (let i = 0; i < 6; i++) { + result += chars.charAt(Math.floor(Math.random() * chars.length)); + } + return result; +} From d1152323d8f814fa79bc0f4f2d282725e97c8fea Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:37:08 +0800 Subject: [PATCH 03/12] Update upload.js --- functions/upload.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/functions/upload.js b/functions/upload.js index bfc72fde5..78168517e 100644 --- a/functions/upload.js +++ b/functions/upload.js @@ -4,7 +4,6 @@ export async function onRequestPost(context) { const { request, env } = context; try { - const clonedRequest = request.clone(); const formData = await clonedRequest.formData(); @@ -58,8 +57,27 @@ export async function onRequestPost(context) { throw new Error('Failed to get file ID'); } + // 生成短链接ID + const shortId = generateShortId(); + const longId = `${fileId}.${fileExtension}`; + + // 保存短链接映射到KV + if (env.img_url) { + await env.img_url.put(`short_${shortId}`, longId); + await env.img_url.put(longId, "", { + metadata: { + ListType: "None", + Label: "None", + TimeStamp: Date.now(), + liked: false, + shortId: shortId + }, + }); + } + + // 返回短链接 return new Response( - JSON.stringify([{ 'src': `/file/${fileId}.${fileExtension}` }]), + JSON.stringify([{ 'src': `/file/${shortId}` }]), { status: 200, headers: { 'Content-Type': 'application/json' } @@ -91,3 +109,13 @@ function getFileId(response) { return null; } + +// 生成6位短链接ID +function generateShortId() { + const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let result = ''; + for (let i = 0; i < 6; i++) { + result += chars.charAt(Math.floor(Math.random() * chars.length)); + } + return result; +} From 744137cb2d60bf8f8d8d5e9683f42ee61497ee4c Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:45:40 +0800 Subject: [PATCH 04/12] Update upload.js --- functions/upload.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/functions/upload.js b/functions/upload.js index 78168517e..74703c2ec 100644 --- a/functions/upload.js +++ b/functions/upload.js @@ -63,21 +63,29 @@ export async function onRequestPost(context) { // 保存短链接映射到KV if (env.img_url) { + // 保存短链接到长链接的映射 await env.img_url.put(`short_${shortId}`, longId); + + // 保存长链接的元数据,包含短链接信息 await env.img_url.put(longId, "", { metadata: { ListType: "None", Label: "None", TimeStamp: Date.now(), liked: false, - shortId: shortId + shortId: shortId, + originalId: longId // 添加原始ID信息 }, }); } - // 返回短链接 + // 返回包含长短链接的响应 return new Response( - JSON.stringify([{ 'src': `/file/${shortId}` }]), + JSON.stringify([{ + 'src': `/file/${shortId}`, + 'originalSrc': `/file/${longId}`, + 'shortId': shortId + }]), { status: 200, headers: { 'Content-Type': 'application/json' } From 6abc7343c462ca9cbdc91310715fd7ef8d0c3bea Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:46:10 +0800 Subject: [PATCH 05/12] Update [id].js --- functions/file/[id].js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/functions/file/[id].js b/functions/file/[id].js index a7a5fd357..31574a0a6 100644 --- a/functions/file/[id].js +++ b/functions/file/[id].js @@ -8,9 +8,11 @@ export async function onRequest(context) { const url = new URL(request.url); let fileUrl = 'https://telegra.ph/' + url.pathname + url.search; let originalId = params.id; + let isShortLink = false; // 检查是否是短链接格式(6位字符) if (originalId.length === 6) { + isShortLink = true; // 从KV中获取原始ID if (env.img_url) { const originalData = await env.img_url.get(`short_${originalId}`); @@ -69,7 +71,7 @@ export async function onRequest(context) { console.log("Record:", record); // 如果是新的长链接,创建短链接 - if (originalId.length > 39 && (!record || !record.metadata || !record.metadata.shortId)) { + if (!isShortLink && originalId.length > 39 && (!record || !record.metadata || !record.metadata.shortId)) { const shortId = generateShortId(); const metadata = record && record.metadata ? record.metadata : { ListType: "None", @@ -81,8 +83,9 @@ export async function onRequest(context) { // 保存短链接映射 await env.img_url.put(`short_${shortId}`, originalId); - // 更新原始记录,添加shortId + // 更新原始记录,添加shortId和originalId metadata.shortId = shortId; + metadata.originalId = originalId; await env.img_url.put(originalId, "", { metadata: metadata }); @@ -95,7 +98,8 @@ export async function onRequest(context) { Label: record.metadata.Label || "None", TimeStamp: record.metadata.TimeStamp || Date.now(), liked: record.metadata.liked !== undefined ? record.metadata.liked : false, - shortId: record.metadata.shortId + shortId: record.metadata.shortId, + originalId: record.metadata.originalId || originalId }; // Handle based on ListType and Label @@ -121,7 +125,8 @@ export async function onRequest(context) { Label: "None", TimeStamp: Date.now(), liked: false, - shortId: shortId + shortId: shortId, + originalId: originalId }, }); } @@ -143,7 +148,8 @@ export async function onRequest(context) { Label: moderateData.rating_label, TimeStamp: time, liked: false, - shortId: shortId + shortId: shortId, + originalId: originalId }, }); } @@ -162,7 +168,8 @@ export async function onRequest(context) { Label: "None", TimeStamp: time, liked: false, - shortId: shortId + shortId: shortId, + originalId: originalId }, }); } From 3dacfc5318a88f9cbb87b91b6cbd8e939986345a Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:50:35 +0800 Subject: [PATCH 06/12] Update [id].js --- functions/file/[id].js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/functions/file/[id].js b/functions/file/[id].js index 31574a0a6..a7a5fd357 100644 --- a/functions/file/[id].js +++ b/functions/file/[id].js @@ -8,11 +8,9 @@ export async function onRequest(context) { const url = new URL(request.url); let fileUrl = 'https://telegra.ph/' + url.pathname + url.search; let originalId = params.id; - let isShortLink = false; // 检查是否是短链接格式(6位字符) if (originalId.length === 6) { - isShortLink = true; // 从KV中获取原始ID if (env.img_url) { const originalData = await env.img_url.get(`short_${originalId}`); @@ -71,7 +69,7 @@ export async function onRequest(context) { console.log("Record:", record); // 如果是新的长链接,创建短链接 - if (!isShortLink && originalId.length > 39 && (!record || !record.metadata || !record.metadata.shortId)) { + if (originalId.length > 39 && (!record || !record.metadata || !record.metadata.shortId)) { const shortId = generateShortId(); const metadata = record && record.metadata ? record.metadata : { ListType: "None", @@ -83,9 +81,8 @@ export async function onRequest(context) { // 保存短链接映射 await env.img_url.put(`short_${shortId}`, originalId); - // 更新原始记录,添加shortId和originalId + // 更新原始记录,添加shortId metadata.shortId = shortId; - metadata.originalId = originalId; await env.img_url.put(originalId, "", { metadata: metadata }); @@ -98,8 +95,7 @@ export async function onRequest(context) { Label: record.metadata.Label || "None", TimeStamp: record.metadata.TimeStamp || Date.now(), liked: record.metadata.liked !== undefined ? record.metadata.liked : false, - shortId: record.metadata.shortId, - originalId: record.metadata.originalId || originalId + shortId: record.metadata.shortId }; // Handle based on ListType and Label @@ -125,8 +121,7 @@ export async function onRequest(context) { Label: "None", TimeStamp: Date.now(), liked: false, - shortId: shortId, - originalId: originalId + shortId: shortId }, }); } @@ -148,8 +143,7 @@ export async function onRequest(context) { Label: moderateData.rating_label, TimeStamp: time, liked: false, - shortId: shortId, - originalId: originalId + shortId: shortId }, }); } @@ -168,8 +162,7 @@ export async function onRequest(context) { Label: "None", TimeStamp: time, liked: false, - shortId: shortId, - originalId: originalId + shortId: shortId }, }); } From 144abadca98c067aa167deceea542d635a35e2af Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 16:52:08 +0800 Subject: [PATCH 07/12] Update [id].js From 4fe23584b453723d89a4e0c930eefdbe088f7c54 Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 17:07:18 +0800 Subject: [PATCH 08/12] Update [id].js --- functions/file/[id].js | 58 +++++++++++++----------------------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/functions/file/[id].js b/functions/file/[id].js index a7a5fd357..40b859464 100644 --- a/functions/file/[id].js +++ b/functions/file/[id].js @@ -69,20 +69,20 @@ export async function onRequest(context) { console.log("Record:", record); // 如果是新的长链接,创建短链接 - if (originalId.length > 39 && (!record || !record.metadata || !record.metadata.shortId)) { + if (originalId.length > 39 && (!record || !record.metadata)) { const shortId = generateShortId(); - const metadata = record && record.metadata ? record.metadata : { + const metadata = { ListType: "None", Label: "None", TimeStamp: Date.now(), - liked: false + liked: false, + shortId: shortId }; // 保存短链接映射 await env.img_url.put(`short_${shortId}`, originalId); - // 更新原始记录,添加shortId - metadata.shortId = shortId; + // 更新原始记录 await env.img_url.put(originalId, "", { metadata: metadata }); @@ -111,19 +111,6 @@ export async function onRequest(context) { if (env.WhiteList_Mode === "true") { return Response.redirect(`${url.origin}/whitelist-on.html`, 302); } - } else { - // If metadata does not exist, initialize it in KV with default values - const shortId = generateShortId(); - await env.img_url.put(`short_${shortId}`, originalId); - await env.img_url.put(originalId, "", { - metadata: { - ListType: "None", - Label: "None", - TimeStamp: Date.now(), - liked: false, - shortId: shortId - }, - }); } } @@ -135,36 +122,25 @@ export async function onRequest(context) { console.log("Moderate Data:", moderateData); if (env.img_url) { - const shortId = generateShortId(); - await env.img_url.put(`short_${shortId}`, originalId); + // 获取现有记录 + const record = await env.img_url.getWithMetadata(originalId); + const metadata = record && record.metadata ? record.metadata : { + ListType: "None", + TimeStamp: time, + liked: false + }; + + // 更新Label但保留其他元数据 + metadata.Label = moderateData.rating_label; + await env.img_url.put(originalId, "", { - metadata: { - ListType: "None", - Label: moderateData.rating_label, - TimeStamp: time, - liked: false, - shortId: shortId - }, + metadata: metadata }); } if (moderateData.rating_label === "adult") { return Response.redirect(`${url.origin}/block-img.html`, 302); } - } else if (env.img_url) { - // Add image to KV with default metadata if ModerateContentApiKey is not available - console.log("KV not enabled for moderation, adding default metadata."); - const shortId = generateShortId(); - await env.img_url.put(`short_${shortId}`, originalId); - await env.img_url.put(originalId, "", { - metadata: { - ListType: "None", - Label: "None", - TimeStamp: time, - liked: false, - shortId: shortId - }, - }); } } From 271dc4a07e3e657c03884c0ef5968643e077d73a Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 17:14:23 +0800 Subject: [PATCH 09/12] Update upload.js --- functions/upload.js | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/functions/upload.js b/functions/upload.js index 74703c2ec..6b6461e56 100644 --- a/functions/upload.js +++ b/functions/upload.js @@ -61,31 +61,22 @@ export async function onRequestPost(context) { const shortId = generateShortId(); const longId = `${fileId}.${fileExtension}`; - // 保存短链接映射到KV + // 只存储原始记录,在metadata中包含shortId if (env.img_url) { - // 保存短链接到长链接的映射 - await env.img_url.put(`short_${shortId}`, longId); - - // 保存长链接的元数据,包含短链接信息 await env.img_url.put(longId, "", { metadata: { ListType: "None", Label: "None", TimeStamp: Date.now(), liked: false, - shortId: shortId, - originalId: longId // 添加原始ID信息 + shortId: shortId }, }); } - // 返回包含长短链接的响应 + // 返回短链接 return new Response( - JSON.stringify([{ - 'src': `/file/${shortId}`, - 'originalSrc': `/file/${longId}`, - 'shortId': shortId - }]), + JSON.stringify([{ 'src': `/file/${shortId}` }]), { status: 200, headers: { 'Content-Type': 'application/json' } From 0cca73abb8ec6aaef6cf5816a7078c587db3b85e Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 17:14:56 +0800 Subject: [PATCH 10/12] Update [id].js --- functions/file/[id].js | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/functions/file/[id].js b/functions/file/[id].js index 40b859464..1ed8b8ffe 100644 --- a/functions/file/[id].js +++ b/functions/file/[id].js @@ -11,11 +11,17 @@ export async function onRequest(context) { // 检查是否是短链接格式(6位字符) if (originalId.length === 6) { - // 从KV中获取原始ID + // 从KV中查找原始ID if (env.img_url) { - const originalData = await env.img_url.get(`short_${originalId}`); - if (originalData) { - originalId = originalData; + // 列出所有KV记录 + const kvList = await env.img_url.list(); + // 遍历查找匹配的shortId + for (const key of kvList.keys) { + const record = await env.img_url.getWithMetadata(key.name); + if (record && record.metadata && record.metadata.shortId === originalId) { + originalId = key.name; + break; + } } } } @@ -68,26 +74,6 @@ export async function onRequest(context) { const record = await env.img_url.getWithMetadata(originalId); console.log("Record:", record); - // 如果是新的长链接,创建短链接 - if (originalId.length > 39 && (!record || !record.metadata)) { - const shortId = generateShortId(); - const metadata = { - ListType: "None", - Label: "None", - TimeStamp: Date.now(), - liked: false, - shortId: shortId - }; - - // 保存短链接映射 - await env.img_url.put(`short_${shortId}`, originalId); - - // 更新原始记录 - await env.img_url.put(originalId, "", { - metadata: metadata - }); - } - // Ensure metadata exists and add default values for missing properties if (record && record.metadata) { const metadata = { From 6c998636b416790997ae043b3d1e8645994106ac Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 17:27:42 +0800 Subject: [PATCH 11/12] Update admin.html --- admin.html | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/admin.html b/admin.html index 943e84e04..a6105a918 100644 --- a/admin.html +++ b/admin.html @@ -19,6 +19,30 @@ .el-button+.el-button { margin: 0; } + + .json-viewer { + background-color: #f5f7fa; + padding: 10px; + border-radius: 4px; + font-family: monospace; + white-space: pre-wrap; + } + + .json-key { + color: #409EFF; + } + + .json-string { + color: #67C23A; + } + + .json-number { + color: #E6A23C; + } + + .json-boolean { + color: #F56C6C; + } @@ -89,10 +113,16 @@ @@ -205,8 +235,15 @@ handleLogout() { window.location.href = "./api/manage/logout"; }, + formatMetadata(metadata) { + if (!metadata) return ''; + const date = new Date(metadata.TimeStamp); + return `${metadata.ListType} | ${metadata.Label} | ${date.toLocaleString()}`; + }, handleCopy(index, key) { - const text = `${document.location.origin}/file/${key}`; + // 使用metadata中的shortId而不是原始key + const shortId = this.tableData[index].metadata.shortId; + const text = `${document.location.origin}/file/${shortId}`; if (navigator.clipboard) { // clipboard api 复制 navigator.clipboard.writeText(text); @@ -227,7 +264,7 @@ document.body.removeChild(textarea); } this.$message({ - message: '复制文件链接成功~', + message: '复制短链接成功~', type: 'success' }); }, @@ -310,4 +347,4 @@ })(window, document, "clarity", "script", "7t5ai7agat"); - \ No newline at end of file + From 85840d84cc16761a9a25f60738a9112e8c5b1e20 Mon Sep 17 00:00:00 2001 From: wyksean448 <153080750+wyksean448@users.noreply.github.com> Date: Mon, 27 Jan 2025 17:32:19 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin.html | 121 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 79 insertions(+), 42 deletions(-) diff --git a/admin.html b/admin.html index a6105a918..6cca565ee 100644 --- a/admin.html +++ b/admin.html @@ -97,48 +97,61 @@ --> @@ -159,6 +172,8 @@ BlackList: 0, showLogoutButton: false, tableData: [], + currentPage: 1, + pageSize: 10, dialogFormVisible: false, formLabelWidth: '120px', form: { @@ -168,7 +183,29 @@ search: '', password: '123456' }, + computed: { + // 根据搜索条件过滤数据 + filteredTableData() { + return this.tableData.filter(data => + !this.search || data.name.toLowerCase().includes(this.search.toLowerCase()) + ); + }, + // 根据当前页码和每页条数计算分页数据 + paginatedData() { + const start = (this.currentPage - 1) * this.pageSize; + const end = start + this.pageSize; + return this.filteredTableData.slice(start, end); + } + }, methods: { + // 添加分页方法 + handleSizeChange(val) { + this.pageSize = val; + this.currentPage = 1; // 重置到第一页 + }, + handleCurrentChange(val) { + this.currentPage = val; + }, handleBlock(index, key) { console.log(key); if (confirm("确认加入黑名单吗?")) {