🐛 fix: Fix bugs
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import useGlobalStore, { GlobalStore } from '@/config/use-global';
|
||||
import { useStatsStore } from '@/store/stats';
|
||||
import { Logout } from '@/utils/common';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ReactQueryStreamedHydration } from '@tanstack/react-query-next-experimental';
|
||||
@@ -42,6 +43,12 @@ export default function Providers({
|
||||
setCommon(common);
|
||||
}, [setCommon, common]);
|
||||
|
||||
const { stats } = useStatsStore();
|
||||
|
||||
useEffect(() => {
|
||||
stats();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<NextThemesProvider attribute='class' defaultTheme='system' enableSystem>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
|
||||
@@ -76,6 +76,17 @@ export async function updateNodeConfig(body: API.NodeConfig, options?: { [key: s
|
||||
});
|
||||
}
|
||||
|
||||
/** PreView Node Multiplier GET /v1/admin/system/node_multiplier/preview */
|
||||
export async function preViewNodeMultiplier(options?: { [key: string]: any }) {
|
||||
return request<API.Response & { data?: API.PreViewNodeMultiplierResponse }>(
|
||||
'/v1/admin/system/node_multiplier/preview',
|
||||
{
|
||||
method: 'GET',
|
||||
...(options || {}),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/** get Privacy Policy Config GET /v1/admin/system/privacy */
|
||||
export async function getPrivacyPolicyConfig(options?: { [key: string]: any }) {
|
||||
return request<API.Response & { data?: API.PrivacyPolicyConfig }>('/v1/admin/system/privacy', {
|
||||
|
||||
+14
-1
@@ -108,6 +108,7 @@ declare namespace API {
|
||||
type AuthConfig = {
|
||||
mobile: MobileAuthenticateConfig;
|
||||
email: EmailAuthticateConfig;
|
||||
device: DeviceAuthticateConfig;
|
||||
register: PubilcRegisterConfig;
|
||||
};
|
||||
|
||||
@@ -456,6 +457,13 @@ declare namespace API {
|
||||
user_subscribe_id: number;
|
||||
};
|
||||
|
||||
type DeviceAuthticateConfig = {
|
||||
enable: boolean;
|
||||
show_ads: boolean;
|
||||
enable_security: boolean;
|
||||
only_real_device: boolean;
|
||||
};
|
||||
|
||||
type Document = {
|
||||
id: number;
|
||||
title: string;
|
||||
@@ -1272,7 +1280,7 @@ declare namespace API {
|
||||
has_migrate: boolean;
|
||||
};
|
||||
|
||||
type Hysteria = {
|
||||
type Hysteria2 = {
|
||||
port: number;
|
||||
hop_ports: string;
|
||||
hop_interval: number;
|
||||
@@ -1495,6 +1503,11 @@ declare namespace API {
|
||||
orderNo: string;
|
||||
};
|
||||
|
||||
type PreViewNodeMultiplierResponse = {
|
||||
current_time: string;
|
||||
ratio: number;
|
||||
};
|
||||
|
||||
type PreviewSubscribeTemplateParams = {
|
||||
id: number;
|
||||
};
|
||||
|
||||
@@ -47,6 +47,18 @@ export async function userLogin(body: API.UserLoginRequest, options?: { [key: st
|
||||
});
|
||||
}
|
||||
|
||||
/** Device Login POST /v1/auth/login/device */
|
||||
export async function deviceLogin(body: API.DeviceLoginRequest, options?: { [key: string]: any }) {
|
||||
return request<API.Response & { data?: API.LoginResponse }>('/v1/auth/login/device', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: body,
|
||||
...(options || {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** User Telephone login POST /v1/auth/login/telephone */
|
||||
export async function telephoneLogin(
|
||||
body: API.TelephoneLoginRequest,
|
||||
|
||||
+21
-1
@@ -114,6 +114,7 @@ declare namespace API {
|
||||
type AuthConfig = {
|
||||
mobile: MobileAuthenticateConfig;
|
||||
email: EmailAuthticateConfig;
|
||||
device: DeviceAuthticateConfig;
|
||||
register: PubilcRegisterConfig;
|
||||
};
|
||||
|
||||
@@ -211,6 +212,19 @@ declare namespace API {
|
||||
currency_symbol: string;
|
||||
};
|
||||
|
||||
type DeviceAuthticateConfig = {
|
||||
enable: boolean;
|
||||
show_ads: boolean;
|
||||
enable_security: boolean;
|
||||
only_real_device: boolean;
|
||||
};
|
||||
|
||||
type DeviceLoginRequest = {
|
||||
identifier: string;
|
||||
user_agent: string;
|
||||
cf_token?: string;
|
||||
};
|
||||
|
||||
type Document = {
|
||||
id: number;
|
||||
title: string;
|
||||
@@ -324,7 +338,7 @@ declare namespace API {
|
||||
state: string;
|
||||
};
|
||||
|
||||
type Hysteria = {
|
||||
type Hysteria2 = {
|
||||
port: number;
|
||||
hop_ports: string;
|
||||
hop_interval: number;
|
||||
@@ -706,6 +720,7 @@ declare namespace API {
|
||||
};
|
||||
|
||||
type ResetPasswordRequest = {
|
||||
identifier: string;
|
||||
email: string;
|
||||
password: string;
|
||||
code?: string;
|
||||
@@ -898,6 +913,7 @@ declare namespace API {
|
||||
};
|
||||
|
||||
type TelephoneLoginRequest = {
|
||||
identifier: string;
|
||||
telephone: string;
|
||||
telephone_code: string;
|
||||
telephone_area_code: string;
|
||||
@@ -906,6 +922,7 @@ declare namespace API {
|
||||
};
|
||||
|
||||
type TelephoneRegisterRequest = {
|
||||
identifier: string;
|
||||
telephone: string;
|
||||
telephone_area_code: string;
|
||||
password: string;
|
||||
@@ -915,6 +932,7 @@ declare namespace API {
|
||||
};
|
||||
|
||||
type TelephoneResetPasswordRequest = {
|
||||
identifier: string;
|
||||
telephone: string;
|
||||
telephone_area_code: string;
|
||||
password: string;
|
||||
@@ -1035,12 +1053,14 @@ declare namespace API {
|
||||
};
|
||||
|
||||
type UserLoginRequest = {
|
||||
identifier: string;
|
||||
email: string;
|
||||
password: string;
|
||||
cf_token?: string;
|
||||
};
|
||||
|
||||
type UserRegisterRequest = {
|
||||
identifier: string;
|
||||
email: string;
|
||||
password: string;
|
||||
invite?: string;
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
// Fixed remote stats endpoint and required header
|
||||
export const REQUIRED_HEADER_NAME = 'stats';
|
||||
export const REQUIRED_HEADER_VALUE = 'ppanel.dev';
|
||||
const STATS_URL = 'https://stats.ppanel.dev';
|
||||
const STATS_LOADED_KEY = 'ppanel:stats:loaded';
|
||||
|
||||
interface StatsState {
|
||||
loading: boolean;
|
||||
loaded: boolean;
|
||||
stats: () => Promise<void>;
|
||||
}
|
||||
|
||||
async function hashHostname(hostname: string): Promise<string> {
|
||||
try {
|
||||
const encoder = new TextEncoder();
|
||||
const data = encoder.encode(hostname);
|
||||
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export const useStatsStore = create<StatsState>((set) => ({
|
||||
loading: false,
|
||||
loaded:
|
||||
typeof window !== 'undefined' ? Boolean(window.localStorage.getItem(STATS_LOADED_KEY)) : false,
|
||||
|
||||
stats: async () => {
|
||||
// if already recorded, skip
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
if (window.localStorage.getItem(STATS_LOADED_KEY)) return;
|
||||
} catch {}
|
||||
}
|
||||
|
||||
set({ loading: true });
|
||||
try {
|
||||
const hostname =
|
||||
typeof window !== 'undefined' && window.location ? window.location.hostname : '';
|
||||
const domain = hostname ? await hashHostname(hostname) : '';
|
||||
|
||||
await fetch(STATS_URL, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[REQUIRED_HEADER_NAME]: REQUIRED_HEADER_VALUE,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
domain,
|
||||
}),
|
||||
});
|
||||
set({ loaded: true });
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
window.localStorage.setItem(STATS_LOADED_KEY, '1');
|
||||
} catch {}
|
||||
}
|
||||
} catch (error) {
|
||||
// treat as completed to avoid repeated attempts
|
||||
set({ loaded: false });
|
||||
if (typeof window !== 'undefined') {
|
||||
try {
|
||||
window.localStorage.setItem(STATS_LOADED_KEY, '0');
|
||||
} catch {}
|
||||
}
|
||||
} finally {
|
||||
set({ loading: false });
|
||||
}
|
||||
},
|
||||
}));
|
||||
Reference in New Issue
Block a user