diff --git a/package.json b/package.json index 044b0af..c5f2b02 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "videosdowntools", "private": true, - "version": "0.1.2", + "version": "0.1.3", "scripts": { "tauri": "tauri" }, diff --git a/scripts/publish_release.py b/scripts/publish_release.py index 4b1af5e..112091b 100644 --- a/scripts/publish_release.py +++ b/scripts/publish_release.py @@ -15,7 +15,7 @@ import httpx ROOT = Path(__file__).resolve().parents[1] API = "https://git.asio.asia/api/v1/repos/nixevol/RaptDramaDump" ASSET = ROOT / "dist" / "VideosDownTools-windows-x64.zip" -NOTES = "DramaBox 登录凭据可以导出成一个 JSON 文件,在另一台电脑导入后继续使用。" +NOTES = "导出 DramaBox 登录凭据时会弹出保存窗口。" PART_SIZE = 40 * 1024 * 1024 diff --git a/server/routes/dramabox.py b/server/routes/dramabox.py index d6f1d76..1ca5c4c 100644 --- a/server/routes/dramabox.py +++ b/server/routes/dramabox.py @@ -104,6 +104,11 @@ class CredentialBody(BaseModel): language: str = "" +@router.post("/login/credential/save") +def save_credential(): + return call(db_login.save_credential_file) + + @router.post("/login/credential") def import_credential(body: CredentialBody): return call(lambda: db_login.import_credential(body.model_dump(), body.language)) diff --git a/server/services/dramabox/login.py b/server/services/dramabox/login.py index ea318f0..a41803b 100644 --- a/server/services/dramabox/login.py +++ b/server/services/dramabox/login.py @@ -1,4 +1,7 @@ +import json import secrets +import subprocess +from pathlib import Path from server.services.dramabox.client import client from server.services.dramabox.locales import DEFAULT_LANGUAGE, public_list, resolve @@ -107,6 +110,54 @@ def export_credential() -> dict: return {"kind": _CREDENTIAL_KIND, "version": _CREDENTIAL_VERSION, "app": app} +def save_credential_file() -> dict: + document = export_credential() + chosen = _pick_credential_path() + if not chosen: + return {"path": ""} + path = Path(chosen) + if path.suffix.lower() != ".json": + path = path.with_suffix(".json") + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(json.dumps(document, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") + return {"path": str(path)} + + +def _pick_credential_path() -> str: + script = """ +Add-Type -AssemblyName System.Windows.Forms +$owner = New-Object System.Windows.Forms.Form +$owner.TopMost = $true +$owner.ShowInTaskbar = $false +$owner.Opacity = 0 +$owner.Show() +$owner.Activate() +$dialog = New-Object System.Windows.Forms.SaveFileDialog +$dialog.Title = '导出登录凭据' +$dialog.Filter = 'JSON 文件 (*.json)|*.json' +$dialog.FileName = 'dramabox-login.json' +$dialog.DefaultExt = 'json' +$dialog.AddExtension = $true +$dialog.OverwritePrompt = $true +$downloads = Join-Path $env:USERPROFILE 'Downloads' +if (Test-Path $downloads) { $dialog.InitialDirectory = $downloads } +$result = $dialog.ShowDialog($owner) +$owner.Close() +if ($result -eq [System.Windows.Forms.DialogResult]::OK) { + [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding $false + [Console]::Out.WriteLine($dialog.FileName) +} +""" + completed = subprocess.run( + ["powershell", "-NoProfile", "-STA", "-Command", script], + capture_output=True, + text=True, + encoding="utf-8", + check=False, + ) + return (completed.stdout or "").strip() + + def import_credential(payload: dict, language: str = "") -> dict: record = _credential_record(payload) try: diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index cadf5b7..039bd85 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "VideosDownTools", - "version": "0.1.2", + "version": "0.1.3", "identifier": "com.videosdowntools.desktop", "build": { "beforeDevCommand": { diff --git a/ui/package.json b/ui/package.json index 6772b08..6efd807 100644 --- a/ui/package.json +++ b/ui/package.json @@ -1,7 +1,7 @@ { "name": "videosdowntools-ui", "private": true, - "version": "0.1.2", + "version": "0.1.3", "type": "module", "scripts": { "dev": "vite", diff --git a/ui/src/App.vue b/ui/src/App.vue index 2418ffc..24f85d4 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -153,6 +153,7 @@ const token = ref(""); const profile = ref(null); const dramaboxLoggedIn = computed(() => profile.value?.has_login === "1"); const dramaboxDeviceReady = computed(() => devices.value.some((item) => item.state === "device")); +const credentialNote = ref(""); const credentialFile = ref(null); const page = ref<"download" | "profile" | "progress" | "settings" | "play">("download"); const playing = ref<{ id: string | number; title: string; image: string } | null>(null); @@ -1098,21 +1099,17 @@ async function loginDramaboxAdb() { function exportDramaboxCredential() { const target = token.value ? profileError : error; target.value = ""; + credentialNote.value = ""; accountBusy.value = Boolean(token.value); busy.value = !token.value; - fetch("/api/dramabox/login/credential") + fetch("/api/dramabox/login/credential/save", { method: "POST" }) .then(async (response) => { const payload = await response.json().catch(() => ({})); if (!response.ok) { throw new Error(typeof payload.detail === "string" ? payload.detail : "导出失败"); } - const blob = new Blob([JSON.stringify(payload, null, 2)], { type: "application/json" }); - const url = URL.createObjectURL(blob); - const link = document.createElement("a"); - link.href = url; - link.download = "dramabox-login.json"; - link.click(); - URL.revokeObjectURL(url); + const path = typeof payload.path === "string" ? payload.path : ""; + credentialNote.value = path ? `已保存到 ${path}` : "已取消"; }) .catch((exc) => { target.value = exc instanceof Error ? exc.message : "导出失败"; @@ -1644,6 +1641,7 @@ onUnmounted(stopLive); 导入凭据 + {{ credentialNote }} {{ profileError }}
{{ item.label }} @@ -1751,6 +1749,7 @@ onUnmounted(stopLive); 探测 MuMu
+ {{ credentialNote }} {{ error }}