mirror of
https://github.com/Physton/sd-webui-prompt-all-in-one.git
synced 2026-01-26 19:29:56 +00:00
Merge pull request #355 from PTCMode/main
[fix] 解决一个可能导致启动失败的问题 & 解决firefox下提示词框体显示问题的样式方案
This commit is contained in:
@@ -57,7 +57,6 @@ except Exception as e:
|
|||||||
|
|
||||||
|
|
||||||
def on_app_started(_: gr.Blocks, app: FastAPI):
|
def on_app_started(_: gr.Blocks, app: FastAPI):
|
||||||
st = Storage()
|
|
||||||
hi = History()
|
hi = History()
|
||||||
|
|
||||||
@app.get("/physton_prompt/get_version")
|
@app.get("/physton_prompt/get_version")
|
||||||
@@ -109,7 +108,7 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||||||
|
|
||||||
@app.get("/physton_prompt/get_data")
|
@app.get("/physton_prompt/get_data")
|
||||||
async def _get_data(key: str):
|
async def _get_data(key: str):
|
||||||
data = st.get(key)
|
data = Storage.get(key)
|
||||||
data = privacy_translate_api_config(key, data)
|
data = privacy_translate_api_config(key, data)
|
||||||
return {"data": data}
|
return {"data": data}
|
||||||
|
|
||||||
@@ -118,7 +117,7 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||||||
keys = keys.split(',')
|
keys = keys.split(',')
|
||||||
datas = {}
|
datas = {}
|
||||||
for key in keys:
|
for key in keys:
|
||||||
datas[key] = st.get(key)
|
datas[key] = Storage.get(key)
|
||||||
datas[key] = privacy_translate_api_config(key, datas[key])
|
datas[key] = privacy_translate_api_config(key, datas[key])
|
||||||
return {"datas": datas}
|
return {"datas": datas}
|
||||||
|
|
||||||
@@ -130,7 +129,7 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||||||
if 'data' not in data:
|
if 'data' not in data:
|
||||||
return {"success": False, "message": get_lang('is_required', {'0': 'data'})}
|
return {"success": False, "message": get_lang('is_required', {'0': 'data'})}
|
||||||
data['data'] = unprotected_translate_api_config(data['key'], data['data'])
|
data['data'] = unprotected_translate_api_config(data['key'], data['data'])
|
||||||
st.set(data['key'], data['data'])
|
Storage.set(data['key'], data['data'])
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
@app.post("/physton_prompt/set_datas")
|
@app.post("/physton_prompt/set_datas")
|
||||||
@@ -140,12 +139,12 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||||||
return {"success": False, "message": get_lang('is_not_dict', {'0': 'data'})}
|
return {"success": False, "message": get_lang('is_not_dict', {'0': 'data'})}
|
||||||
for key in data:
|
for key in data:
|
||||||
data[key] = unprotected_translate_api_config(key, data[key])
|
data[key] = unprotected_translate_api_config(key, data[key])
|
||||||
st.set(key, data[key])
|
Storage.set(key, data[key])
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
@app.get("/physton_prompt/get_data_list_item")
|
@app.get("/physton_prompt/get_data_list_item")
|
||||||
async def _get_data_list_item(key: str, index: int):
|
async def _get_data_list_item(key: str, index: int):
|
||||||
return {"item": st.list_get(key, index)}
|
return {"item": Storage.list_get(key, index)}
|
||||||
|
|
||||||
@app.post("/physton_prompt/push_data_list")
|
@app.post("/physton_prompt/push_data_list")
|
||||||
async def _push_data_list(request: Request):
|
async def _push_data_list(request: Request):
|
||||||
@@ -154,7 +153,7 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||||||
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
||||||
if 'item' not in data:
|
if 'item' not in data:
|
||||||
return {"success": False, "message": get_lang('is_required', {'0': 'item'})}
|
return {"success": False, "message": get_lang('is_required', {'0': 'item'})}
|
||||||
st.list_push(data['key'], data['item'])
|
Storage.list_push(data['key'], data['item'])
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
@app.post("/physton_prompt/pop_data_list")
|
@app.post("/physton_prompt/pop_data_list")
|
||||||
@@ -162,14 +161,14 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||||||
data = await request.json()
|
data = await request.json()
|
||||||
if 'key' not in data:
|
if 'key' not in data:
|
||||||
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
||||||
return {"success": True, 'item': st.list_pop(data['key'])}
|
return {"success": True, 'item': Storage.list_pop(data['key'])}
|
||||||
|
|
||||||
@app.post("/physton_prompt/shift_data_list")
|
@app.post("/physton_prompt/shift_data_list")
|
||||||
async def _shift_data_list(request: Request):
|
async def _shift_data_list(request: Request):
|
||||||
data = await request.json()
|
data = await request.json()
|
||||||
if 'key' not in data:
|
if 'key' not in data:
|
||||||
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
||||||
return {"success": True, 'item': st.list_shift(data['key'])}
|
return {"success": True, 'item': Storage.list_shift(data['key'])}
|
||||||
|
|
||||||
@app.post("/physton_prompt/remove_data_list")
|
@app.post("/physton_prompt/remove_data_list")
|
||||||
async def _remove_data_list(request: Request):
|
async def _remove_data_list(request: Request):
|
||||||
@@ -178,7 +177,7 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||||||
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
||||||
if 'index' not in data:
|
if 'index' not in data:
|
||||||
return {"success": False, "message": get_lang('is_required', {'0': 'index'})}
|
return {"success": False, "message": get_lang('is_required', {'0': 'index'})}
|
||||||
st.list_remove(data['key'], data['index'])
|
Storage.list_remove(data['key'], data['index'])
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
@app.post("/physton_prompt/clear_data_list")
|
@app.post("/physton_prompt/clear_data_list")
|
||||||
@@ -186,7 +185,7 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||||||
data = await request.json()
|
data = await request.json()
|
||||||
if 'key' not in data:
|
if 'key' not in data:
|
||||||
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
return {"success": False, "message": get_lang('is_required', {'0': 'key'})}
|
||||||
st.list_clear(data['key'])
|
Storage.list_clear(data['key'])
|
||||||
return {"success": True}
|
return {"success": True}
|
||||||
|
|
||||||
@app.get("/physton_prompt/get_histories")
|
@app.get("/physton_prompt/get_histories")
|
||||||
@@ -395,7 +394,7 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
|||||||
return {"tags": get_group_tags(lang)}
|
return {"tags": get_group_tags(lang)}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
translate_api = st.get('translateApi')
|
translate_api = Storage.get('translateApi')
|
||||||
if translate_api == 'mbart50':
|
if translate_api == 'mbart50':
|
||||||
mbart50_initialize()
|
mbart50_initialize()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
from scripts.physton_prompt.storage import Storage
|
from scripts.physton_prompt.storage import Storage
|
||||||
|
|
||||||
storage = Storage()
|
|
||||||
from scripts.physton_prompt.get_i18n import get_i18n
|
from scripts.physton_prompt.get_i18n import get_i18n
|
||||||
|
|
||||||
|
|
||||||
@@ -12,7 +10,7 @@ def replace_vars(text, vars):
|
|||||||
|
|
||||||
def get_lang(key, vars={}):
|
def get_lang(key, vars={}):
|
||||||
i18n = get_i18n()
|
i18n = get_i18n()
|
||||||
code = storage.get('languageCode')
|
code = Storage.get('languageCode')
|
||||||
|
|
||||||
def find_lang(code):
|
def find_lang(code):
|
||||||
for item in i18n['languages']:
|
for item in i18n['languages']:
|
||||||
|
|||||||
@@ -2,17 +2,14 @@ import os
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
from scripts.physton_prompt.storage import Storage
|
from scripts.physton_prompt.storage import Storage
|
||||||
st = Storage()
|
|
||||||
|
|
||||||
# from scripts.physton_prompt.storage import Storage
|
# from scripts.physton_prompt.storage import Storage
|
||||||
|
|
||||||
translate_apis = {}
|
translate_apis = {}
|
||||||
|
|
||||||
|
|
||||||
# st = Storage()
|
|
||||||
def get_translate_apis(reload=False):
|
def get_translate_apis(reload=False):
|
||||||
global translate_apis
|
global translate_apis
|
||||||
global st
|
|
||||||
if reload or not translate_apis:
|
if reload or not translate_apis:
|
||||||
translate_apis = {}
|
translate_apis = {}
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -26,7 +23,7 @@ def get_translate_apis(reload=False):
|
|||||||
# if 'config' not in item:
|
# if 'config' not in item:
|
||||||
# continue
|
# continue
|
||||||
# config_name = 'translate_api.' + item['key']
|
# config_name = 'translate_api.' + item['key']
|
||||||
# config = st.get(config_name)
|
# config = Storage.get(config_name)
|
||||||
# if not config:
|
# if not config:
|
||||||
# config = {}
|
# config = {}
|
||||||
# for config_item in item['config']:
|
# for config_item in item['config']:
|
||||||
@@ -102,7 +99,7 @@ def unprotected_translate_api_config(data_key, data):
|
|||||||
if 'config' not in api_item or not api_item['config']:
|
if 'config' not in api_item or not api_item['config']:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
storage_data = st.get(data_key)
|
storage_data = Storage.get(data_key)
|
||||||
|
|
||||||
for config in api_item['config']:
|
for config in api_item['config']:
|
||||||
# 如果有 privacy 的属性并且为 True
|
# 如果有 privacy 的属性并且为 True
|
||||||
|
|||||||
@@ -17,26 +17,25 @@ class History:
|
|||||||
'img2img_neg': [],
|
'img2img_neg': [],
|
||||||
}
|
}
|
||||||
max = 100
|
max = 100
|
||||||
storage = Storage()
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
for type in self.histories:
|
for type in self.histories:
|
||||||
self.histories[type] = self.storage.get('history.' + type)
|
self.histories[type] = Storage.get('history.' + type)
|
||||||
if self.histories[type] is None:
|
if self.histories[type] is None:
|
||||||
self.histories[type] = []
|
self.histories[type] = []
|
||||||
self.__save_histories(type)
|
self.__save_histories(type)
|
||||||
|
|
||||||
for type in self.favorites:
|
for type in self.favorites:
|
||||||
self.favorites[type] = self.storage.get('favorite.' + type)
|
self.favorites[type] = Storage.get('favorite.' + type)
|
||||||
if self.favorites[type] is None:
|
if self.favorites[type] is None:
|
||||||
self.favorites[type] = []
|
self.favorites[type] = []
|
||||||
self.__save_favorites(type)
|
self.__save_favorites(type)
|
||||||
|
|
||||||
def __save_histories(self, type):
|
def __save_histories(self, type):
|
||||||
self.storage.set('history.' + type, self.histories[type])
|
Storage.set('history.' + type, self.histories[type])
|
||||||
|
|
||||||
def __save_favorites(self, type):
|
def __save_favorites(self, type):
|
||||||
self.storage.set('favorite.' + type, self.favorites[type])
|
Storage.set('favorite.' + type, self.favorites[type])
|
||||||
|
|
||||||
def get_histories(self, type):
|
def get_histories(self, type):
|
||||||
histories = self.histories[type]
|
histories = self.histories[type]
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
from pathlib import Path
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@@ -7,50 +6,62 @@ import time
|
|||||||
class Storage:
|
class Storage:
|
||||||
storage_path = ''
|
storage_path = ''
|
||||||
|
|
||||||
def __init__(self):
|
def __init__():
|
||||||
pass
|
Storage.__dispose_all_locks()
|
||||||
|
|
||||||
def __get_storage_path(self):
|
def __get_storage_path():
|
||||||
self.storage_path = os.path.dirname(os.path.abspath(__file__)) + '/../../storage'
|
Storage.storage_path = os.path.dirname(os.path.abspath(__file__)) + '/../../storage'
|
||||||
self.storage_path = os.path.normpath(self.storage_path)
|
Storage.storage_path = os.path.normpath(Storage.storage_path)
|
||||||
if not os.path.exists(self.storage_path):
|
if not os.path.exists(Storage.storage_path):
|
||||||
os.makedirs(self.storage_path)
|
os.makedirs(Storage.storage_path)
|
||||||
|
|
||||||
# old_storage_path = os.path.join(Path().absolute(), 'physton-prompt')
|
# old_storage_path = os.path.join(Path().absolute(), 'physton-prompt')
|
||||||
# if os.path.exists(old_storage_path):
|
# if os.path.exists(old_storage_path):
|
||||||
# # 复制就的存储文件到新的存储文件夹
|
# # 复制就的存储文件到新的存储文件夹
|
||||||
# for file in os.listdir(old_storage_path):
|
# for file in os.listdir(old_storage_path):
|
||||||
# old_file_path = os.path.join(old_storage_path, file)
|
# old_file_path = os.path.join(old_storage_path, file)
|
||||||
# new_file_path = os.path.join(self.storage_path, file)
|
# new_file_path = os.path.join(Storage.storage_path, file)
|
||||||
# if not os.path.exists(new_file_path):
|
# if not os.path.exists(new_file_path):
|
||||||
# os.rename(old_file_path, new_file_path)
|
# os.rename(old_file_path, new_file_path)
|
||||||
# # 删除旧的存储文件夹
|
# # 删除旧的存储文件夹
|
||||||
# os.rmdir(old_storage_path)
|
# os.rmdir(old_storage_path)
|
||||||
|
|
||||||
return self.storage_path
|
return Storage.storage_path
|
||||||
|
|
||||||
def __get_data_filename(self, key):
|
def __get_data_filename(key):
|
||||||
return self.__get_storage_path() + '/' + key + '.json'
|
return Storage.__get_storage_path() + '/' + key + '.json'
|
||||||
|
|
||||||
def __get_key_lock_filename(self, key):
|
def __get_key_lock_filename(key):
|
||||||
return self.__get_storage_path() + '/' + key + '.lock'
|
return Storage.__get_storage_path() + '/' + key + '.lock'
|
||||||
|
|
||||||
def __lock(self, key):
|
def __dispose_all_locks():
|
||||||
file_path = self.__get_key_lock_filename(key)
|
directory = Storage.__get_storage_path()
|
||||||
|
for filename in os.listdir(directory):
|
||||||
|
# 检查文件是否以指定后缀结尾
|
||||||
|
if filename.endswith('.lock'):
|
||||||
|
file_path = os.path.join(directory, filename)
|
||||||
|
try:
|
||||||
|
os.remove(file_path)
|
||||||
|
print(f"Disposed lock: {file_path}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Dispose lock {file_path} failed: {e}")
|
||||||
|
|
||||||
|
def __lock(key):
|
||||||
|
file_path = Storage.__get_key_lock_filename(key)
|
||||||
with open(file_path, 'w') as f:
|
with open(file_path, 'w') as f:
|
||||||
f.write('1')
|
f.write('1')
|
||||||
|
|
||||||
def __unlock(self, key):
|
def __unlock(key):
|
||||||
file_path = self.__get_key_lock_filename(key)
|
file_path = Storage.__get_key_lock_filename(key)
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
|
|
||||||
def __is_locked(self, key):
|
def __is_locked(key):
|
||||||
file_path = self.__get_key_lock_filename(key)
|
file_path = Storage.__get_key_lock_filename(key)
|
||||||
return os.path.exists(file_path)
|
return os.path.exists(file_path)
|
||||||
|
|
||||||
def __get(self, key):
|
def __get(key):
|
||||||
filename = self.__get_data_filename(key)
|
filename = Storage.__get_data_filename(key)
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
return None
|
return None
|
||||||
if os.path.getsize(filename) == 0:
|
if os.path.getsize(filename) == 0:
|
||||||
@@ -75,103 +86,103 @@ class Storage:
|
|||||||
return None
|
return None
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def __set(self, key, data):
|
def __set(key, data):
|
||||||
file_path = self.__get_data_filename(key)
|
file_path = Storage.__get_data_filename(key)
|
||||||
with open(file_path, 'w') as f:
|
with open(file_path, 'w') as f:
|
||||||
json.dump(data, f, indent=4, ensure_ascii=True)
|
json.dump(data, f, indent=4, ensure_ascii=True)
|
||||||
|
|
||||||
def set(self, key, data):
|
def set(key, data):
|
||||||
while self.__is_locked(key):
|
while Storage.__is_locked(key):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
self.__lock(key)
|
Storage.__lock(key)
|
||||||
try:
|
try:
|
||||||
self.__set(key, data)
|
Storage.__set(key, data)
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
def get(self, key):
|
def get(key):
|
||||||
return self.__get(key)
|
return Storage.__get(key)
|
||||||
|
|
||||||
def delete(self, key):
|
def delete(key):
|
||||||
file_path = self.__get_data_filename(key)
|
file_path = Storage.__get_data_filename(key)
|
||||||
if os.path.exists(file_path):
|
if os.path.exists(file_path):
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
|
|
||||||
def __get_list(self, key):
|
def __get_list(key):
|
||||||
data = self.get(key)
|
data = Storage.get(key)
|
||||||
if not data:
|
if not data:
|
||||||
data = []
|
data = []
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# 向列表中添加元素
|
# 向列表中添加元素
|
||||||
def list_push(self, key, item):
|
def list_push(key, item):
|
||||||
while self.__is_locked(key):
|
while Storage.__is_locked(key):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
self.__lock(key)
|
Storage.__lock(key)
|
||||||
try:
|
try:
|
||||||
data = self.__get_list(key)
|
data = Storage.__get_list(key)
|
||||||
data.append(item)
|
data.append(item)
|
||||||
self.__set(key, data)
|
Storage.__set(key, data)
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
# 从列表中删除和返回最后一个元素
|
# 从列表中删除和返回最后一个元素
|
||||||
def list_pop(self, key):
|
def list_pop(key):
|
||||||
while self.__is_locked(key):
|
while Storage.__is_locked(key):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
self.__lock(key)
|
Storage.__lock(key)
|
||||||
try:
|
try:
|
||||||
data = self.__get_list(key)
|
data = Storage.__get_list(key)
|
||||||
item = data.pop()
|
item = data.pop()
|
||||||
self.__set(key, data)
|
Storage.__set(key, data)
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
return item
|
return item
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
# 从列表中删除和返回第一个元素
|
# 从列表中删除和返回第一个元素
|
||||||
def list_shift(self, key):
|
def list_shift(key):
|
||||||
while self.__is_locked(key):
|
while Storage.__is_locked(key):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
self.__lock(key)
|
Storage.__lock(key)
|
||||||
try:
|
try:
|
||||||
data = self.__get_list(key)
|
data = Storage.__get_list(key)
|
||||||
item = data.pop(0)
|
item = data.pop(0)
|
||||||
self.__set(key, data)
|
Storage.__set(key, data)
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
return item
|
return item
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
# 从列表中删除指定元素
|
# 从列表中删除指定元素
|
||||||
def list_remove(self, key, index):
|
def list_remove(key, index):
|
||||||
while self.__is_locked(key):
|
while Storage.__is_locked(key):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
self.__lock(key)
|
Storage.__lock(key)
|
||||||
data = self.__get_list(key)
|
data = Storage.__get_list(key)
|
||||||
data.pop(index)
|
data.pop(index)
|
||||||
self.__set(key, data)
|
Storage.__set(key, data)
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
|
|
||||||
# 获取列表中指定位置的元素
|
# 获取列表中指定位置的元素
|
||||||
def list_get(self, key, index):
|
def list_get(key, index):
|
||||||
data = self.__get_list(key)
|
data = Storage.__get_list(key)
|
||||||
return data[index]
|
return data[index]
|
||||||
|
|
||||||
# 清空列表中的所有元素
|
# 清空列表中的所有元素
|
||||||
def list_clear(self, key):
|
def list_clear(key):
|
||||||
while self.__is_locked(key):
|
while Storage.__is_locked(key):
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
self.__lock(key)
|
Storage.__lock(key)
|
||||||
try:
|
try:
|
||||||
self.__set(key, [])
|
Storage.__set(key, [])
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.__unlock(key)
|
Storage.__unlock(key)
|
||||||
raise e
|
raise e
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from scripts.physton_prompt.storage import Storage
|
from scripts.physton_prompt.storage import Storage
|
||||||
|
|
||||||
storage = Storage()
|
|
||||||
|
|
||||||
styles_path = os.path.dirname(os.path.abspath(__file__)) + '/../../styles'
|
styles_path = os.path.dirname(os.path.abspath(__file__)) + '/../../styles'
|
||||||
styles_path = os.path.normpath(styles_path)
|
styles_path = os.path.normpath(styles_path)
|
||||||
@@ -58,7 +57,7 @@ def get_extension_css_list():
|
|||||||
'manifest': manifest,
|
'manifest': manifest,
|
||||||
'style': f'extensions/{dir}/style.min.css',
|
'style': f'extensions/{dir}/style.min.css',
|
||||||
}
|
}
|
||||||
css_item['selected'] = storage.get(css_item['dataName'])
|
css_item['selected'] = Storage.get(css_item['dataName'])
|
||||||
css_list.append(css_item)
|
css_list.append(css_item)
|
||||||
|
|
||||||
return css_list
|
return css_list
|
||||||
|
|||||||
8
styles/extensions/firefox-fix/manifest.json
Normal file
8
styles/extensions/firefox-fix/manifest.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "Temporary fix for issues caused by css in Firefox.",
|
||||||
|
"i18n": {
|
||||||
|
"zh_CN": "临时修复Firefox中css导致的问题"
|
||||||
|
},
|
||||||
|
"author": "PTCMode",
|
||||||
|
"type": "enhance"
|
||||||
|
}
|
||||||
26
styles/extensions/firefox-fix/style.less
Normal file
26
styles/extensions/firefox-fix/style.less
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
.physton-prompt {
|
||||||
|
.prompt-tags {
|
||||||
|
.prompt-tags-list {
|
||||||
|
.prompt-tag {
|
||||||
|
.prompt-tag-main {
|
||||||
|
--pp-pt-dsb-ptl-pt-promptTagMain-width: calc(100% + 4px);
|
||||||
|
.prompt-tag-edit {
|
||||||
|
--pp-pt-dsb-ptl-pt-ptm-promptTagEdit-width: calc(100% + 8px);
|
||||||
|
.prompt-tag-value {
|
||||||
|
--pp-pt-dsb-ptl-pt-ptm-pte-promptTagValue-width: calc(100% - 8px);
|
||||||
|
.character {
|
||||||
|
--pp-pt-dsb-ptl-pt-ptm-pte-ptv-character-white-space: nowrap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.input-tag-edit {
|
||||||
|
--pp-pt-dsb-ptl-pt-ptm-pte-inputTagEdit-max-width: calc(100% - 8px);
|
||||||
|
}
|
||||||
|
.btn-tag-delete {
|
||||||
|
--pp-pt-dsb-ptl-pt-ptm-pte-btnTagDelete-width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
styles/extensions/firefox-fix/style.min.css
vendored
Normal file
1
styles/extensions/firefox-fix/style.min.css
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.physton-prompt{.prompt-tags{.prompt-tags-list{.prompt-tag{.prompt-tag-main{--pp-pt-dsb-ptl-pt-promptTagMain-width:calc(100%+4px);.prompt-tag-edit{--pp-pt-dsb-ptl-pt-ptm-promptTagEdit-width:calc(100%+8px);.prompt-tag-value{--pp-pt-dsb-ptl-pt-ptm-pte-promptTagValue-width:calc(100%-8px);.character{--pp-pt-dsb-ptl-pt-ptm-pte-ptv-character-white-space:nowrap;}}.input-tag-edit{--pp-pt-dsb-ptl-pt-ptm-pte-inputTagEdit-max-width:calc(100%-8px);}.btn-tag-delete{--pp-pt-dsb-ptl-pt-ptm-pte-btnTagDelete-width:100%;}}}}}}}
|
||||||
@@ -3,9 +3,8 @@ import sys
|
|||||||
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
||||||
from scripts.physton_prompt.storage import Storage
|
from scripts.physton_prompt.storage import Storage
|
||||||
from scripts.physton_prompt.get_translate_apis import privacy_translate_api_config, unprotected_translate_api_config
|
from scripts.physton_prompt.get_translate_apis import privacy_translate_api_config, unprotected_translate_api_config
|
||||||
st = Storage()
|
|
||||||
key = 'translate_api.volcengine'
|
key = 'translate_api.volcengine'
|
||||||
data = st.get(key)
|
data = Storage.get(key)
|
||||||
data = privacy_translate_api_config(key, data)
|
data = privacy_translate_api_config(key, data)
|
||||||
print(data)
|
print(data)
|
||||||
data = unprotected_translate_api_config(key, data)
|
data = unprotected_translate_api_config(key, data)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from scripts.physton_prompt.get_translate_apis import get_translate_apis
|
|||||||
from scripts.physton_prompt.storage import Storage
|
from scripts.physton_prompt.storage import Storage
|
||||||
|
|
||||||
i18n = get_i18n()
|
i18n = get_i18n()
|
||||||
st = Storage()
|
|
||||||
text = 'Hello World, I am a boy'
|
text = 'Hello World, I am a boy'
|
||||||
|
|
||||||
tested_file = os.path.join(os.path.dirname(__file__), 'tested.json')
|
tested_file = os.path.join(os.path.dirname(__file__), 'tested.json')
|
||||||
@@ -37,7 +36,7 @@ def add_tested(api_key, from_lang, to_lang, translated_text):
|
|||||||
def test_api(api):
|
def test_api(api):
|
||||||
print(f"开始测试 {api['name']}")
|
print(f"开始测试 {api['name']}")
|
||||||
config_name = 'translate_api.' + api['key']
|
config_name = 'translate_api.' + api['key']
|
||||||
config = st.get(config_name)
|
config = Storage.get(config_name)
|
||||||
if not config:
|
if not config:
|
||||||
config = {}
|
config = {}
|
||||||
for lang_code in api['support']:
|
for lang_code in api['support']:
|
||||||
|
|||||||
Reference in New Issue
Block a user