Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(config): 未填 CloudDrive2 地址时云代理区块显示设置入口

longmeidao3d75b12550af
diff --git a/docs/ROUTES.md b/docs/ROUTES.md
index 89909e7ed..cbda9efbe 100644
--- a/docs/ROUTES.md
+++ b/docs/ROUTES.md
@@ -99,7 +99,7 @@
设置分区可直接打开、刷新和用浏览器前进后退。偏好面板从当前页面打开时保留背景;配置分区复用配置页及其权限检查。配置分类导航停在搜索栏下方,切换分类时显示所选分区的开头。
-`GET /api/configuration/cloud-proxies` 返回已添加媒体库对应的 CloudDrive 账号及 API/数据代理、未匹配媒体库和账号修订号,不回显代理密码。`POST` 接受账号 `id`、`revision` 和本次修改的 `api`/`data`,写回 CloudDrive 后返回该账号当前状态;配置冲突返回 409。这两条接口均限本机管理权限,写入还要求同源请求。
+`GET /api/configuration/cloud-proxies` 返回已添加媒体库对应的 CloudDrive 账号及 API/数据代理、未匹配媒体库和账号修订号,不回显代理密码;尚未填写 CloudDrive2 地址时返回空列表与 `configured: false`。`POST` 接受账号 `id`、`revision` 和本次修改的 `api`/`data`,写回 CloudDrive 后返回该账号当前状态;配置冲突返回 409。这两条接口均限本机管理权限,写入还要求同源请求。
## 兼容地址与服务接口
diff --git a/frontend/e2e/cloud-proxy-settings.test.ts b/frontend/e2e/cloud-proxy-settings.test.ts
index 823f7ef91..0496417de 100644
--- a/frontend/e2e/cloud-proxy-settings.test.ts
+++ b/frontend/e2e/cloud-proxy-settings.test.ts
@@ -66,4 +66,23 @@ describe('CloudDrive 代理设置', () => {
} finally { await opened.close() }
});
}
+ it('未填 CloudDrive2 地址时显示设置入口,不报错', async () => {
+ const opened = await visit(browser, '/settings/library', VIEWPORTS[0], async page => {
+ await page.route('**/api/configuration', async route => {
+ const data = await (await route.fetch()).json();
+ await route.fulfill({ json: { ...data, media_sources: [{ location: '115', root: 'B:/', path: '', cost: 'metered' }] } });
+ });
+ await page.route('**/api/configuration/cloud-proxies', route =>
+ route.fulfill({ json: { accounts: [], unlinked: [], configured: false } }));
+ });
+ const { page } = opened;
+ try {
+ const section = page.getByRole('region', { name: 'CloudDrive 代理', exact: true });
+ await section.getByText('填写 CloudDrive2 地址和 API 令牌后,在这里设置各网盘账号的代理。').waitFor();
+ assert.equal(await section.getByRole('link', { name: '下载设置', exact: true }).getAttribute('href'), '/settings/downloads');
+ assert.equal(await section.getByText('没有读取配置').count(), 0);
+ assert.equal(await section.getByText('还没有使用 CloudDrive 的媒体库。').count(), 0);
+ assert.deepEqual(opened.problems, []);
+ } finally { await opened.close() }
+ });
});
diff --git a/frontend/src/react/settings/cloud-proxy-settings.tsx b/frontend/src/react/settings/cloud-proxy-settings.tsx
index d122ca3a4..3a31b597e 100644
--- a/frontend/src/react/settings/cloud-proxy-settings.tsx
+++ b/frontend/src/react/settings/cloud-proxy-settings.tsx
@@ -23,7 +23,7 @@ interface Account {
libraries?: Library[];
}
interface Library { name: string; root: string; location: string }
-interface ProxyList { accounts: Account[]; unlinked?: Library[] }
+interface ProxyList { accounts: Account[]; unlinked?: Library[]; configured?: boolean }
const options = [['direct', '直连'], ['system', '跟随系统'], ['http', 'HTTP 代理'], ['socks5', 'SOCKS5 代理']] as const;
export function CloudProxySettings({ receipt }: { receipt(message: string): void }) {
@@ -51,7 +51,8 @@ export function CloudProxySettings({ receipt }: { receipt(message: string): void
<Help>API 代理用于列目录和查询文件信息,数据代理用于读取视频及配套文件。保存后,同一网盘账号在 CloudDrive 中的其他读取也会使用此设置。</Help>
{loading ? <div data-skeleton aria-busy="true" aria-label="正在读取网盘代理"><div className="h-24 w-full rounded-2lg bg-background-tertiary-default" /></div> : null}
{action.error ? <Note tone="error" title="没有读取配置">{action.error} <LinkButton href="/settings/downloads" size="small">下载设置</LinkButton></Note> : null}
- {state?.accounts.length === 0 && !state.unlinked?.length ? <Help>还没有使用 CloudDrive 的媒体库。</Help> : null}
+ {state?.configured === false ? <Help>填写 CloudDrive2 地址和 API 令牌后,在这里设置各网盘账号的代理。 <LinkButton href="/settings/downloads" size="small">下载设置</LinkButton></Help>
+ : state?.accounts.length === 0 && !state.unlinked?.length ? <Help>还没有使用 CloudDrive 的媒体库。</Help> : null}
{state?.unlinked?.map(library => <div key={library.root} className="flex min-w-0 flex-col gap-1">
<FieldLabel><span className="inline-flex items-center gap-2"><SourceMark mark={sourceMark(library.location)} />{library.name}</span></FieldLabel>
<Help>尚未匹配 CloudDrive 账号</Help>
diff --git a/src/peach/clouddrive_proxy.py b/src/peach/clouddrive_proxy.py
index cc4ae9643..01efd5cff 100644
--- a/src/peach/clouddrive_proxy.py
+++ b/src/peach/clouddrive_proxy.py
@@ -77,9 +77,12 @@ def _accounts(client):
def read(config):
+ """没填 CloudDrive2 地址是全新部署的常态,回空结果并标 `configured=False`,不当成错误。"""
from .media_sources import CLOUD_LOCATIONS
if not any(config.locations.get(key) for key in CLOUD_LOCATIONS):
return dict(accounts=[], unlinked=[])
+ if not DownloadSettings(config.directory('state')).load().clouddrive_address:
+ return dict(accounts=[], unlinked=[], configured=False)
with client_for(config) as client:
permissions, apis = _accounts(client)
bindings = _bindings(config, client, permissions, apis)
diff --git a/tests/test_clouddrive_proxy.py b/tests/test_clouddrive_proxy.py
index 7a54d620f..3e3636b1e 100644
--- a/tests/test_clouddrive_proxy.py
+++ b/tests/test_clouddrive_proxy.py
@@ -75,6 +75,20 @@ class ProxyTests(_Server):
self.assertEqual(proxy.read(config), {'accounts': [], 'unlinked': []})
create_client.assert_not_called()
+ def test_cloud_libraries_without_clouddrive_address_read_as_not_configured(self):
+ DownloadSettings(self.config.directory('state')).save({'clouddrive_address': ''}, {})
+ with patch.object(proxy, 'client_for') as create_client:
+ self.assertEqual(proxy.read(self.config), {'accounts': [], 'unlinked': [], 'configured': False})
+ create_client.assert_not_called()
+ app = FastAPI()
+ app.include_router(router)
+ app.dependency_overrides[require_auth] = lambda: {}
+ with patch('peach.routes_configuration.settings_file.load_config', return_value=self.config), TestClient(
+ app, base_url='http://127.0.0.1', client=('127.0.0.1', 8000)) as client:
+ response = client.get('/api/configuration/cloud-proxies')
+ self.assertEqual(response.status_code, 200, response.text)
+ self.assertIs(response.json()['configured'], False)
+
def test_reads_are_fresh_and_passwords_are_not_exposed(self):
state = proxy.read(self.config)
self.assertEqual(len(state['accounts']), 2)
diff --git a/web/dist/peach-app.js b/web/dist/peach-app.js
index 438ca4fa2..b1d2f48d8 100644
--- a/web/dist/peach-app.js
+++ b/web/dist/peach-app.js
@@ -2,7 +2,7 @@
(function() {
try {
var e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, t = new e.Error().stack;
- t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "bc580cd5-ef33-42c5-b955-c8e1e665cbf1", e._sentryDebugIdIdentifier = "sentry-dbid-bc580cd5-ef33-42c5-b955-c8e1e665cbf1");
+ t && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[t] = "bdb69905-0674-46f9-a674-353d321fef0c", e._sentryDebugIdIdentifier = "sentry-dbid-bdb69905-0674-46f9-a674-353d321fef0c");
} catch {}
})();
var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, n) => {
@@ -76710,7 +76710,11 @@ function lLe({ receipt: e }) {
})
]
}) : null,
- t?.accounts.length === 0 && !t.unlinked?.length ? /* @__PURE__ */ (0, D.jsx)(dA, { children: "还没有使用 CloudDrive 的媒体库。" }) : null,
+ t?.configured === !1 ? /* @__PURE__ */ (0, D.jsxs)(dA, { children: ["填写 CloudDrive2 地址和 API 令牌后,在这里设置各网盘账号的代理。 ", /* @__PURE__ */ (0, D.jsx)(qk, {
+ href: "/settings/downloads",
+ size: "small",
+ children: "下载设置"
+ })] }) : t?.accounts.length === 0 && !t.unlinked?.length ? /* @__PURE__ */ (0, D.jsx)(dA, { children: "还没有使用 CloudDrive 的媒体库。" }) : null,
t?.unlinked?.map((e) => /* @__PURE__ */ (0, D.jsxs)("div", {
className: "flex min-w-0 flex-col gap-1",
children: [/* @__PURE__ */ (0, D.jsx)(pA, { children: /* @__PURE__ */ (0, D.jsxs)("span", {
@@ -115619,4 +115623,4 @@ nxt(rxt);
//#endregion
export { HT as applyTheme, yk as peachHistory, Go as popCount, Agt as showToast };
-//# debugId=bc580cd5-ef33-42c5-b955-c8e1e665cbf1
\ No newline at end of file
+//# debugId=bdb69905-0674-46f9-a674-353d321fef0c
\ No newline at end of file