support rawgithub and hf mirror

This commit is contained in:
刘雪峰
2024-04-15 17:13:48 +08:00
parent 6780b59ca2
commit def2cb3b02
4 changed files with 124 additions and 35 deletions
+3
View File
@@ -76,6 +76,9 @@ Tips: base64格式字符串比较长,会导致界面卡顿,接口请求带
- 模糊搜索
配置路径:Settings -> [EasyApi] Fuzzy Search
![save api extended](docs/fuzzy_search.png)
- 使用镜像地址(模型自动下载问题)
- 配置路径:Settings -> [EasyApi] Huggingface Mirror
- 配置路径:Settings -> [EasyApi] RawGithub Mirror
- 菜单扩展
+3 -3
View File
@@ -2,7 +2,7 @@ import glob
import importlib.util
import sys
import os
from .easyapi import api, logScript
from .easyapi import api, logScript, mirrorUrlApply
extension_folder = os.path.dirname(os.path.realpath(__file__))
@@ -13,8 +13,8 @@ pyPath = os.path.join(extension_folder, 'easyapi')
# sys.path.append(extension_folder)
logScript.log_wrap()
# api.init()
api.init()
mirrorUrlApply.init()
def loadCustomNodes():
files = glob.glob(os.path.join(pyPath, "*Node.py"), recursive=True)
+22 -27
View File
@@ -1,5 +1,4 @@
import os
import json
import folder_paths
import nodes
@@ -8,6 +7,7 @@ from aiohttp import web
import execution
from simple_lama_inpainting import SimpleLama
from .util import image_to_base64, base64_to_image
from .settings import reset_history_size, get_settings, set_settings
extension_folder = os.path.dirname(os.path.realpath(__file__))
@@ -22,28 +22,6 @@ else:
os.makedirs(lama_model_dir, exist_ok=True)
def reset_history_size(max_size=execution.MAXIMUM_HISTORY_SIZE, isStart=False):
configDataFilePath = os.path.join(extension_folder, 'config')
if not os.path.exists(configDataFilePath):
os.mkdir(configDataFilePath)
configFile = os.path.join(configDataFilePath, "easyapi.json")
with open(configFile, 'w+', encoding="utf-8") as file:
json.dump({"history_max_size": max_size}, file, indent=2)
else:
configFile = os.path.join(configDataFilePath, "easyapi.json")
if not os.path.exists(configFile):
with open(configFile, 'w+', encoding="utf-8") as file:
json.dump({"history_max_size": max_size}, file, indent=2)
else:
with open(configFile, 'r+', encoding="UTF-8") as file:
data = json.load(file)
if not isStart:
data['history_max_size'] = max_size
with open(configFile, 'w+', encoding="UTF-8") as file:
json.dump(data, file, indent=2)
def register_routes():
@PromptServer.instance.routes.post("/easyapi/history/size")
async def set_history_size(request):
@@ -70,13 +48,30 @@ def register_routes():
@PromptServer.instance.routes.get("/easyapi/history/maxSize")
async def get_history_size(request):
maxSize = execution.MAXIMUM_HISTORY_SIZE
with open(os.path.join(extension_folder, 'config/easyapi.json'), 'r', encoding="UTF-8") as file:
data = json.load(file)
if data['history_max_size'] is not None:
maxSize = data['history_max_size']
data = get_settings(file='config/easyapi.json')
if 'history_max_size' in data:
maxSize = data['history_max_size']
return web.json_response({"maxSize": maxSize})
@PromptServer.instance.routes.post("/easyapi/settings/{id}")
async def set_setting(request):
setting_id = request.match_info.get("id", None)
if not setting_id:
return web.Response(status=400)
json_body = await request.json()
set_settings(setting_id, json_body[setting_id])
return web.Response(status=200)
@PromptServer.instance.routes.get("/easyapi/settings/{id}")
async def get_setting(request):
setting_id = request.match_info.get("id", None)
settings = get_settings(file='config/easyapi.json')
if settings and setting_id in settings:
return web.json_response({setting_id: settings[setting_id]})
return web.json_response({})
@PromptServer.instance.routes.post("/easyapi/prompt")
async def post_prompt(request):
print("got prompt")
+96 -5
View File
@@ -5,9 +5,6 @@ import { debounce } from "./debounce.js"
app.registerExtension({
name: "Comfy.EasyApi.Setting",
async setup(app) {
const res = await api.fetchApi("/easyapi/history/maxSize")
const jsonData = await res.json() || {};
const max = jsonData['maxSize'] || 10000
const changeFun = debounce((n, o) => api.fetchApi("/easyapi/history/size", {
method: 'POST',
headers: {
@@ -17,10 +14,10 @@ app.registerExtension({
maxSize: n
})
}), 1000, false)
const setting = app.ui.settings.addSetting({
app.ui.settings.addSetting({
id: "Easyapi.SizeOfHistory",
name: "[EasyApi] Maximum History Size",
defaultValue: max,
defaultValue: 10000,
type: "slider",
attrs: {
min: 1,
@@ -31,6 +28,100 @@ app.registerExtension({
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"
}
],
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 replace = () => {
LiteGraph.ContextMenu = function (values, options) {