fix: 导出凭据时弹出另存为窗口
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "videosdowntools",
|
"name": "videosdowntools",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"tauri": "tauri"
|
"tauri": "tauri"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import httpx
|
|||||||
ROOT = Path(__file__).resolve().parents[1]
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
API = "https://git.asio.asia/api/v1/repos/nixevol/RaptDramaDump"
|
API = "https://git.asio.asia/api/v1/repos/nixevol/RaptDramaDump"
|
||||||
ASSET = ROOT / "dist" / "VideosDownTools-windows-x64.zip"
|
ASSET = ROOT / "dist" / "VideosDownTools-windows-x64.zip"
|
||||||
NOTES = "DramaBox 登录凭据可以导出成一个 JSON 文件,在另一台电脑导入后继续使用。"
|
NOTES = "导出 DramaBox 登录凭据时会弹出保存窗口。"
|
||||||
PART_SIZE = 40 * 1024 * 1024
|
PART_SIZE = 40 * 1024 * 1024
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -104,6 +104,11 @@ class CredentialBody(BaseModel):
|
|||||||
language: str = ""
|
language: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/login/credential/save")
|
||||||
|
def save_credential():
|
||||||
|
return call(db_login.save_credential_file)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/login/credential")
|
@router.post("/login/credential")
|
||||||
def import_credential(body: CredentialBody):
|
def import_credential(body: CredentialBody):
|
||||||
return call(lambda: db_login.import_credential(body.model_dump(), body.language))
|
return call(lambda: db_login.import_credential(body.model_dump(), body.language))
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
import json
|
||||||
import secrets
|
import secrets
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from server.services.dramabox.client import client
|
from server.services.dramabox.client import client
|
||||||
from server.services.dramabox.locales import DEFAULT_LANGUAGE, public_list, resolve
|
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}
|
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:
|
def import_credential(payload: dict, language: str = "") -> dict:
|
||||||
record = _credential_record(payload)
|
record = _credential_record(payload)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://schema.tauri.app/config/2",
|
"$schema": "https://schema.tauri.app/config/2",
|
||||||
"productName": "VideosDownTools",
|
"productName": "VideosDownTools",
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"identifier": "com.videosdowntools.desktop",
|
"identifier": "com.videosdowntools.desktop",
|
||||||
"build": {
|
"build": {
|
||||||
"beforeDevCommand": {
|
"beforeDevCommand": {
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "videosdowntools-ui",
|
"name": "videosdowntools-ui",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.1.2",
|
"version": "0.1.3",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
+7
-8
@@ -153,6 +153,7 @@ const token = ref("");
|
|||||||
const profile = ref<Profile | null>(null);
|
const profile = ref<Profile | null>(null);
|
||||||
const dramaboxLoggedIn = computed(() => profile.value?.has_login === "1");
|
const dramaboxLoggedIn = computed(() => profile.value?.has_login === "1");
|
||||||
const dramaboxDeviceReady = computed(() => devices.value.some((item) => item.state === "device"));
|
const dramaboxDeviceReady = computed(() => devices.value.some((item) => item.state === "device"));
|
||||||
|
const credentialNote = ref("");
|
||||||
const credentialFile = ref<HTMLInputElement | null>(null);
|
const credentialFile = ref<HTMLInputElement | null>(null);
|
||||||
const page = ref<"download" | "profile" | "progress" | "settings" | "play">("download");
|
const page = ref<"download" | "profile" | "progress" | "settings" | "play">("download");
|
||||||
const playing = ref<{ id: string | number; title: string; image: string } | null>(null);
|
const playing = ref<{ id: string | number; title: string; image: string } | null>(null);
|
||||||
@@ -1098,21 +1099,17 @@ async function loginDramaboxAdb() {
|
|||||||
function exportDramaboxCredential() {
|
function exportDramaboxCredential() {
|
||||||
const target = token.value ? profileError : error;
|
const target = token.value ? profileError : error;
|
||||||
target.value = "";
|
target.value = "";
|
||||||
|
credentialNote.value = "";
|
||||||
accountBusy.value = Boolean(token.value);
|
accountBusy.value = Boolean(token.value);
|
||||||
busy.value = !token.value;
|
busy.value = !token.value;
|
||||||
fetch("/api/dramabox/login/credential")
|
fetch("/api/dramabox/login/credential/save", { method: "POST" })
|
||||||
.then(async (response) => {
|
.then(async (response) => {
|
||||||
const payload = await response.json().catch(() => ({}));
|
const payload = await response.json().catch(() => ({}));
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(typeof payload.detail === "string" ? payload.detail : "导出失败");
|
throw new Error(typeof payload.detail === "string" ? payload.detail : "导出失败");
|
||||||
}
|
}
|
||||||
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: "application/json" });
|
const path = typeof payload.path === "string" ? payload.path : "";
|
||||||
const url = URL.createObjectURL(blob);
|
credentialNote.value = path ? `已保存到 ${path}` : "已取消";
|
||||||
const link = document.createElement("a");
|
|
||||||
link.href = url;
|
|
||||||
link.download = "dramabox-login.json";
|
|
||||||
link.click();
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
})
|
})
|
||||||
.catch((exc) => {
|
.catch((exc) => {
|
||||||
target.value = exc instanceof Error ? exc.message : "导出失败";
|
target.value = exc instanceof Error ? exc.message : "导出失败";
|
||||||
@@ -1644,6 +1641,7 @@ onUnmounted(stopLive);
|
|||||||
<n-button size="tiny" secondary :loading="accountBusy" @click="pickDramaboxCredential">导入凭据</n-button>
|
<n-button size="tiny" secondary :loading="accountBusy" @click="pickDramaboxCredential">导入凭据</n-button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<n-alert v-if="credentialNote" class="hint" type="success" :show-icon="false">{{ credentialNote }}</n-alert>
|
||||||
<n-alert v-if="profileError" class="hint" type="error" :show-icon="false">{{ profileError }}</n-alert>
|
<n-alert v-if="profileError" class="hint" type="error" :show-icon="false">{{ profileError }}</n-alert>
|
||||||
<div v-for="item in accountFields" :key="item.key" class="profile-row">
|
<div v-for="item in accountFields" :key="item.key" class="profile-row">
|
||||||
<span class="profile-row-label">{{ item.label }}</span>
|
<span class="profile-row-label">{{ item.label }}</span>
|
||||||
@@ -1751,6 +1749,7 @@ onUnmounted(stopLive);
|
|||||||
<n-button :loading="devicesBusy" @click="probeMumu">探测 MuMu</n-button>
|
<n-button :loading="devicesBusy" @click="probeMumu">探测 MuMu</n-button>
|
||||||
</div>
|
</div>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
|
<n-alert v-if="credentialNote && platform === 'dramabox'" class="hint" type="success" :show-icon="false">{{ credentialNote }}</n-alert>
|
||||||
<n-alert v-if="error" class="hint" type="error" :show-icon="false">{{ error }}</n-alert>
|
<n-alert v-if="error" class="hint" type="error" :show-icon="false">{{ error }}</n-alert>
|
||||||
<div class="login-actions">
|
<div class="login-actions">
|
||||||
<n-button v-if="platform === 'dramabox'" attr-type="button" secondary :loading="busy" :disabled="!dramaboxDeviceReady" @click="loginDramaboxAdb">从设备登录</n-button>
|
<n-button v-if="platform === 'dramabox'" attr-type="button" secondary :loading="busy" :disabled="!dramaboxDeviceReady" @click="loginDramaboxAdb">从设备登录</n-button>
|
||||||
|
|||||||
Reference in New Issue
Block a user