Skip to content
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

后台优化(音频上传/音视频卡片/黑白名单/优化代码结构) #210

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

Conversation

DJChanahCJD
Copy link
Contributor

@DJChanahCJD DJChanahCJD commented Dec 8, 2024

主要功能更新

  • upload.js添加了audio的判断,支持音频/文件上传
  • file/[id].js优化后台判定,Refer 包含/admin前缀的请求(如admin-imgtc、admin-waterfall)直接返回文件
  • 为不同类型文件 (视频/音频/文档) 定制专属卡片样式,支持顶栏切换文件类型
  • metadata中添加了fileName,默认显示原始文件名,支持重命名(新增一个了 editName API)
  • 搜索功能终于有用了,且兼容之前的文件(支持name或fileName)
  • 支持黑白名单的批量添加以及收藏、黑白名单、NSFW(rating_label="adult")的筛选
  • 添加快捷方式按钮,支持自定义外链
  • 其他
    • 将样式单独分离出一个CSS文件 admin-tc.css
    • 将功能整合进对应的下拉菜单,支持检测失效文件/全选当前页/批量下载/展示文件详情(需点击文件名)
    • 优化了部分代码结构,将类似的函数集中起来,方便维护
    • 取消了上传文件类型的判定,调整了支持上传的文件大小限制 (5MB->20MB)

👀其实超过20MB的文件也能成功上传到TG,但是TG bot getFile API 似乎最大只支持20MB的分发,因此无法返回可访问的路径,后台也无法显示。(如果能解决的话就完美了)

可能的参考:php - How can Downloading a big fIle from Telegram bot API - Stack Overflow(蹲...)

尝试解决图片压缩(<=10MB)、高宽比(<=20)、高宽和(<=10000)的问题,但受限于Worker环境无法实现。telegram-api sendphoto
已解决:上传图片时增加错误重传机制(自动将接口改为sendDocument
考虑添加一个KV键uploadPublic,用于自定义是否开放上传接口

界面预览

视频界面
image

音频界面
image

文件界面
image

@xyTom xyTom requested a review from Copilot December 12, 2024 12:18

Choose a reason for hiding this comment

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no suggestions.

Comments skipped due to low confidence (2)

functions/api/manage/editName/[id].js:11

  • Check if value is null or undefined before accessing value.metadata. Suggestion: if (!value || !value.metadata) return new Response(Image metadata not found for ID: ${params.id}, { status: 404 });
if (!value.metadata) return new Response(`Image metadata not found for ID: ${params.id}`, { status: 404 });

functions/upload.js:108

  • Use optional chaining to simplify the code and make it more readable.
if (result.audio) return result.audio.file_id;
@xyTom xyTom requested a review from Copilot December 14, 2024 14:37

Choose a reason for hiding this comment

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

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

Comments suppressed due to low confidence (5)

functions/api/manage/editName/[id].js:11

  • [nitpick] The error message could be more descriptive. Consider including additional context, such as 'Metadata not found for image ID: ' + params.id.
if (!value.metadata) return new Response(`Image metadata not found for ID: ${params.id}`, { status: 404 });

functions/upload.js:54

  • The variable 'fileExtension' is used without being defined. Ensure 'fileExtension' is properly set before using it.
await env.img_url.put(`${fileId}.${fileExtension}`, "", {

functions/upload.js:60

  • The variable 'fileName' should be properly set before using it in the metadata.
fileName: fileName,

functions/upload.js:46

  • [nitpick] The error message 'Failed to get file ID' could be more descriptive to help with debugging.
const fileId = getFileId(result.data);

functions/file/[id].js:51

  • [nitpick] The metadata initialization is redundant. Consolidate the metadata properties to avoid setting them multiple times.
let record = await env.img_url.getWithMetadata(params.id);
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.

1 participant