jkjnkjkllkjjk
This commit is contained in:
@@ -541,8 +541,36 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
# Map provider 0x0 to storage 0x0 for download-data
|
||||
if provider_name == "0x0":
|
||||
dl_args.extend(["-storage", "0x0"])
|
||||
|
||||
return dl_module._run(result, dl_args, config)
|
||||
|
||||
# Capture results from download-data so we can add them to DB
|
||||
captured_results = []
|
||||
original_emit = ctx.emit
|
||||
|
||||
def capture_emit(obj):
|
||||
captured_results.append(obj)
|
||||
original_emit(obj)
|
||||
|
||||
ctx.emit = capture_emit
|
||||
|
||||
try:
|
||||
ret_code = dl_module._run(result, dl_args, config)
|
||||
finally:
|
||||
ctx.emit = original_emit
|
||||
|
||||
if ret_code != 0:
|
||||
return ret_code
|
||||
|
||||
# Process the downloaded files recursively to add them to DB
|
||||
if captured_results:
|
||||
log(f"Processing {len(captured_results)} downloaded file(s)...", file=sys.stderr)
|
||||
success_count = 0
|
||||
for res in captured_results:
|
||||
# Recursively call add-file with the downloaded result
|
||||
if _run(res, _args, config) == 0:
|
||||
success_count += 1
|
||||
return 0 if success_count > 0 else 1
|
||||
|
||||
return 0
|
||||
|
||||
if media_path is None:
|
||||
log("File path could not be resolved")
|
||||
@@ -609,13 +637,13 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
return 0
|
||||
|
||||
# Handle storage-based operations (location is not None here)
|
||||
valid_locations = {'hydrus', 'local'}
|
||||
valid_locations = {'hydrus', 'local', 'matrix'}
|
||||
is_valid_location = location in valid_locations
|
||||
is_local_path = not is_valid_location and ('/' in location or '\\' in location or ':' in location)
|
||||
|
||||
if not (is_valid_location or is_local_path):
|
||||
log(f"❌ Invalid location: {location}")
|
||||
log(f"Valid options: 'hydrus', 'local', or a directory path (e.g., C:\\Music or /home/user/music)")
|
||||
log(f"Valid options: 'hydrus', 'local', 'matrix', or a directory path")
|
||||
return 1
|
||||
|
||||
if location == 'local':
|
||||
@@ -704,6 +732,36 @@ def _run(result: Any, _args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
|
||||
return exit_code
|
||||
|
||||
elif location == 'matrix':
|
||||
log(f"Uploading to Matrix: {media_path.name}", file=sys.stderr)
|
||||
try:
|
||||
result_url = storage["matrix"].upload(media_path, config=config)
|
||||
log(f"Matrix: {result_url}", file=sys.stderr)
|
||||
|
||||
result_dict = create_pipe_object_result(
|
||||
source='matrix',
|
||||
identifier=result_url,
|
||||
file_path=str(media_path),
|
||||
cmdlet_name='add-file',
|
||||
title=media_path.name,
|
||||
target=result_url
|
||||
)
|
||||
ctx.emit(result_dict)
|
||||
|
||||
except Exception as exc:
|
||||
log(f"Failed: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if delete_after_upload:
|
||||
try:
|
||||
media_path.unlink()
|
||||
_cleanup_sidecar_files(media_path)
|
||||
log(f"✅ Deleted file and sidecar", file=sys.stderr)
|
||||
except Exception as exc:
|
||||
log(f"⚠️ Could not delete file: {exc}", file=sys.stderr)
|
||||
|
||||
return 0
|
||||
|
||||
# location == 'hydrus'
|
||||
# Compute file hash to check if already in Hydrus
|
||||
log(f"Uploading to Hydrus: {media_path.name}", file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user