Skip to content

新增后台管理图片分页功能以及data数据的显示优化、新增url短链功能 #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

wyksean448
Copy link

No description provided.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@xyTom xyTom requested a review from Copilot February 23, 2025 10:21
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

functions/file/[id].js:80

  • [nitpick] Metadata keys such as 'ListType' and 'TimeStamp' use PascalCase. Consider using lowerCamelCase (e.g. listType, timestamp) to align with common JavaScript naming conventions.
                      ListType: record.metadata.ListType || "None",

functions/upload.js:67

  • [nitpick] Metadata keys such as 'ListType' and 'TimeStamp' use PascalCase; using lowerCamelCase (e.g. listType, timestamp) may improve consistency with JavaScript standards.
                metadata: { ListType: "None", Label: "None", TimeStamp: Date.now(), liked: false,

@cf-pages
Copy link
Owner

你好 @wyksean448,感谢你的PR!你的PR短链接功能看起来也很实用。目前有一些合并冲突需要解决,然后我们才能合并这个PR。

冲突解决

有两个文件存在冲突:

•	functions/file/[id].js
•	functions/upload.js

你需要解决这些冲突。以下是建议的解决方法:
对于 functions/file/[id].js:

// 保留短ID查找功能和改进的错误处理
if (originalId.length === 6) {
    // 你的短ID查找代码
} 

// 保留增强的元数据处理和正确的Content-Type头
const newResponse = new Response(response.body, response);
const contentType = getContentType(fileExtension);
newResponse.headers.set('Content-Type', contentType);

对于 functions/upload.js:

// 合并保存元数据的代码,同时包含短ID和文件信息
if (env.img_url) {
    await env.img_url.put(longId, "", {
        metadata: { 
            ListType: "None", 
            Label: "None", 
            TimeStamp: Date.now(), 
            liked: false,
            shortId: enableShortUrls ? shortId : null,
            fileName: fileName,
            fileSize: uploadFile.size
        },
    });
}

// 保留带有重试逻辑的sendToTelegram函数

功能建议

  1. 将短链接设为可选项:目前短链接总是被生成。考虑通过环境变量使此功能可配置:
// 在函数开始处
const enableShortUrls = env.ENABLE_SHORT_URLS === "true";

// 生成ID时
const shortId = enableShortUrls ? generateShortId() : null;
const longId = `${fileId}.${fileExtension}`;

// 在响应中
return new Response(
    JSON.stringify([{ 'src': enableShortUrls ? `/file/${shortId}` : `/file/${longId}` }]),
    {
        status: 200,
        headers: { 'Content-Type': 'application/json' }
    }
);
  1. 考虑短链接碰撞处理:我注意到代码生成随机的6字符ID(字符长度如果可以调整就更好了),但没有检查碰撞。考虑添加检查以确保唯一性(或者使用UUID):
// 检查shortId是否已存在于KV存储中
let isUnique = false;
let shortId;
while (!isUnique) {
    shortId = generateShortId();
    const existing = await env.img_url.list({ prefix: shortId });
    isUnique = existing.keys.length === 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants