mirror of
https://github.com/itdoginfo/podkop.git
synced 2025-12-06 11:36:50 +03:00
feat: add yacd_secret_key support for ws
This commit is contained in:
@@ -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 || '';
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import { getConfigSections } from './getConfigSections';
|
import { getConfigSections } from './getConfigSections';
|
||||||
import { getDashboardSections } from './getDashboardSections';
|
import { getDashboardSections } from './getDashboardSections';
|
||||||
|
import { getClashApiSecret } from './getClashApiSecret';
|
||||||
|
|
||||||
export const CustomPodkopMethods = {
|
export const CustomPodkopMethods = {
|
||||||
getConfigSections,
|
getConfigSections,
|
||||||
getDashboardSections,
|
getDashboardSections,
|
||||||
|
getClashApiSecret,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { CustomPodkopMethods, PodkopShellMethods } from '../../methods';
|
|||||||
import { logger, socket, store, StoreType } from '../../services';
|
import { logger, socket, store, StoreType } from '../../services';
|
||||||
import { renderSections, renderWidget } from './partials';
|
import { renderSections, renderWidget } from './partials';
|
||||||
import { fetchServicesInfo } from '../../fetchers';
|
import { fetchServicesInfo } from '../../fetchers';
|
||||||
|
import { getClashApiSecret } from '../../methods/custom/getClashApiSecret';
|
||||||
|
|
||||||
// Fetchers
|
// Fetchers
|
||||||
|
|
||||||
@@ -38,8 +39,10 @@ async function fetchDashboardSections() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function connectToClashSockets() {
|
async function connectToClashSockets() {
|
||||||
|
const clashApiSecret = await getClashApiSecret();
|
||||||
|
|
||||||
socket.subscribe(
|
socket.subscribe(
|
||||||
`${getClashWsUrl()}/traffic?token=`,
|
`${getClashWsUrl()}/traffic?token=${clashApiSecret}`,
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const parsedMsg = JSON.parse(msg);
|
const parsedMsg = JSON.parse(msg);
|
||||||
|
|
||||||
@@ -68,7 +71,7 @@ async function connectToClashSockets() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
socket.subscribe(
|
socket.subscribe(
|
||||||
`${getClashWsUrl()}/connections?token=`,
|
`${getClashWsUrl()}/connections?token=${clashApiSecret}`,
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const parsedMsg = JSON.parse(msg);
|
const parsedMsg = JSON.parse(msg);
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ export namespace Podkop {
|
|||||||
export type ConfigSection = ConfigBaseSection & {
|
export type ConfigSection = ConfigBaseSection & {
|
||||||
'.name': string;
|
'.name': string;
|
||||||
'.type': 'settings' | 'section';
|
'.type': 'settings' | 'section';
|
||||||
|
yacd_secret_key?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface MethodSuccessResponse<T> {
|
export interface MethodSuccessResponse<T> {
|
||||||
|
|||||||
@@ -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
|
// src/podkop/methods/custom/index.ts
|
||||||
var CustomPodkopMethods = {
|
var CustomPodkopMethods = {
|
||||||
getConfigSections,
|
getConfigSections,
|
||||||
getDashboardSections
|
getDashboardSections,
|
||||||
|
getClashApiSecret
|
||||||
};
|
};
|
||||||
|
|
||||||
// src/constants.ts
|
// src/constants.ts
|
||||||
@@ -1876,8 +1884,9 @@ async function fetchDashboardSections() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
async function connectToClashSockets() {
|
async function connectToClashSockets() {
|
||||||
|
const clashApiSecret = await getClashApiSecret();
|
||||||
socket.subscribe(
|
socket.subscribe(
|
||||||
`${getClashWsUrl()}/traffic?token=`,
|
`${getClashWsUrl()}/traffic?token=${clashApiSecret}`,
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const parsedMsg = JSON.parse(msg);
|
const parsedMsg = JSON.parse(msg);
|
||||||
store.set({
|
store.set({
|
||||||
@@ -1904,7 +1913,7 @@ async function connectToClashSockets() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
socket.subscribe(
|
socket.subscribe(
|
||||||
`${getClashWsUrl()}/connections?token=`,
|
`${getClashWsUrl()}/connections?token=${clashApiSecret}`,
|
||||||
(msg) => {
|
(msg) => {
|
||||||
const parsedMsg = JSON.parse(msg);
|
const parsedMsg = JSON.parse(msg);
|
||||||
store.set({
|
store.set({
|
||||||
|
|||||||
Reference in New Issue
Block a user