h
This commit is contained in:
@@ -2028,6 +2028,7 @@ class API_folder_store:
|
|||||||
pipe: Optional[str] = None,
|
pipe: Optional[str] = None,
|
||||||
) -> int:
|
) -> int:
|
||||||
"""Insert a new worker entry into the database."""
|
"""Insert a new worker entry into the database."""
|
||||||
|
with self._db_lock:
|
||||||
try:
|
try:
|
||||||
cursor = self.connection.cursor()
|
cursor = self.connection.cursor()
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
@@ -2107,6 +2108,7 @@ class API_folder_store:
|
|||||||
|
|
||||||
def update_worker_status(self, worker_id: str, status: str) -> int:
|
def update_worker_status(self, worker_id: str, status: str) -> int:
|
||||||
"""Update worker status and return its database ID."""
|
"""Update worker status and return its database ID."""
|
||||||
|
with self._db_lock:
|
||||||
try:
|
try:
|
||||||
cursor = self.connection.cursor()
|
cursor = self.connection.cursor()
|
||||||
|
|
||||||
@@ -2484,10 +2486,15 @@ class API_folder_store:
|
|||||||
logger.error(f"Error closing database: {e}", exc_info=True)
|
logger.error(f"Error closing database: {e}", exc_info=True)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
if not self.connection:
|
||||||
|
self._init_db()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
try:
|
||||||
self.close()
|
self.close()
|
||||||
|
finally:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
@@ -372,6 +372,7 @@ class Folder(Store):
|
|||||||
tag: Optional list of tag values to add
|
tag: Optional list of tag values to add
|
||||||
url: Optional list of url to associate with the file
|
url: Optional list of url to associate with the file
|
||||||
title: Optional title (will be added as 'title:value' tag)
|
title: Optional title (will be added as 'title:value' tag)
|
||||||
|
file_hash: Optional pre-calculated SHA256 hash (skips re-hashing)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
File hash (SHA256 hex string) as identifier
|
File hash (SHA256 hex string) as identifier
|
||||||
@@ -380,6 +381,7 @@ class Folder(Store):
|
|||||||
tag_list = kwargs.get("tag", [])
|
tag_list = kwargs.get("tag", [])
|
||||||
url = kwargs.get("url", [])
|
url = kwargs.get("url", [])
|
||||||
title = kwargs.get("title")
|
title = kwargs.get("title")
|
||||||
|
file_hash = kwargs.get("file_hash")
|
||||||
|
|
||||||
# Extract title from tags if not explicitly provided
|
# Extract title from tags if not explicitly provided
|
||||||
if not title:
|
if not title:
|
||||||
@@ -400,7 +402,10 @@ class Folder(Store):
|
|||||||
tag_list = [title_tag] + list(tag_list)
|
tag_list = [title_tag] + list(tag_list)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if not file_hash or len(str(file_hash)) != 64:
|
||||||
|
debug(f"[folder] Re-hashing file: {file_path}", file=sys.stderr)
|
||||||
file_hash = sha256_file(file_path)
|
file_hash = sha256_file(file_path)
|
||||||
|
|
||||||
debug(f"File hash: {file_hash}", file=sys.stderr)
|
debug(f"File hash: {file_hash}", file=sys.stderr)
|
||||||
|
|
||||||
# Preserve extension in the stored filename
|
# Preserve extension in the stored filename
|
||||||
|
|||||||
@@ -546,7 +546,7 @@ class Add_File(Cmdlet):
|
|||||||
delete_after_item = delete_after
|
delete_after_item = delete_after
|
||||||
try:
|
try:
|
||||||
if use_steps and (not steps_started):
|
if use_steps and (not steps_started):
|
||||||
progress.begin_steps(4)
|
progress.begin_steps(5)
|
||||||
progress.step("resolving source")
|
progress.step("resolving source")
|
||||||
steps_started = True
|
steps_started = True
|
||||||
|
|
||||||
@@ -560,6 +560,19 @@ class Add_File(Cmdlet):
|
|||||||
failures += 1
|
failures += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if use_steps and steps_started:
|
||||||
|
progress.step("hashing file")
|
||||||
|
|
||||||
|
# Update pipe_obj with resolved path
|
||||||
|
pipe_obj.path = str(media_path)
|
||||||
|
|
||||||
|
# When using -path (filesystem export), allow all file types.
|
||||||
|
# When using -store (backend), restrict to SUPPORTED_MEDIA_EXTENSIONS.
|
||||||
|
allow_all_files = not (location and is_storage_backend_location)
|
||||||
|
if not self._validate_source(media_path, allow_all_extensions=allow_all_files):
|
||||||
|
failures += 1
|
||||||
|
continue
|
||||||
|
|
||||||
if use_steps and steps_started and (not step2_done):
|
if use_steps and steps_started and (not step2_done):
|
||||||
progress.step("ingesting file")
|
progress.step("ingesting file")
|
||||||
step2_done = True
|
step2_done = True
|
||||||
@@ -1973,16 +1986,18 @@ class Add_File(Cmdlet):
|
|||||||
debug("[add-file] Deferring tag application until after Hydrus upload")
|
debug("[add-file] Deferring tag application until after Hydrus upload")
|
||||||
|
|
||||||
debug(
|
debug(
|
||||||
f"[add-file] Storing into backend '{backend_name}' path='{media_path}' title='{title}'"
|
f"[add-file] Storing into backend '{backend_name}' path='{media_path}' title='{title}' hash='{f_hash[:12] if f_hash else 'N/A'}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Call backend's add_file with full metadata
|
# Call backend's add_file with full metadata
|
||||||
# Backend returns hash as identifier
|
# Backend returns hash as identifier. If we already know the hash from _resolve_source
|
||||||
|
# (which came from download-file emit), pass it to skip re-hashing the 4GB file.
|
||||||
file_identifier = backend.add_file(
|
file_identifier = backend.add_file(
|
||||||
media_path,
|
media_path,
|
||||||
title=title,
|
title=title,
|
||||||
tag=upload_tags,
|
tag=upload_tags,
|
||||||
url=[] if (defer_url_association and url) else url,
|
url=[] if (defer_url_association and url) else url,
|
||||||
|
file_hash=f_hash,
|
||||||
)
|
)
|
||||||
debug(
|
debug(
|
||||||
f"[add-file] backend.add_file returned identifier {file_identifier} (len={len(str(file_identifier)) if file_identifier is not None else 'None'})"
|
f"[add-file] backend.add_file returned identifier {file_identifier} (len={len(str(file_identifier)) if file_identifier is not None else 'None'})"
|
||||||
|
|||||||
Reference in New Issue
Block a user