Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

[Feature Request] 自己造图床 #432

Closed
2 tasks done
langningchen opened this issue Sep 17, 2023 · 79 comments · Fixed by #583
Closed
2 tasks done

[Feature Request] 自己造图床 #432

langningchen opened this issue Sep 17, 2023 · 79 comments · Fixed by #583
Assignees
Labels
enhancement New feature or request GitHub-related Issues or pull requests related to this GitHub repo's config priority-low This has low priority server This issue or pull request is related to server-side code user-script This issue or pull request is related to the main user script
Milestone

Comments

@langningchen
Copy link
Owner

检查项

  • 我已确认了XMOJ增强脚本已为最新版,且最新版未实现这一功能。
  • 我已在 Issues 页面 中搜索,确认了这一提案未被提交过。

描述

使用 GitHub 私有仓库 + Cloudflare Workers ,参考 这篇 文章

原因

No response

@langningchen langningchen added enhancement New feature or request GitHub-related Issues or pull requests related to this GitHub repo's config priority-low This has low priority server This issue or pull request is related to server-side code labels Sep 17, 2023
@langningchen langningchen added this to the v1.0.* milestone Sep 17, 2023
@langningchen langningchen self-assigned this Sep 17, 2023
@boomzero
Copy link
Collaborator

@langningchen SEO修好了!

@boomzero
Copy link
Collaborator

seo

@PythonSmall-Q
Copy link
Collaborator

可以用团队的repo @langningchen 物尽其用

@langningchen
Copy link
Owner Author

@PythonSmall-Q 原来不是试过了不太行吗?好像对于权限管理不太好弄

@langningchen
Copy link
Owner Author

@boomzero @PythonSmall-Q 你们到时候可别去 Cloudflare 后台偷我的 PAT 啊!不过我也只给 repo 权限 😆

@boomzero
Copy link
Collaborator

@boomzero @PythonSmall-Q 你们到时候可别去 Cloudflare 后台偷我的 PAT 啊!不过我也只给 repo 权限 😆

别提醒我

@langningchen
Copy link
Owner Author

langningchen commented Sep 23, 2023

好麻烦啊!Workers流量的问题、GitHub权限的问题、JS前端事件触发的问题……让我不想继续了

@github-actions github-actions bot added the wontfix This will not be worked on label Sep 23, 2023
@boomzero
Copy link
Collaborator

好麻烦啊!Workers流量的问题、GitHub权限的问题、JS前端事件触发的问题……让我不想继续了

考虑Cloudflare R2?

@boomzero
Copy link
Collaborator

但是没有credit card, 而且免费额度可能不够

@boomzero
Copy link
Collaborator

或者iframe 洛谷图床

@langningchen
Copy link
Owner Author

langningchen commented Sep 23, 2023

@boomzero 最主要的是JS前端事件触发的问题

@github-actions github-actions bot added user-script This issue or pull request is related to the main user script and removed wontfix This will not be worked on labels Sep 23, 2023
@langningchen
Copy link
Owner Author

langningchen commented Sep 24, 2023

@boomzero 帮我解决一下JS前端事件触发的问题

@github-actions github-actions bot added the help-wanted Extra attention is needed label Sep 24, 2023
@boomzero
Copy link
Collaborator

boomzero commented Sep 24, 2023 via email

@langningchen
Copy link
Owner Author

@boomzero 就是按了 Ctrl+V 无法触发 onpaste 事件

@langningchen
Copy link
Owner Author

右键点粘贴也不行

@PythonSmall-Q
Copy link
Collaborator

这个actions太贴心了qaq

@PythonSmall-Q
Copy link
Collaborator

