From 5690e76d7d712930df239def220dfc528f2c7977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=9B=AA=E5=B3=B0?= Date: Tue, 16 Apr 2024 14:44:53 +0800 Subject: [PATCH] support github mirror --- easyapi/mirrorUrlApply.py | 7 + static/js/easyapi.js | 309 +++++++++++++++++++++++--------------- 2 files changed, 198 insertions(+), 118 deletions(-) diff --git a/easyapi/mirrorUrlApply.py b/easyapi/mirrorUrlApply.py index ba1dc79..e7c6021 100644 --- a/easyapi/mirrorUrlApply.py +++ b/easyapi/mirrorUrlApply.py @@ -16,6 +16,13 @@ mirror_url = [ "n_url": "None", "u_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0", }, + { + "id": "github", + "o_url": "github.com", + # "n_url": "mirror.ghproxy.com/https://github.com" + "n_url": "None", + "u_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0", + }, ] diff --git a/static/js/easyapi.js b/static/js/easyapi.js index ec4b666..de79a7f 100644 --- a/static/js/easyapi.js +++ b/static/js/easyapi.js @@ -5,124 +5,12 @@ import { debounce } from "./debounce.js" app.registerExtension({ name: "Comfy.EasyApi.Setting", async setup(app) { - const changeFun = debounce((n, o) => api.fetchApi("/easyapi/history/size", { - method: 'POST', - headers: { - "content-type": "application/json", - }, - body: JSON.stringify({ - maxSize: n - }) - }), 1000, false) - app.ui.settings.addSetting({ - id: "Easyapi.SizeOfHistory", - name: "[EasyApi] Maximum History Size", - defaultValue: 10000, - type: "slider", - attrs: { - min: 1, - max: 10000, - step: 1, - }, - onChange: (newVal, oldVal) => { - changeFun.apply(null, [newVal, oldVal]) - } - }); - const changeFun1 = debounce((n, o) => api.fetchApi("/easyapi/settings/huggingface_mirror", { - method: 'POST', - headers: { - "content-type": "application/json", - }, - body: JSON.stringify({ - huggingface_mirror: n - }) - }), 1000, false) - app.ui.settings.addSetting({ - id: "Easyapi.MirrorSet.huggingface", - name: "[EasyApi] Huggingface Mirror", - tooltip: "Will replace host huggingface.co", - defaultValue: "None", - type: "combo", - options: [ - { - value: "None", - text: "None" - }, - { - value: "hf-mirror.com", - text: "hf-mirror.com" - } - ], + this.add_history_setting(app); + this.add_github_mirror_setting(app); + this.add_rawgithub_mirror_setting(app); + this.add_huggingface_mirror_setting(app); - onChange: (newVal, oldVal) => { - changeFun1.apply(null, [newVal, oldVal]) - } - }); - - const changeFun2 = debounce((n, o) => api.fetchApi("/easyapi/settings/rawgithub_mirror", { - method: 'POST', - headers: { - "content-type": "application/json", - }, - body: JSON.stringify({ - rawgithub_mirror: n - }) - }), 1000, false) - app.ui.settings.addSetting({ - id: "Easyapi.MirrorSet.rawgithub", - name: "[EasyApi] RawGithub Mirror", - defaultValue: "None", - tooltip: "Will replace host raw.githubusercontent.com", - type: "combo", - options: [ - { - value: "None", - text: "None" - }, - { - value: "raw.gitmirror.com", - text: "gitmirror.com" - }, - { - value: "mirror.ghproxy.com/https://raw.githubusercontent.com", - text: "mirror.ghproxy.com" - }, - { - value: "ghproxy.net/https://raw.githubusercontent.com", - text: "ghproxy.net" - }, - { - value: "ghproxy.org/https://raw.githubusercontent.com", - text: "ghproxy.org" - }, - { - value: "gh-proxy.com/https://raw.githubusercontent.com", - text: "gh-proxy.com" - }, - { - value: "mirrors.chenby.cn/https://raw.githubusercontent.com", - text: "mirrors.chenby.cn" - }, - { - value: "521github.com/extdomains/raw.githubusercontent.com", - text: "521github.com" - }, - { - value: "gh.ddlc.top/https://raw.githubusercontent.com", - text: "gh.ddlc.top" - }, - { - value: "github.moeyy.xyz/https://raw.githubusercontent.com", - text: "github.moeyy.xyz" - } - ], - - onChange: (newVal, oldVal) => { - changeFun2.apply(null, [newVal, oldVal]) - } - }); - - const ctxMenu = LiteGraph.ContextMenu; + const ctxMenu = LiteGraph.ContextMenu; const replace = () => { LiteGraph.ContextMenu = function (values, options) { options = options || {}; @@ -153,7 +41,192 @@ app.registerExtension({ LiteGraph.search_fuzzy_match = value; }, }); - } + }, + add_history_setting: function (app) { + const changeFun = debounce((n, o) => api.fetchApi("/easyapi/history/size", { + method: 'POST', + headers: { + "content-type": "application/json", + }, + body: JSON.stringify({ + maxSize: n + }) + }), 1000, false) + app.ui.settings.addSetting({ + id: "Easyapi.SizeOfHistory", + name: "[EasyApi] Maximum History Size", + defaultValue: 10000, + type: "slider", + attrs: { + min: 1, + max: 10000, + step: 1, + }, + onChange: (newVal, oldVal) => { + changeFun.apply(null, [newVal, oldVal]) + } + }); + }, + add_github_mirror_setting: function (app) { + const changeFun = debounce((n, o) => api.fetchApi("/easyapi/settings/github_mirror", { + method: 'POST', + headers: { + "content-type": "application/json", + }, + body: JSON.stringify({ + github_mirror: n + }) + }), 1000, false) + app.ui.settings.addSetting({ + id: "Easyapi.MirrorSet.github", + name: "[EasyApi] Github Mirror", + defaultValue: "None", + tooltip: "Will replace host github.com. Suitable of download some models from github.com.", + type: "combo", + options: [ + { + value: "None", + text: "None" + }, + { + value: "hub.gitmirror.com/https://github.com", + text: "gitmirror.com" + }, + { + value: "mirror.ghproxy.com/https://github.com", + text: "mirror.ghproxy.com" + }, + { + value: "ghproxy.net/https://github.com", + text: "ghproxy.net" + }, + { + value: "ghproxy.org/https://github.com", + text: "ghproxy.org" + }, + { + value: "gh-proxy.com/https://github.com", + text: "gh-proxy.com" + }, + { + value: "gh.ddlc.top/https://raw.githubusercontent.com", + text: "gh.ddlc.top" + }, + { + value: "mirrors.chenby.cn/https://github.com", + text: "mirrors.chenby.cn" + }, + { + value: "521github.com/extdomains/github.com", + text: "521github.com" + }, + { + value: "github.moeyy.xyz/https://raw.githubusercontent.com", + text: "github.moeyy.xyz" + } + ], + + onChange: (newVal, oldVal) => { + changeFun.apply(null, [newVal, oldVal]) + } + }); + }, + add_rawgithub_mirror_setting: function (app) { + const changeFun = debounce((n, o) => api.fetchApi("/easyapi/settings/rawgithub_mirror", { + method: 'POST', + headers: { + "content-type": "application/json", + }, + body: JSON.stringify({ + rawgithub_mirror: n + }) + }), 1000, false) + app.ui.settings.addSetting({ + id: "Easyapi.MirrorSet.rawgithub", + name: "[EasyApi] RawGithub Mirror", + defaultValue: "None", + tooltip: "Will replace host raw.githubusercontent.com", + type: "combo", + options: [ + { + value: "None", + text: "None" + }, + { + value: "raw.gitmirror.com", + text: "gitmirror.com" + }, + { + value: "mirror.ghproxy.com/https://raw.githubusercontent.com", + text: "mirror.ghproxy.com" + }, + { + value: "ghproxy.net/https://raw.githubusercontent.com", + text: "ghproxy.net" + }, + { + value: "ghproxy.org/https://raw.githubusercontent.com", + text: "ghproxy.org" + }, + { + value: "gh-proxy.com/https://raw.githubusercontent.com", + text: "gh-proxy.com" + }, + { + value: "mirrors.chenby.cn/https://raw.githubusercontent.com", + text: "mirrors.chenby.cn" + }, + { + value: "gh.ddlc.top/https://raw.githubusercontent.com", + text: "gh.ddlc.top" + }, + { + value: "521github.com/extdomains/raw.githubusercontent.com", + text: "521github.com" + }, + { + value: "github.moeyy.xyz/https://raw.githubusercontent.com", + text: "github.moeyy.xyz" + } + ], + + onChange: (newVal, oldVal) => { + changeFun.apply(null, [newVal, oldVal]) + } + }); + }, + add_huggingface_mirror_setting: function (app) { + const changeFun = debounce((n, o) => api.fetchApi("/easyapi/settings/huggingface_mirror", { + method: 'POST', + headers: { + "content-type": "application/json", + }, + body: JSON.stringify({ + huggingface_mirror: n + }) + }), 1000, false) + app.ui.settings.addSetting({ + id: "Easyapi.MirrorSet.huggingface", + name: "[EasyApi] Huggingface Mirror", + tooltip: "Will replace host huggingface.co", + defaultValue: "None", + type: "combo", + options: [ + { + value: "None", + text: "None" + }, + { + value: "hf-mirror.com", + text: "hf-mirror.com" + } + ], + + onChange: (newVal, oldVal) => { + changeFun.apply(null, [newVal, oldVal]) + } + }); + }, }) app.registerExtension({