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

[Feature] 添加一个新的 optifine 下载源 #2717

Open
zkitefly opened this issue Jan 31, 2024 · 13 comments · May be fixed by #2719
Open

[Feature] 添加一个新的 optifine 下载源 #2717

zkitefly opened this issue Jan 31, 2024 · 13 comments · May be fixed by #2719

Comments

@zkitefly
Copy link
Member

描述 | Description

RT,可以是解析 optifine.net html 页面,或者 optifine.cn 等

原因 | Reason

减少 bmclapi 的负担

@burningtnt
Copy link
Member

burningtnt commented Jan 31, 2024

能否使用 GitHub Action 定时拉取 OptiFine 的数据,并整合版本信息为 JSON?
信息站不提供文件本身的下载,只提供版本信息和 OptiFine 官方的下载链接

问题:站点如何托管?如何保证动态更新?

@zkitefly
Copy link
Member Author

zkitefly commented Jan 31, 2024

能否使用 GitHub Action 定时拉取 OptiFine 的数据,并整合版本信息为 JSON? 信息站不提供文件本身的下载,只提供版本信息和 OptiFine 官方的下载链接

问题:站点如何托管?如何保证动态更新?

应该可以

托管问题可以用 GitHub Page(例如 authlib-injector 官方下载站就是,还是不行就用 BMCLAPI 不就行了)

动态更新的话 GitHub Action 最短 5 分钟执行一次,应该够了

@burningtnt
Copy link
Member

burningtnt commented Jan 31, 2024

目前已部署 https://of-302.zkitefly.eu.org/ 这一 CloudFlare Worker,可通过 https://of-302.zkitefly.eu.org/file/<OptiFine File Name> 下载 OptiFine

原理:解析 OptiFine Mirror 界面,骗一个 Token 出来拼到下载链接

export default {
    /**
     * @param {Request} request
     * @param {Env} env
     * @param {ExecutionContext} ctx
     * @returns {Promise<Response>}
     */
    async fetch(request, env, ctx) {
        const url = new URL(request.url), prefix = "/file/";

        if (!url.pathname.startsWith(prefix) || url.pathname.indexOf("/", prefix.length) != -1) {
            return new Response(undefined, {
                "status": 404
            });
        }

        return fetch("https://optifine.net/adloadx?f=" + url.pathname.substring(prefix.length)).then(response => response.text()).then(text => {
            let start = text.indexOf("href='", text.indexOf("<div class=\"downloadButton\">")) + "href='".length;

            return new Response(undefined, {
                "status": 302,
                "headers": {
                    "Location": "https://optifine.net/" + text.substring(start, text.indexOf("'", start))
                }
            })
        })
    },
};

@ZekerZhayard
Copy link
Contributor

那怎么获得 optifine 的版本列表

@burningtnt
Copy link
Member

burningtnt commented Jan 31, 2024

那怎么获得 optifine 的版本列表

目前讨论下来,有两种方案:

  • 自己维护一个静态文件托管:如 https://zkitefly.github.io/optifine-download-list/index.json ,由 GitHub Action 从 BMCLAPI / GitHub 网页拉取构建
    问题:大概率只能托管到 HMCL-docs,会不会带来较大的压力?
  • 启动器直接请求 BMCLAPI:考虑到版本 JSON 很小,真正的大头是 OptiFine 本体(一个就 7MB),官方源时分流本体,就已经能极大的缓解 BMCLAPI 的压力了

不如投个票:方案一给这个消息一个 爱心 回复,方案二给这个消息一个 火箭回复

@zkitefly
Copy link
Member Author

那怎么获得 optifine 的版本列表

目前讨论下来,有两种方案:

  • 自己维护一个静态文件托管:如 https://zkitefly.github.io/optifine-download-list/index.json ,由 GitHub Action 从 BMCLAPI / GitHub 网页拉取构建
    问题:大概率只能托管到 HMCL-docs,会不会带来较大的压力?
  • 启动器直接请求 BMCLAPI:考虑到版本 JSON 很小,真正的大头是 OptiFine 本体(一个就 7MB),官方源时分流本体,就已经能极大的缓解 BMCLAPI 的压力了

不如投个票:方案一给这个消息一个 爱心 回复,方案二给这个消息一个 火箭回复

https://zkitefly.github.io/optifine-download-list/index.json 直接爬取 optifine.net

@zkitefly
Copy link
Member Author

zkitefly commented Jan 31, 2024

https://github.com/zkitefly/optifine-downloadfile-302

这个是可以使用 Vercel 进行解析的项目,Vercel 以 带宽 计费,免费版每月 100 GB,应该不限制请求数,对一个 API 来说再好不过了

https://of-302v.zkitefly.eu.org/file/

测试链接:https://of-302v.zkitefly.eu.org/file/preview_OptiFine_1.20.4_HD_U_I7_pre2.jar

@burningtnt
Copy link
Member

Verbal 和 Cloudflare Worker 哪个响应快?

@zkitefly
Copy link
Member Author

zkitefly commented Feb 1, 2024

Verbal 和 Cloudflare Worker 哪个响应快?

Vercel 更好点

@burningtnt burningtnt linked a pull request Feb 1, 2024 that will close this issue
@zkitefly
Copy link
Member Author

zkitefly commented Feb 1, 2024

基于上方代码修改。添加即将 302 的地址是否含为 200 状态码或是否含有 Content-Disposition 标头,若不是,则返回 404 File not found。添加缓存 fetch 结果,缓存五分钟。新增功能,若 OptiFine 官网无此文件,则跳转至 BMCLAPI 下载文件
https://gist.github.com/zkitefly/02debe936035d633113aa041797bc7a1

@burningtnt
Copy link
Member

burningtnt commented Feb 2, 2024

目前的问题及可能的解决方案

  • OptiFine 官方下载渠道不会保留所有文件
    与 BMCLAPI 合并,OF-302 服务器会在 OptiFine 找不到时导流到 BMCLAPI
  • 存在版权风险
    在页面提示上添加前往 OptiFine 手动下载支持 OptiFine 的提示

还需要进一步讨论

@zkitefly
Copy link
Member Author

zkitefly commented Feb 2, 2024

当前 index.json 中已含有官网没有但 BMCLAPI 拥有的文件列表

当前 optifine-downloadfile-302 增加了使用 BMCLAPI 下载的功能,如果请求的 filename 在 OptiFine 官网没有,会自动获取 BMCLAPI 的 OptiFine 列表并查找是否含有该 filename,若存在,则会返回 BMCLAPI 的下载地址;若不存在则 404。

@8MiYile
Copy link

8MiYile commented Feb 2, 2024

@burningtnt 请求下载optifine前 先请求optifine的广告 且告知用户()

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

Successfully merging a pull request may close this issue.

4 participants