mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
change from pin to star
This commit is contained in:
parent
08dc265e09
commit
80b0c5eab4
@ -286,3 +286,30 @@ async def delete_images_from_list(
|
|||||||
return DeleteImagesFromListResult(deleted_images=deleted_images)
|
return DeleteImagesFromListResult(deleted_images=deleted_images)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail="Failed to delete images")
|
raise HTTPException(status_code=500, detail="Failed to delete images")
|
||||||
|
|
||||||
|
|
||||||
|
@images_router.post("/star", operation_id="star_images_in_list")
|
||||||
|
async def star_images_in_list(
|
||||||
|
image_names: list[str] = Body(description="The list of names of images to star", embed=True),
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
for image_name in image_names:
|
||||||
|
try:
|
||||||
|
ApiDependencies.invoker.services.images.update(image_name, changes=ImageRecordChanges(starred=True))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=500, detail="Failed to star images")
|
||||||
|
|
||||||
|
@images_router.post("/unstar", operation_id="unstar_images_in_list")
|
||||||
|
async def unstar_images_in_list(
|
||||||
|
image_names: list[str] = Body(description="The list of names of images to unstar", embed=True),
|
||||||
|
):
|
||||||
|
try:
|
||||||
|
for image_name in image_names:
|
||||||
|
try:
|
||||||
|
ApiDependencies.invoker.services.images.update(image_name, changes=ImageRecordChanges(starred=False))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
except Exception as e:
|
||||||
|
raise HTTPException(status_code=500, detail="Failed to unstar images")
|
@ -67,7 +67,7 @@ IMAGE_DTO_COLS = ", ".join(
|
|||||||
"created_at",
|
"created_at",
|
||||||
"updated_at",
|
"updated_at",
|
||||||
"deleted_at",
|
"deleted_at",
|
||||||
"pinned"
|
"starred"
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -140,7 +140,7 @@ class ImageRecordStorageBase(ABC):
|
|||||||
node_id: Optional[str],
|
node_id: Optional[str],
|
||||||
metadata: Optional[dict],
|
metadata: Optional[dict],
|
||||||
is_intermediate: bool = False,
|
is_intermediate: bool = False,
|
||||||
pinned: bool = False
|
starred: bool = False
|
||||||
) -> datetime:
|
) -> datetime:
|
||||||
"""Saves an image record."""
|
"""Saves an image record."""
|
||||||
pass
|
pass
|
||||||
@ -205,10 +205,10 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
|
|||||||
self._cursor.execute("PRAGMA table_info(images)")
|
self._cursor.execute("PRAGMA table_info(images)")
|
||||||
columns = [column[1] for column in self._cursor.fetchall()]
|
columns = [column[1] for column in self._cursor.fetchall()]
|
||||||
|
|
||||||
if "pinned" not in columns:
|
if "starred" not in columns:
|
||||||
self._cursor.execute(
|
self._cursor.execute(
|
||||||
"""--sql
|
"""--sql
|
||||||
ALTER TABLE images ADD COLUMN pinned BOOLEAN DEFAULT FALSE;
|
ALTER TABLE images ADD COLUMN starred BOOLEAN DEFAULT FALSE;
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
|
|||||||
|
|
||||||
self._cursor.execute(
|
self._cursor.execute(
|
||||||
"""--sql
|
"""--sql
|
||||||
CREATE INDEX IF NOT EXISTS idx_images_pinned ON images(pinned);
|
CREATE INDEX IF NOT EXISTS idx_images_starred ON images(starred);
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -339,15 +339,15 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
|
|||||||
(changes.is_intermediate, image_name),
|
(changes.is_intermediate, image_name),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Change the image's `pinned`` state
|
# Change the image's `starred`` state
|
||||||
if changes.pinned is not None:
|
if changes.starred is not None:
|
||||||
self._cursor.execute(
|
self._cursor.execute(
|
||||||
f"""--sql
|
f"""--sql
|
||||||
UPDATE images
|
UPDATE images
|
||||||
SET pinned = ?
|
SET starred = ?
|
||||||
WHERE image_name = ?;
|
WHERE image_name = ?;
|
||||||
""",
|
""",
|
||||||
(changes.pinned, image_name),
|
(changes.starred, image_name),
|
||||||
)
|
)
|
||||||
|
|
||||||
self._conn.commit()
|
self._conn.commit()
|
||||||
@ -426,7 +426,7 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
|
|||||||
query_params.append(board_id)
|
query_params.append(board_id)
|
||||||
|
|
||||||
query_pagination = """--sql
|
query_pagination = """--sql
|
||||||
ORDER BY images.pinned DESC, images.created_at DESC LIMIT ? OFFSET ?
|
ORDER BY images.starred DESC, images.created_at DESC LIMIT ? OFFSET ?
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Final images query with pagination
|
# Final images query with pagination
|
||||||
@ -529,7 +529,7 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
|
|||||||
node_id: Optional[str],
|
node_id: Optional[str],
|
||||||
metadata: Optional[dict],
|
metadata: Optional[dict],
|
||||||
is_intermediate: bool = False,
|
is_intermediate: bool = False,
|
||||||
pinned: bool = False
|
starred: bool = False
|
||||||
) -> datetime:
|
) -> datetime:
|
||||||
try:
|
try:
|
||||||
metadata_json = None if metadata is None else json.dumps(metadata)
|
metadata_json = None if metadata is None else json.dumps(metadata)
|
||||||
@ -546,7 +546,7 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
|
|||||||
session_id,
|
session_id,
|
||||||
metadata,
|
metadata,
|
||||||
is_intermediate,
|
is_intermediate,
|
||||||
pinned
|
starred
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||||
""",
|
""",
|
||||||
@ -560,7 +560,7 @@ class SqliteImageRecordStorage(ImageRecordStorageBase):
|
|||||||
session_id,
|
session_id,
|
||||||
metadata_json,
|
metadata_json,
|
||||||
is_intermediate,
|
is_intermediate,
|
||||||
pinned,
|
starred,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
self._conn.commit()
|
self._conn.commit()
|
||||||
|
@ -39,8 +39,8 @@ class ImageRecord(BaseModelExcludeNull):
|
|||||||
description="The node ID that generated this image, if it is a generated image.",
|
description="The node ID that generated this image, if it is a generated image.",
|
||||||
)
|
)
|
||||||
"""The node ID that generated this image, if it is a generated image."""
|
"""The node ID that generated this image, if it is a generated image."""
|
||||||
pinned: bool = Field(description="Whether this image is pinned.")
|
starred: bool = Field(description="Whether this image is starred.")
|
||||||
"""Whether this image is pinned."""
|
"""Whether this image is starred."""
|
||||||
|
|
||||||
|
|
||||||
class ImageRecordChanges(BaseModelExcludeNull, extra=Extra.forbid):
|
class ImageRecordChanges(BaseModelExcludeNull, extra=Extra.forbid):
|
||||||
@ -50,7 +50,7 @@ class ImageRecordChanges(BaseModelExcludeNull, extra=Extra.forbid):
|
|||||||
- `image_category`: change the category of an image
|
- `image_category`: change the category of an image
|
||||||
- `session_id`: change the session associated with an image
|
- `session_id`: change the session associated with an image
|
||||||
- `is_intermediate`: change the image's `is_intermediate` flag
|
- `is_intermediate`: change the image's `is_intermediate` flag
|
||||||
- `pinned`: change whether the image is pinned
|
- `starred`: change whether the image is starred
|
||||||
"""
|
"""
|
||||||
|
|
||||||
image_category: Optional[ImageCategory] = Field(description="The image's new category.")
|
image_category: Optional[ImageCategory] = Field(description="The image's new category.")
|
||||||
@ -62,8 +62,8 @@ class ImageRecordChanges(BaseModelExcludeNull, extra=Extra.forbid):
|
|||||||
"""The image's new session ID."""
|
"""The image's new session ID."""
|
||||||
is_intermediate: Optional[StrictBool] = Field(default=None, description="The image's new `is_intermediate` flag.")
|
is_intermediate: Optional[StrictBool] = Field(default=None, description="The image's new `is_intermediate` flag.")
|
||||||
"""The image's new `is_intermediate` flag."""
|
"""The image's new `is_intermediate` flag."""
|
||||||
pinned: Optional[StrictBool] = Field(default=None, description="The image's new `pinned` state")
|
starred: Optional[StrictBool] = Field(default=None, description="The image's new `starred` state")
|
||||||
"""The image's new `pinned` state."""
|
"""The image's new `starred` state."""
|
||||||
|
|
||||||
|
|
||||||
class ImageUrlsDTO(BaseModelExcludeNull):
|
class ImageUrlsDTO(BaseModelExcludeNull):
|
||||||
@ -118,7 +118,7 @@ def deserialize_image_record(image_dict: dict) -> ImageRecord:
|
|||||||
updated_at = image_dict.get("updated_at", get_iso_timestamp())
|
updated_at = image_dict.get("updated_at", get_iso_timestamp())
|
||||||
deleted_at = image_dict.get("deleted_at", get_iso_timestamp())
|
deleted_at = image_dict.get("deleted_at", get_iso_timestamp())
|
||||||
is_intermediate = image_dict.get("is_intermediate", False)
|
is_intermediate = image_dict.get("is_intermediate", False)
|
||||||
pinned = image_dict.get("pinned", False)
|
starred = image_dict.get("starred", False)
|
||||||
|
|
||||||
return ImageRecord(
|
return ImageRecord(
|
||||||
image_name=image_name,
|
image_name=image_name,
|
||||||
@ -132,5 +132,5 @@ def deserialize_image_record(image_dict: dict) -> ImageRecord:
|
|||||||
updated_at=updated_at,
|
updated_at=updated_at,
|
||||||
deleted_at=deleted_at,
|
deleted_at=deleted_at,
|
||||||
is_intermediate=is_intermediate,
|
is_intermediate=is_intermediate,
|
||||||
pinned=pinned
|
starred=starred
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user