feat: add yacd_secret_key support for ws

This commit is contained in:
divocat
2025-11-06 16:52:08 +02:00
parent ac4d7570f3
commit c67aadf267
5 changed files with 29 additions and 5 deletions

View File

@@ -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 || '';
}

View File

@@ -1,7 +1,9 @@
import { getConfigSections } from './getConfigSections';
import { getDashboardSections } from './getDashboardSections';
import { getClashApiSecret } from './getClashApiSecret';
export const CustomPodkopMethods = {
getConfigSections,
getDashboardSections,
getClashApiSecret,
};

View File

@@ -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);

View File

@@ -126,6 +126,7 @@ export namespace Podkop {
export type ConfigSection = ConfigBaseSection & {
'.name': string;
'.type': 'settings' | 'section';
yacd_secret_key?: string;
};
export interface MethodSuccessResponse<T> {

View File

@@ -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({