v1.9.3: S3 context menu — two link types: temp 48h + permanent direct
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -209,9 +209,14 @@ class S3Tab(ctk.CTkFrame):
|
||||
# Right-click context menu
|
||||
self._ctx_menu = tk.Menu(self._tree, tearoff=0)
|
||||
self._ctx_menu.add_command(
|
||||
label=icon_text("copy", t("s3_copy_link")),
|
||||
command=self._copy_link,
|
||||
label=icon_text("copy", t("s3_copy_link_48h")),
|
||||
command=self._copy_link_48h,
|
||||
)
|
||||
self._ctx_menu.add_command(
|
||||
label=icon_text("copy", t("s3_copy_link_permanent")),
|
||||
command=self._copy_link_permanent,
|
||||
)
|
||||
self._ctx_menu.add_separator()
|
||||
self._ctx_menu.add_command(
|
||||
label=icon_text("download", t("s3_download")),
|
||||
command=self._download,
|
||||
@@ -491,33 +496,54 @@ class S3Tab(ctk.CTkFrame):
|
||||
name = str(name)
|
||||
is_folder = name.endswith("/")
|
||||
# Enable/disable menu items based on type
|
||||
self._ctx_menu.entryconfigure(0, state="normal" if not is_folder else "disabled") # Copy link
|
||||
self._ctx_menu.entryconfigure(1, state="normal" if not is_folder else "disabled") # Download
|
||||
self._ctx_menu.entryconfigure(3, state="normal" if not is_folder else "disabled") # Delete
|
||||
state = "normal" if not is_folder else "disabled"
|
||||
self._ctx_menu.entryconfigure(0, state=state) # Link 48h
|
||||
self._ctx_menu.entryconfigure(1, state=state) # Link permanent
|
||||
self._ctx_menu.entryconfigure(3, state=state) # Download
|
||||
self._ctx_menu.entryconfigure(5, state=state) # Delete
|
||||
self._ctx_menu.tk_popup(event.x_root, event.y_root)
|
||||
|
||||
def _copy_link(self):
|
||||
"""Generate presigned URL and copy to clipboard."""
|
||||
def _get_selected_key(self) -> str | None:
|
||||
"""Return the full S3 key for the selected file, or None."""
|
||||
sel = self._tree.selection()
|
||||
if not sel or not self._client or not self._current_bucket:
|
||||
return
|
||||
return None
|
||||
item = self._tree.item(sel[0])
|
||||
name = item["values"][0] if item["values"] else ""
|
||||
if not isinstance(name, str):
|
||||
name = str(name)
|
||||
if name.endswith("/"):
|
||||
return
|
||||
return None
|
||||
return self._current_prefix + name
|
||||
|
||||
key = self._current_prefix + name
|
||||
def _copy_link_48h(self):
|
||||
"""Generate presigned URL (48h) and copy to clipboard."""
|
||||
key = self._get_selected_key()
|
||||
if not key:
|
||||
return
|
||||
self._status_label.configure(text=t("s3_generating_link"))
|
||||
|
||||
def _do():
|
||||
url = self._client.generate_presigned_url(self._current_bucket, key)
|
||||
self.after(0, lambda: self._on_link_ready(url))
|
||||
url = self._client.generate_presigned_url(
|
||||
self._current_bucket, key, expires_in=48 * 3600)
|
||||
self.after(0, lambda: self._on_link_ready(url, "48h"))
|
||||
|
||||
threading.Thread(target=_do, daemon=True).start()
|
||||
|
||||
def _on_link_ready(self, url: str | None):
|
||||
def _copy_link_permanent(self):
|
||||
"""Build direct (permanent) URL and copy to clipboard."""
|
||||
key = self._get_selected_key()
|
||||
if not key:
|
||||
return
|
||||
url = self._client.get_direct_url(self._current_bucket, key)
|
||||
if url:
|
||||
self.clipboard_clear()
|
||||
self.clipboard_append(url)
|
||||
self._status_label.configure(text=t("s3_link_copied"))
|
||||
else:
|
||||
self._status_label.configure(text=t("s3_link_failed"))
|
||||
|
||||
def _on_link_ready(self, url: str | None, kind: str = ""):
|
||||
if url:
|
||||
self.clipboard_clear()
|
||||
self.clipboard_append(url)
|
||||
|
||||
Reference in New Issue
Block a user