dfdfdf
This commit is contained in:
@@ -943,6 +943,79 @@ class Folder(Store):
|
||||
debug(f"delete_url failed for local file: {exc}")
|
||||
return False
|
||||
|
||||
def get_note(self, file_identifier: str, **kwargs: Any) -> Dict[str, str]:
|
||||
"""Get notes for a local file by hash."""
|
||||
from API.folder import API_folder_store
|
||||
try:
|
||||
if not self._location:
|
||||
return {}
|
||||
file_hash = str(file_identifier or "").strip().lower()
|
||||
if not _normalize_hash(file_hash):
|
||||
return {}
|
||||
with API_folder_store(Path(self._location)) as db:
|
||||
getter = getattr(db, "get_notes", None)
|
||||
if callable(getter):
|
||||
notes = getter(file_hash)
|
||||
return notes if isinstance(notes, dict) else {}
|
||||
# Fallback: default-only
|
||||
note = db.get_note(file_hash)
|
||||
return {"default": str(note or "")} if note else {}
|
||||
except Exception as exc:
|
||||
debug(f"get_note failed for local file: {exc}")
|
||||
return {}
|
||||
|
||||
def set_note(self, file_identifier: str, name: str, text: str, **kwargs: Any) -> bool:
|
||||
"""Set a named note for a local file by hash."""
|
||||
from API.folder import API_folder_store
|
||||
try:
|
||||
if not self._location:
|
||||
return False
|
||||
file_hash = str(file_identifier or "").strip().lower()
|
||||
if not _normalize_hash(file_hash):
|
||||
return False
|
||||
|
||||
file_path = self.get_file(file_hash, **kwargs)
|
||||
if not file_path or not isinstance(file_path, Path) or not file_path.exists():
|
||||
return False
|
||||
|
||||
with API_folder_store(Path(self._location)) as db:
|
||||
setter = getattr(db, "set_note", None)
|
||||
if callable(setter):
|
||||
setter(file_path, str(name), str(text))
|
||||
return True
|
||||
db.save_note(file_path, str(text))
|
||||
return True
|
||||
except Exception as exc:
|
||||
debug(f"set_note failed for local file: {exc}")
|
||||
return False
|
||||
|
||||
def delete_note(self, file_identifier: str, name: str, **kwargs: Any) -> bool:
|
||||
"""Delete a named note for a local file by hash."""
|
||||
from API.folder import API_folder_store
|
||||
try:
|
||||
if not self._location:
|
||||
return False
|
||||
file_hash = str(file_identifier or "").strip().lower()
|
||||
if not _normalize_hash(file_hash):
|
||||
return False
|
||||
with API_folder_store(Path(self._location)) as db:
|
||||
deleter = getattr(db, "delete_note", None)
|
||||
if callable(deleter):
|
||||
deleter(file_hash, str(name))
|
||||
return True
|
||||
# Default-only fallback
|
||||
if str(name).strip().lower() == "default":
|
||||
deleter2 = getattr(db, "save_note", None)
|
||||
if callable(deleter2):
|
||||
file_path = self.get_file(file_hash, **kwargs)
|
||||
if file_path and isinstance(file_path, Path) and file_path.exists():
|
||||
deleter2(file_path, "")
|
||||
return True
|
||||
return False
|
||||
except Exception as exc:
|
||||
debug(f"delete_note failed for local file: {exc}")
|
||||
return False
|
||||
|
||||
def delete_file(self, file_identifier: str, **kwargs: Any) -> bool:
|
||||
"""Delete a file from the folder store.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user