v1.9.4: S3 optimizations — skip redundant health checks, folder drag-and-drop
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -262,20 +262,34 @@ class S3Tab(ctk.CTkFrame):
|
||||
self._dnd_active = False
|
||||
|
||||
def _on_files_dropped(self, files):
|
||||
"""Handle files dropped from OS file manager."""
|
||||
"""Handle files/folders dropped from OS file manager."""
|
||||
if not self._client or not self._current_bucket:
|
||||
return
|
||||
# windnd gives list of bytes on Windows
|
||||
paths = []
|
||||
raw_paths = []
|
||||
for f in files:
|
||||
if isinstance(f, bytes):
|
||||
paths.append(f.decode("utf-8", errors="replace"))
|
||||
raw_paths.append(f.decode("utf-8", errors="replace"))
|
||||
else:
|
||||
paths.append(str(f))
|
||||
paths = [p for p in paths if os.path.isfile(p)]
|
||||
if not paths:
|
||||
raw_paths.append(str(f))
|
||||
|
||||
# Collect (local_path, s3_key_suffix) pairs
|
||||
upload_pairs: list[tuple[str, str]] = []
|
||||
for p in raw_paths:
|
||||
if os.path.isfile(p):
|
||||
upload_pairs.append((p, os.path.basename(p)))
|
||||
elif os.path.isdir(p):
|
||||
base = os.path.basename(p.rstrip("/\\"))
|
||||
for root, _dirs, fnames in os.walk(p):
|
||||
for fn in fnames:
|
||||
full = os.path.join(root, fn)
|
||||
rel = os.path.relpath(full, os.path.dirname(p))
|
||||
rel = rel.replace("\\", "/")
|
||||
upload_pairs.append((full, rel))
|
||||
|
||||
if not upload_pairs:
|
||||
return
|
||||
self._upload_files(paths)
|
||||
self._upload_pairs(upload_pairs)
|
||||
|
||||
def _show_progress(self, label: str, total_bytes: int):
|
||||
"""Show and reset the progress bar."""
|
||||
@@ -315,11 +329,17 @@ class S3Tab(ctk.CTkFrame):
|
||||
self.after(0, lambda: self._status_label.configure(text=message))
|
||||
|
||||
def _upload_files(self, paths: list[str]):
|
||||
"""Upload multiple files to current prefix."""
|
||||
"""Upload multiple files to current prefix (flat — no subdirs)."""
|
||||
pairs = [(p, os.path.basename(p)) for p in paths if os.path.isfile(p)]
|
||||
if pairs:
|
||||
self._upload_pairs(pairs)
|
||||
|
||||
def _upload_pairs(self, pairs: list[tuple[str, str]]):
|
||||
"""Upload (local_path, relative_key) pairs to current prefix."""
|
||||
if not self._client or not self._current_bucket:
|
||||
return
|
||||
total_files = len(paths)
|
||||
total_bytes = sum(os.path.getsize(p) for p in paths if os.path.isfile(p))
|
||||
total_files = len(pairs)
|
||||
total_bytes = sum(os.path.getsize(p) for p, _ in pairs if os.path.isfile(p))
|
||||
label = (t("s3_uploading_n").format(count=total_files) if total_files > 1
|
||||
else t("s3_uploading"))
|
||||
self._status_label.configure(text=label)
|
||||
@@ -327,11 +347,10 @@ class S3Tab(ctk.CTkFrame):
|
||||
|
||||
def _do():
|
||||
ok_count = 0
|
||||
for path in paths:
|
||||
filename = os.path.basename(path)
|
||||
key = self._current_prefix + filename
|
||||
for local_path, rel_key in pairs:
|
||||
key = self._current_prefix + rel_key
|
||||
if self._client.upload_file(
|
||||
path, self._current_bucket, key,
|
||||
local_path, self._current_bucket, key,
|
||||
progress_cb=self._on_progress,
|
||||
status_cb=self._on_transfer_status):
|
||||
ok_count += 1
|
||||
|
||||
Reference in New Issue
Block a user