refactor database and media handling to use icon paths instead of flags
This commit is contained in:
@@ -31,7 +31,7 @@ class MediaRepository:
|
||||
continue
|
||||
color_dir = MEDIA_DIR / color
|
||||
icon_file = color_dir / "icon.jpg"
|
||||
self.db.update_color_icon_flag(color, icon_file.exists())
|
||||
self.db.update_color_icon(color, icon_file.as_posix() if icon_file.exists() else DEFAULT_ICON.as_posix())
|
||||
|
||||
disk_files = {f.name for f in color_dir.iterdir() if f.is_file() and f.name != "icon.jpg"}
|
||||
db_files = {m["filename"] for m in self.db.get_media_for_color(color_id)}
|
||||
@@ -53,7 +53,7 @@ class MediaRepository:
|
||||
if icon_path and icon_path.exists():
|
||||
shutil.copy(icon_path, icon_file)
|
||||
|
||||
self.db.add_color(name, icon_file.exists())
|
||||
self.db.add_color(name, icon_file.as_posix() if icon_file.exists() else DEFAULT_ICON.as_posix())
|
||||
|
||||
def remove_color(self, name: str):
|
||||
if (MEDIA_DIR / name).exists():
|
||||
@@ -72,7 +72,7 @@ class MediaRepository:
|
||||
shutil.copy(icon_path, icon_file)
|
||||
|
||||
self.db.update_color_name(old_name, new_name)
|
||||
self.db.update_color_icon_flag(new_name, icon_file.exists())
|
||||
self.db.update_color_icon(new_name, icon_file.as_posix() if icon_file.exists() else DEFAULT_ICON.as_posix())
|
||||
|
||||
def add_media(self, color: str, file_path: Path):
|
||||
target_dir = MEDIA_DIR / color
|
||||
@@ -83,13 +83,13 @@ class MediaRepository:
|
||||
ftype = "photo" if file_path.suffix.lower() in [".jpg", ".png"] else "video"
|
||||
color_id = self.db.get_color_id(color)
|
||||
if color_id is not None:
|
||||
self.db.add_media(color_id, file_path.name, ftype)
|
||||
self.db.add_media(color_id, target_file.as_posix(), ftype)
|
||||
|
||||
def remove_media(self, color: str, filename: str):
|
||||
file_path = MEDIA_DIR / color / filename
|
||||
def remove_media(self, color: str, file_path: Path):
|
||||
# file_path = MEDIA_DIR / color / filename
|
||||
if file_path.exists():
|
||||
file_path.unlink()
|
||||
|
||||
color_id = self.db.get_color_id(color)
|
||||
if color_id is not None:
|
||||
self.db.delete_media(color_id, filename)
|
||||
self.db.delete_media(color_id, file_path.as_posix())
|
||||
|
||||
Reference in New Issue
Block a user