Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6274c6ff6 |
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "videosdowntools",
|
||||
"private": true,
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"scripts": {
|
||||
"tauri": "tauri"
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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": {
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "videosdowntools-ui",
|
||||
"private": true,
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
+7
-8
@@ -153,6 +153,7 @@ const token = ref("");
|
||||
const profile = ref<Profile | null>(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<HTMLInputElement | null>(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);
|
||||
<n-button size="tiny" secondary :loading="accountBusy" @click="pickDramaboxCredential">导入凭据</n-button>
|
||||
</span>
|
||||
</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>
|
||||
<div v-for="item in accountFields" :key="item.key" class="profile-row">
|
||||
<span class="profile-row-label">{{ item.label }}</span>
|
||||
@@ -1751,6 +1749,7 @@ onUnmounted(stopLive);
|
||||
<n-button :loading="devicesBusy" @click="probeMumu">探测 MuMu</n-button>
|
||||
</div>
|
||||
</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>
|
||||
<div class="login-actions">
|
||||
<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