From 3a7c443004d52bfbd3f492402bbb50faeace4af1 Mon Sep 17 00:00:00 2001 From: Nose Date: Fri, 16 Jan 2026 20:16:10 -0800 Subject: [PATCH] f --- API/folder.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/API/folder.py b/API/folder.py index 2c2b509..3d6d31b 100644 --- a/API/folder.py +++ b/API/folder.py @@ -1858,6 +1858,51 @@ class API_folder_store: return None return None + def get_notes(self, file_hash: str) -> Dict[str, str]: + """Return all named notes for a file hash.""" + normalized_hash = str(file_hash or "").strip().lower() + if len(normalized_hash) != 64: + return {} + + notes: Dict[str, str] = {} + max_attempts = 5 + import time + + for attempt in range(max_attempts): + try: + with self._with_db_lock(): + cursor = self.connection.cursor() + cursor.execute( + "SELECT name, note FROM note WHERE hash = ?", + (normalized_hash, + ), + ) + rows = cursor.fetchall() or [] + for row in rows: + note_name = str(row[0] or "").strip() + if not note_name: + continue + notes[note_name] = str(row[1] or "") + return notes + except sqlite3.OperationalError as e: + msg = str(e or "").lower() + if "database is locked" in msg and attempt < (max_attempts - 1): + sleep_time = min(0.1 * (2 ** attempt), 1.0) + time.sleep(sleep_time) + continue + logger.error( + f"Error getting notes for hash {file_hash}: {e}", + exc_info=True + ) + return {} + except Exception as e: + logger.error( + f"Error getting notes for hash {file_hash}: {e}", + exc_info=True + ) + return {} + return {} + def set_note_by_hash(self, file_hash: str, name: str, note: str) -> None: """Set a named note using a known file hash (no re-hash).""" note_name = str(name or "").strip()