有点被他暖到(不是

@boomzero
Copy link
Collaborator

@langningchen 我没有code啊

@boomzero
Copy link
Collaborator

神奇

@langningchen
Copy link
Owner Author

@langningchen
Copy link
Owner Author

不过获取到的不太对

@langningchen
Copy link
Owner Author

我说过了:#432 (comment)

@langningchen
Copy link
Owner Author

我检查过, GitHub Rest API 返回的内容没有错,是用 Curl 检查的

curl "https://api.github.com/repos/langningchen/XMOJ-Script-Pictures/contents/rptzrfmpxufetajrvzeccnwqlsesbgmp" \
    -H"Authorization: Bearer ***" \
    -H"User-Agent: XMOJ-Script-Server" \
    -H"Accept: application/vnd.github.raw" \
    --output /mnt/c/Users/jpxx_/OneDrive/Desktop/API.png
diff /mnt/c/Users/jpxx_/OneDrive/Desktop/Raw.png /mnt/c/Users/jpxx_/OneDrive/Desktop/API.png

@langningchen
Copy link
Owner Author

所以不是上传的错误

@langningchen
Copy link
Owner Author

我又试了试不用 Curl ,用 JS 的 Fetch

let ImageData = await fetch(new URL("https://api.github.com/repos/langningchen/XMOJ-Script-Pictures/contents/ggqzbaghexjxuzwyzvteioeejlouqtcw"), {
    method: "GET",
    headers: {
        "Authorization": "Bearer ***",
        "Accept": "application/vnd.github.text",
        "User-Agent": "XMOJ-Script-Server"
    }
}).then((Response) => {
    return Response.text();
});
let a = document.createElement("a");
a.href = URL.createObjectURL(new Blob([ImageData], { type: "image/png" }));
a.download = "Fetch.png";
a.click();
diff Error.png Fetch.png

结果发现 Fetch 得到的和错误的一样,所以 我误会了 CloudFlare , 原来是 Fetch 的问题

@langningchen
Copy link
Owner Author

langningchen commented Oct 2, 2023

有人说是 text 的问题,应该要用 Blob ,但是还是不对

image

@langningchen
Copy link
Owner Author

现在准备用 XMLHttpRequest

@langningchen
Copy link
Owner Author

还是不行……

@PythonSmall-Q
Copy link
Collaborator

加油做模拟赛!

@PythonSmall-Q
Copy link
Collaborator

我看你们二老还没交题欸~

@langningchen
Copy link
Owner Author

我看你们二老还没交题欸~

@PythonSmall-Q 确实

@langningchen
Copy link
Owner Author

langningchen commented Oct 2, 2023

上面是正确的,下面是用 fetch 和 GitHub API 获取到的,发现有些字符被替换为了 FFFD

image

@langningchen
Copy link
Owner Author

用 Curl 和 Github API 获取到的是对的,和正确的一样,但是使用 fetch 或者 XMLHttpRequest 获取到的就有个别字符是错的,是不是字符编码的问题?

@PythonSmall-Q
Copy link
Collaborator

我看你们二老还没交题欸~

@PythonSmall-Q 确实

做了点题,结果发现状态不在都做不出来qwq

@langningchen
Copy link
Owner Author

@PythonSmall-Q 那就来帮我解决问题吧

@langningchen
Copy link
Owner Author

langningchen commented Oct 2, 2023

经查询, U+FFFD 是替换字符,表示UTF-8中没有对应的字符,显示为黑色的菱形和一个问号

@langningchen
Copy link
Owner Author

@boomzero @PythonSmall-Q 有什么思路吗?我现在准备去网上问一问

@langningchen
Copy link
Owner Author

langningchen commented Oct 2, 2023

image

@langningchen
Copy link
Owner Author

@langningchen
Copy link
Owner Author

langningchen commented Oct 2, 2023

@boomzero @PythonSmall-Q Horray!

image

@langningchen
Copy link
Owner Author

langningchen commented Oct 2, 2023

StackOverflow users give me the answer! 🎉

@langningchen
Copy link
Owner Author

langningchen commented Oct 2, 2023

@boomzero @PythonSmall-Q 你们快去试试吧!

@github-actions github-actions bot removed the help-wanted Extra attention is needed label Oct 2, 2023
@langningchen langningchen linked a pull request Oct 2, 2023 that will close this issue
@github-actions github-actions bot deleted a comment from langningchen Oct 2, 2023
@github-actions github-actions bot removed the working-on-it Work in progess, please be patient label Oct 2, 2023
@boomzero
Copy link
Collaborator

boomzero commented Oct 2, 2023

@langningchen
Copy link
Owner Author

@boomzero 解决了,问题就删了

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request GitHub-related Issues or pull requests related to this GitHub repo's config priority-low This has low priority server This issue or pull request is related to server-side code user-script This issue or pull request is related to the main user script
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants