mirror of
https://github.com/Physton/sd-webui-prompt-all-in-one.git
synced 2026-05-01 03:31:41 +00:00
#256 Sort Favorites option
This commit is contained in:
@@ -221,6 +221,24 @@ def on_app_started(_: gr.Blocks, app: FastAPI):
|
||||
hi.push_favorite(data['type'], data['tags'], data['prompt'], data.get('name', ''))
|
||||
return {"success": True}
|
||||
|
||||
@app.post("/physton_prompt/move_up_favorite")
|
||||
async def _move_up_favorite(request: Request):
|
||||
data = await request.json()
|
||||
if 'type' not in data:
|
||||
return {"success": False, "message": get_lang('is_required', {'0': 'type'})}
|
||||
if 'id' not in data:
|
||||
return {"success": False, "message": get_lang('is_required', {'0': 'id'})}
|
||||
return {"success": hi.move_up_favorite(data['type'], data['id'])}
|
||||
|
||||
@app.post("/physton_prompt/move_down_favorite")
|
||||
async def _move_down_favorite(request: Request):
|
||||
data = await request.json()
|
||||
if 'type' not in data:
|
||||
return {"success": False, "message": get_lang('is_required', {'0': 'type'})}
|
||||
if 'id' not in data:
|
||||
return {"success": False, "message": get_lang('is_required', {'0': 'id'})}
|
||||
return {"success": hi.move_down_favorite(data['type'], data['id'])}
|
||||
|
||||
@app.get("/physton_prompt/get_latest_history")
|
||||
async def _get_latest_history(type: str):
|
||||
return {"history": hi.get_latest_history(type)}
|
||||
|
||||
@@ -79,6 +79,26 @@ class History:
|
||||
self.__save_favorites(type)
|
||||
return item
|
||||
|
||||
def move_up_favorite(self, type, id):
|
||||
for index, favorite in enumerate(self.favorites[type]):
|
||||
if favorite['id'] == id:
|
||||
if index > 0:
|
||||
self.favorites[type].insert(index - 1, self.favorites[type].pop(index))
|
||||
self.__save_favorites(type)
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
||||
def move_down_favorite(self, type, id):
|
||||
for index, favorite in enumerate(self.favorites[type]):
|
||||
if favorite['id'] == id:
|
||||
if index < len(self.favorites[type]) - 1:
|
||||
self.favorites[type].insert(index + 1, self.favorites[type].pop(index))
|
||||
self.__save_favorites(type)
|
||||
return True
|
||||
return False
|
||||
return False
|
||||
|
||||
def get_latest_history(self, type):
|
||||
if len(self.histories[type]) > 0:
|
||||
return self.histories[type][-1]
|
||||
|
||||
Reference in New Issue
Block a user