From c67aadf26706810ff5b407a08e072bc3896407b0 Mon Sep 17 00:00:00 2001 From: divocat Date: Thu, 6 Nov 2025 16:52:08 +0200 Subject: [PATCH] feat: add yacd_secret_key support for ws --- .../podkop/methods/custom/getClashApiSecret.ts | 9 +++++++++ fe-app-podkop/src/podkop/methods/custom/index.ts | 2 ++ .../src/podkop/tabs/dashboard/initController.ts | 7 +++++-- fe-app-podkop/src/podkop/types.ts | 1 + .../luci-static/resources/view/podkop/main.js | 15 ++++++++++++--- 5 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 fe-app-podkop/src/podkop/methods/custom/getClashApiSecret.ts diff --git a/fe-app-podkop/src/podkop/methods/custom/getClashApiSecret.ts b/fe-app-podkop/src/podkop/methods/custom/getClashApiSecret.ts new file mode 100644 index 0000000..4bc654a --- /dev/null +++ b/fe-app-podkop/src/podkop/methods/custom/getClashApiSecret.ts @@ -0,0 +1,9 @@ +import { getConfigSections } from './getConfigSections'; + +export async function getClashApiSecret() { + const sections = await getConfigSections(); + + const settings = sections.find((section) => section['.type'] === 'settings'); + + return settings?.yacd_secret_key || ''; +} diff --git a/fe-app-podkop/src/podkop/methods/custom/index.ts b/fe-app-podkop/src/podkop/methods/custom/index.ts index 7ade0fa..8aba225 100644 --- a/fe-app-podkop/src/podkop/methods/custom/index.ts +++ b/fe-app-podkop/src/podkop/methods/custom/index.ts @@ -1,7 +1,9 @@ import { getConfigSections } from './getConfigSections'; import { getDashboardSections } from './getDashboardSections'; +import { getClashApiSecret } from './getClashApiSecret'; export const CustomPodkopMethods = { getConfigSections, getDashboardSections, + getClashApiSecret, }; diff --git a/fe-app-podkop/src/podkop/tabs/dashboard/initController.ts b/fe-app-podkop/src/podkop/tabs/dashboard/initController.ts index e1abeab..2b8c948 100644 --- a/fe-app-podkop/src/podkop/tabs/dashboard/initController.ts +++ b/fe-app-podkop/src/podkop/tabs/dashboard/initController.ts @@ -8,6 +8,7 @@ import { CustomPodkopMethods, PodkopShellMethods } from '../../methods'; import { logger, socket, store, StoreType } from '../../services'; import { renderSections, renderWidget } from './partials'; import { fetchServicesInfo } from '../../fetchers'; +import { getClashApiSecret } from '../../methods/custom/getClashApiSecret'; // Fetchers @@ -38,8 +39,10 @@ async function fetchDashboardSections() { } async function connectToClashSockets() { + const clashApiSecret = await getClashApiSecret(); + socket.subscribe( - `${getClashWsUrl()}/traffic?token=`, + `${getClashWsUrl()}/traffic?token=${clashApiSecret}`, (msg) => { const parsedMsg = JSON.parse(msg); @@ -68,7 +71,7 @@ async function connectToClashSockets() { ); socket.subscribe( - `${getClashWsUrl()}/connections?token=`, + `${getClashWsUrl()}/connections?token=${clashApiSecret}`, (msg) => { const parsedMsg = JSON.parse(msg); diff --git a/fe-app-podkop/src/podkop/types.ts b/fe-app-podkop/src/podkop/types.ts index 25e65d7..0f4ed35 100644 --- a/fe-app-podkop/src/podkop/types.ts +++ b/fe-app-podkop/src/podkop/types.ts @@ -126,6 +126,7 @@ export namespace Podkop { export type ConfigSection = ConfigBaseSection & { '.name': string; '.type': 'settings' | 'section'; + yacd_secret_key?: string; }; export interface MethodSuccessResponse { diff --git a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js index c4b7ee7..638867e 100644 --- a/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js +++ b/luci-app-podkop/htdocs/luci-static/resources/view/podkop/main.js @@ -731,10 +731,18 @@ async function getDashboardSections() { }; } +// src/podkop/methods/custom/getClashApiSecret.ts +async function getClashApiSecret() { + const sections = await getConfigSections(); + const settings = sections.find((section) => section[".type"] === "settings"); + return settings?.yacd_secret_key || ""; +} + // src/podkop/methods/custom/index.ts var CustomPodkopMethods = { getConfigSections, - getDashboardSections + getDashboardSections, + getClashApiSecret }; // src/constants.ts @@ -1876,8 +1884,9 @@ async function fetchDashboardSections() { }); } async function connectToClashSockets() { + const clashApiSecret = await getClashApiSecret(); socket.subscribe( - `${getClashWsUrl()}/traffic?token=`, + `${getClashWsUrl()}/traffic?token=${clashApiSecret}`, (msg) => { const parsedMsg = JSON.parse(msg); store.set({ @@ -1904,7 +1913,7 @@ async function connectToClashSockets() { } ); socket.subscribe( - `${getClashWsUrl()}/connections?token=`, + `${getClashWsUrl()}/connections?token=${clashApiSecret}`, (msg) => { const parsedMsg = JSON.parse(msg); store.set({