Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 47f66030db | |||
| 70b3484f98 | |||
| 3c036eb09c | |||
| ce9ab89c1c | |||
| bb0a811432 | |||
| 8445e302e6 | |||
| 2bff15fd13 | |||
| 0345b7cced | |||
| 7a4ebdf985 | |||
| 05a61d8bf2 | |||
| 0a07d2578e | |||
| ee05a73834 | |||
| 13dce0c20b | |||
| 41f06bfe54 | |||
| 0cadd83e45 | |||
| d7879a8654 | |||
| 49b3dcc591 | |||
| e94405d1cd | |||
| 1dde7088bc | |||
| bd67ece479 | |||
| a3c5e31094 | |||
| 1b715c5f8b | |||
| 6dfac27bc3 | |||
| c6dd0b63f2 |
+61
-6
@@ -1,16 +1,71 @@
|
|||||||
<a name="readme-top"></a>
|
<a name="readme-top"></a>
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [1.4.4](https://github.com/perfect-panel/ppanel-web/compare/v1.4.3...v1.4.4) (2025-09-16)
|
## [1.4.8](https://github.com/perfect-panel/ppanel-web/compare/v1.4.7...v1.4.8) (2025-09-23)
|
||||||
|
|
||||||
|
|
||||||
### 🐛 Bug Fixes
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
* Add minimum value constraint for count and user limit inputs in CouponForm ([6991b69](https://github.com/perfect-panel/ppanel-web/commit/6991b69))
|
* Rename 'server_id' to 'protocol' in NodesPage and clean up unused imports and code in ServerConfig ([70b3484](https://github.com/perfect-panel/ppanel-web/commit/70b3484))
|
||||||
* Add protocol-related constants, default configurations, field definitions, and validation modes ([d685407](https://github.com/perfect-panel/ppanel-web/commit/d685407))
|
* Update announcement page to display timeline of announcements with Markdown content ([3c036eb](https://github.com/perfect-panel/ppanel-web/commit/3c036eb))
|
||||||
* Added the enabled field in the protocol configuration, updated the related type definition and default configuration ([2b0cf9a](https://github.com/perfect-panel/ppanel-web/commit/2b0cf9a))
|
* Update Empty component to support border prop and adjust usage in various pages ([ce9ab89](https://github.com/perfect-panel/ppanel-web/commit/ce9ab89))
|
||||||
* Filter available protocols to exclude disabled ones in NodeForm ([982d288](https://github.com/perfect-panel/ppanel-web/commit/982d288))
|
|
||||||
* Refactor key generation logic and update dependencies for ML-KEM-768 integration ([b8f630f](https://github.com/perfect-panel/ppanel-web/commit/b8f630f))
|
## [1.4.7](https://github.com/perfect-panel/ppanel-web/compare/v1.4.6...v1.4.7) (2025-09-23)
|
||||||
|
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
* Add unique key to ProTable for improved rendering with user ID filters ([2bff15f](https://github.com/perfect-panel/ppanel-web/commit/2bff15f))
|
||||||
|
* Adjust layout spacing and chart aspect ratio in ServerConfig component ([05a61d8](https://github.com/perfect-panel/ppanel-web/commit/05a61d8))
|
||||||
|
* Refactor server ID cell rendering for improved readability and consistency ([0345b7c](https://github.com/perfect-panel/ppanel-web/commit/0345b7c))
|
||||||
|
* Update announcement page to format creation date and enhance content display ([8445e30](https://github.com/perfect-panel/ppanel-web/commit/8445e30))
|
||||||
|
* Update OnlineUsersCell to display user count with icon instead of badge ([7a4ebdf](https://github.com/perfect-panel/ppanel-web/commit/7a4ebdf))
|
||||||
|
* Update subscribe name fallback to return '--' instead of 'Unknown' ([0a07d25](https://github.com/perfect-panel/ppanel-web/commit/0a07d25))
|
||||||
|
|
||||||
|
## [1.4.6](https://github.com/perfect-panel/ppanel-web/compare/v1.4.5...v1.4.6) (2025-09-17)
|
||||||
|
|
||||||
|
|
||||||
|
### 🎫 Chores
|
||||||
|
|
||||||
|
* Merge branch 'main' into develop ([41f06bf](https://github.com/perfect-panel/ppanel-web/commit/41f06bf))
|
||||||
|
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
* Add loaded state to node, server, and subscribe stores for better loading management ([13dce0c](https://github.com/perfect-panel/ppanel-web/commit/13dce0c))
|
||||||
|
* Removed node metadata fields in subscription schema to simplify structure ([0cadd83](https://github.com/perfect-panel/ppanel-web/commit/0cadd83))
|
||||||
|
|
||||||
|
## [1.4.5](https://github.com/perfect-panel/ppanel-web/compare/v1.4.4...v1.4.5) (2025-09-17)
|
||||||
|
|
||||||
|
|
||||||
|
### ♻ Code Refactoring
|
||||||
|
|
||||||
|
* Replace useQuery with Zustand store for subscription and node data management ([c6dd0b6](https://github.com/perfect-panel/ppanel-web/commit/c6dd0b6))
|
||||||
|
* Simplify TemplatePreview component structure by consolidating Sheet and Button elements ([1b715c5](https://github.com/perfect-panel/ppanel-web/commit/1b715c5))
|
||||||
|
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
* Add showLineNumbers prop handling in MonacoEditor for improved placeholder positioning ([bd67ece](https://github.com/perfect-panel/ppanel-web/commit/bd67ece))
|
||||||
|
* Add fetchTags method to NodesPage and ensure tags are fetched alongside nodes ([a3c5e31](https://github.com/perfect-panel/ppanel-web/commit/a3c5e31))
|
||||||
|
* Add NEXT_PUBLIC_HIDDEN_TUTORIAL_DOCUMENT to control tutorial visibility and update page query accordingly ([e94405d](https://github.com/perfect-panel/ppanel-web/commit/e94405d))
|
||||||
|
* Add subscribeSchema for subscription management with detailed proxy and user information ([49b3dcc](https://github.com/perfect-panel/ppanel-web/commit/49b3dcc))
|
||||||
|
* Enhance server ID display in ServerTrafficLogPage with badges and server ratio ([6dfac27](https://github.com/perfect-panel/ppanel-web/commit/6dfac27))
|
||||||
|
* Update platform handling in Content component to ensure available platforms are correctly filtered and displayed ([1dde708](https://github.com/perfect-panel/ppanel-web/commit/1dde708))
|
||||||
|
|
||||||
|
<a name="readme-top"></a>
|
||||||
|
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
## [1.4.4](https://github.com/perfect-panel/ppanel-web/compare/v1.4.3...v1.4.4) (2025-09-16)
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
- Add minimum value constraint for count and user limit inputs in CouponForm ([6991b69](https://github.com/perfect-panel/ppanel-web/commit/6991b69))
|
||||||
|
- Add protocol-related constants, default configurations, field definitions, and validation modes ([d685407](https://github.com/perfect-panel/ppanel-web/commit/d685407))
|
||||||
|
- Added the enabled field in the protocol configuration, updated the related type definition and default configuration ([2b0cf9a](https://github.com/perfect-panel/ppanel-web/commit/2b0cf9a))
|
||||||
|
- Filter available protocols to exclude disabled ones in NodeForm ([982d288](https://github.com/perfect-panel/ppanel-web/commit/982d288))
|
||||||
|
- Refactor key generation logic and update dependencies for ML-KEM-768 integration ([b8f630f](https://github.com/perfect-panel/ppanel-web/commit/b8f630f))
|
||||||
|
|
||||||
<a name="readme-top"></a>
|
<a name="readme-top"></a>
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
import { useSubscribe } from '@/store/subscribe';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
@@ -81,16 +80,7 @@ export default function CouponForm<T extends Record<string, any>>({
|
|||||||
|
|
||||||
const type = form.watch('type');
|
const type = form.watch('type');
|
||||||
|
|
||||||
const { data: subscribe } = useQuery({
|
const { subscribes } = useSubscribe();
|
||||||
queryKey: ['getSubscribeList', 'all'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await getSubscribeList({
|
|
||||||
page: 1,
|
|
||||||
size: 9999,
|
|
||||||
});
|
|
||||||
return data.data?.list as API.Subscribe[];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sheet open={open} onOpenChange={setOpen}>
|
<Sheet open={open} onOpenChange={setOpen}>
|
||||||
@@ -247,9 +237,9 @@ export default function CouponForm<T extends Record<string, any>>({
|
|||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
form.setValue(field.name, value);
|
form.setValue(field.name, value);
|
||||||
}}
|
}}
|
||||||
options={subscribe?.map((item: API.Subscribe) => ({
|
options={subscribes?.map((item) => ({
|
||||||
value: item.id,
|
value: item.id!,
|
||||||
label: item.name,
|
label: item.name!,
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|||||||
@@ -9,9 +9,8 @@ import {
|
|||||||
getCouponList,
|
getCouponList,
|
||||||
updateCoupon,
|
updateCoupon,
|
||||||
} from '@/services/admin/coupon';
|
} from '@/services/admin/coupon';
|
||||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
import { useSubscribe } from '@/store/subscribe';
|
||||||
import { formatDate } from '@/utils/common';
|
import { formatDate } from '@/utils/common';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import { Badge } from '@workspace/ui/components/badge';
|
import { Badge } from '@workspace/ui/components/badge';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import { Switch } from '@workspace/ui/components/switch';
|
import { Switch } from '@workspace/ui/components/switch';
|
||||||
@@ -24,16 +23,7 @@ import CouponForm from './coupon-form';
|
|||||||
export default function Page() {
|
export default function Page() {
|
||||||
const t = useTranslations('coupon');
|
const t = useTranslations('coupon');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const { data } = useQuery({
|
const { subscribes } = useSubscribe();
|
||||||
queryKey: ['getSubscribeList', 'all'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await getSubscribeList({
|
|
||||||
page: 1,
|
|
||||||
size: 9999,
|
|
||||||
});
|
|
||||||
return data.data?.list as API.SubscribeGroup[];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const ref = useRef<ProTableActions>(null);
|
const ref = useRef<ProTableActions>(null);
|
||||||
return (
|
return (
|
||||||
<ProTable<API.Coupon, { group_id: number; query: string }>
|
<ProTable<API.Coupon, { group_id: number; query: string }>
|
||||||
@@ -67,8 +57,8 @@ export default function Page() {
|
|||||||
{
|
{
|
||||||
key: 'subscribe',
|
key: 'subscribe',
|
||||||
placeholder: t('subscribe'),
|
placeholder: t('subscribe'),
|
||||||
options: data?.map((item) => ({
|
options: subscribes?.map((item) => ({
|
||||||
label: item.name,
|
label: item.name!,
|
||||||
value: String(item.id),
|
value: String(item.id),
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
import { ProTable } from '@/components/pro-table';
|
import { ProTable } from '@/components/pro-table';
|
||||||
import { filterServerTrafficLog } from '@/services/admin/log';
|
import { filterServerTrafficLog } from '@/services/admin/log';
|
||||||
import { filterServerList } from '@/services/admin/server';
|
import { useServer } from '@/store/server';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { Badge } from '@workspace/ui/components/badge';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import { formatBytes } from '@workspace/ui/utils';
|
import { formatBytes } from '@workspace/ui/utils';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
@@ -13,20 +13,10 @@ import { useSearchParams } from 'next/navigation';
|
|||||||
export default function ServerTrafficLogPage() {
|
export default function ServerTrafficLogPage() {
|
||||||
const t = useTranslations('log');
|
const t = useTranslations('log');
|
||||||
const sp = useSearchParams();
|
const sp = useSearchParams();
|
||||||
|
const { getServerName, getServerById } = useServer();
|
||||||
|
|
||||||
const today = new Date().toISOString().split('T')[0];
|
const today = new Date().toISOString().split('T')[0];
|
||||||
|
|
||||||
const { data: servers = [] } = useQuery({
|
|
||||||
queryKey: ['filterServerListAll'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await filterServerList({ page: 1, size: 999999999 });
|
|
||||||
return data?.data?.list || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getServerName = (id?: number) =>
|
|
||||||
id ? (servers.find((s) => s.id === id)?.name ?? `Server ${id}`) : 'Unknown';
|
|
||||||
|
|
||||||
const initialFilters = {
|
const initialFilters = {
|
||||||
date: sp.get('date') || today,
|
date: sp.get('date') || today,
|
||||||
server_id: sp.get('server_id') ? Number(sp.get('server_id')) : undefined,
|
server_id: sp.get('server_id') ? Number(sp.get('server_id')) : undefined,
|
||||||
@@ -50,11 +40,17 @@ export default function ServerTrafficLogPage() {
|
|||||||
{
|
{
|
||||||
accessorKey: 'server_id',
|
accessorKey: 'server_id',
|
||||||
header: t('column.server'),
|
header: t('column.server'),
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => {
|
||||||
<span>
|
const server = getServerById(row.original.server_id);
|
||||||
{getServerName(row.original.server_id)} ({row.original.server_id})
|
const ratio = server?.ratio || 1;
|
||||||
</span>
|
return (
|
||||||
),
|
<div className='flex items-center gap-2'>
|
||||||
|
<Badge>{row.original.server_id}</Badge>
|
||||||
|
<span>{getServerName(row.original.server_id)}</span>
|
||||||
|
<Badge variant='outline'>{ratio}X</Badge>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'upload',
|
accessorKey: 'upload',
|
||||||
|
|||||||
@@ -3,9 +3,8 @@
|
|||||||
import { UserDetail, UserSubscribeDetail } from '@/app/dashboard/user/user-detail';
|
import { UserDetail, UserSubscribeDetail } from '@/app/dashboard/user/user-detail';
|
||||||
import { ProTable } from '@/components/pro-table';
|
import { ProTable } from '@/components/pro-table';
|
||||||
import { filterTrafficLogDetails } from '@/services/admin/log';
|
import { filterTrafficLogDetails } from '@/services/admin/log';
|
||||||
import { filterServerList } from '@/services/admin/server';
|
import { useServer } from '@/store/server';
|
||||||
import { formatDate } from '@/utils/common';
|
import { formatDate } from '@/utils/common';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import { formatBytes } from '@workspace/ui/utils';
|
import { formatBytes } from '@workspace/ui/utils';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useSearchParams } from 'next/navigation';
|
import { useSearchParams } from 'next/navigation';
|
||||||
@@ -13,20 +12,10 @@ import { useSearchParams } from 'next/navigation';
|
|||||||
export default function TrafficDetailsPage() {
|
export default function TrafficDetailsPage() {
|
||||||
const t = useTranslations('log');
|
const t = useTranslations('log');
|
||||||
const sp = useSearchParams();
|
const sp = useSearchParams();
|
||||||
|
const { getServerName } = useServer();
|
||||||
|
|
||||||
const today = new Date().toISOString().split('T')[0];
|
const today = new Date().toISOString().split('T')[0];
|
||||||
|
|
||||||
const { data: servers = [] } = useQuery({
|
|
||||||
queryKey: ['filterServerListAll'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await filterServerList({ page: 1, size: 999999999 });
|
|
||||||
return data?.data?.list || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getServerName = (id?: number) =>
|
|
||||||
id ? (servers.find((s) => s.id === id)?.name ?? `Server ${id}`) : 'Unknown';
|
|
||||||
|
|
||||||
const initialFilters = {
|
const initialFilters = {
|
||||||
date: sp.get('date') || today,
|
date: sp.get('date') || today,
|
||||||
server_id: sp.get('server_id') ? Number(sp.get('server_id')) : undefined,
|
server_id: sp.get('server_id') ? Number(sp.get('server_id')) : undefined,
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
|
|
||||||
import { Display } from '@/components/display';
|
import { Display } from '@/components/display';
|
||||||
import { createQuotaTask, queryQuotaTaskPreCount } from '@/services/admin/marketing';
|
import { createQuotaTask, queryQuotaTaskPreCount } from '@/services/admin/marketing';
|
||||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
import { useSubscribe } from '@/store/subscribe';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
@@ -73,17 +72,7 @@ export default function QuotaBroadcastForm() {
|
|||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
// Get subscribe list
|
const { subscribes } = useSubscribe();
|
||||||
const { data: subscribeList } = useQuery({
|
|
||||||
queryKey: ['getSubscribeList', 'all'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await getSubscribeList({
|
|
||||||
page: 1,
|
|
||||||
size: 999999999,
|
|
||||||
});
|
|
||||||
return data.data?.list as API.SubscribeItem[];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Calculate recipient count
|
// Calculate recipient count
|
||||||
const calculateRecipients = async () => {
|
const calculateRecipients = async () => {
|
||||||
@@ -217,21 +206,19 @@ export default function QuotaBroadcastForm() {
|
|||||||
value={field.value || []}
|
value={field.value || []}
|
||||||
onChange={field.onChange}
|
onChange={field.onChange}
|
||||||
placeholder={t('pleaseSelectSubscribers')}
|
placeholder={t('pleaseSelectSubscribers')}
|
||||||
options={
|
options={subscribes?.map((subscribe) => ({
|
||||||
subscribeList?.map((subscribe) => ({
|
value: subscribe.id!,
|
||||||
value: subscribe.id!,
|
label: subscribe.name!,
|
||||||
label: subscribe.name!,
|
children: (
|
||||||
children: (
|
<div>
|
||||||
<div>
|
<div>{subscribe.name}</div>
|
||||||
<div>{subscribe.name}</div>
|
<div className='text-muted-foreground text-xs'>
|
||||||
<div className='text-muted-foreground text-xs'>
|
<Display type='traffic' value={subscribe.traffic || 0} /> /{' '}
|
||||||
<Display type='traffic' value={subscribe.traffic || 0} /> /{' '}
|
<Display type='currency' value={subscribe.unit_price || 0} />
|
||||||
<Display type='currency' value={subscribe.unit_price || 0} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
),
|
</div>
|
||||||
})) || []
|
),
|
||||||
}
|
}))}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
@@ -3,9 +3,8 @@
|
|||||||
import { Display } from '@/components/display';
|
import { Display } from '@/components/display';
|
||||||
import { ProTable } from '@/components/pro-table';
|
import { ProTable } from '@/components/pro-table';
|
||||||
import { queryQuotaTaskList } from '@/services/admin/marketing';
|
import { queryQuotaTaskList } from '@/services/admin/marketing';
|
||||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
import { useSubscribe } from '@/store/subscribe';
|
||||||
import { formatDate } from '@/utils/common';
|
import { formatDate } from '@/utils/common';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import { Badge } from '@workspace/ui/components/badge';
|
import { Badge } from '@workspace/ui/components/badge';
|
||||||
import { ScrollArea } from '@workspace/ui/components/scroll-area';
|
import { ScrollArea } from '@workspace/ui/components/scroll-area';
|
||||||
import {
|
import {
|
||||||
@@ -23,21 +22,9 @@ export default function QuotaTaskManager() {
|
|||||||
const t = useTranslations('marketing');
|
const t = useTranslations('marketing');
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
// Get subscribe list to show subscription names
|
const { subscribes } = useSubscribe();
|
||||||
const { data: subscribeList } = useQuery({
|
|
||||||
queryKey: ['getSubscribeList', 'all'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await getSubscribeList({
|
|
||||||
page: 1,
|
|
||||||
size: 999999999,
|
|
||||||
});
|
|
||||||
return data.data?.list as API.SubscribeItem[];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create a map for quick lookup of subscription names
|
|
||||||
const subscribeMap =
|
const subscribeMap =
|
||||||
subscribeList?.reduce(
|
subscribes?.reduce(
|
||||||
(acc, subscribe) => {
|
(acc, subscribe) => {
|
||||||
acc[subscribe.id!] = subscribe.name!;
|
acc[subscribe.id!] = subscribe.name!;
|
||||||
return acc;
|
return acc;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { filterServerList, queryNodeTag } from '@/services/admin/server';
|
import { useNode } from '@/store/node';
|
||||||
|
import { useServer } from '@/store/server';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
@@ -40,8 +40,6 @@ export type ProtocolName =
|
|||||||
| 'tuic'
|
| 'tuic'
|
||||||
| 'anytls';
|
| 'anytls';
|
||||||
|
|
||||||
type ServerRow = API.Server;
|
|
||||||
|
|
||||||
const buildSchema = (t: ReturnType<typeof useTranslations>) =>
|
const buildSchema = (t: ReturnType<typeof useTranslations>) =>
|
||||||
z.object({
|
z.object({
|
||||||
name: z.string().trim().min(1, t('errors.nameRequired')),
|
name: z.string().trim().min(1, t('errors.nameRequired')),
|
||||||
@@ -103,38 +101,12 @@ export default function NodeForm(props: {
|
|||||||
|
|
||||||
const serverId = form.watch('server_id');
|
const serverId = form.watch('server_id');
|
||||||
|
|
||||||
const { data } = useQuery({
|
const { servers, getAvailableProtocols } = useServer();
|
||||||
enabled: open,
|
const { tags } = useNode();
|
||||||
queryKey: ['filterServerListAll'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await filterServerList({ page: 1, size: 999999999 });
|
|
||||||
return data?.data?.list || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const servers: ServerRow[] = data as ServerRow[];
|
|
||||||
|
|
||||||
const { data: tagsData } = useQuery({
|
const existingTags: string[] = tags || [];
|
||||||
enabled: open,
|
|
||||||
queryKey: ['queryNodeTag'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await queryNodeTag();
|
|
||||||
return data?.data?.tags || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const existingTags: string[] = tagsData as string[];
|
|
||||||
|
|
||||||
const currentServer = useMemo(() => servers?.find((s) => s.id === serverId), [servers, serverId]);
|
const availableProtocols = getAvailableProtocols(serverId);
|
||||||
|
|
||||||
const availableProtocols = useMemo(() => {
|
|
||||||
if (!currentServer?.protocols) return [];
|
|
||||||
|
|
||||||
return currentServer.protocols
|
|
||||||
.filter((p) => p.enable !== false)
|
|
||||||
.map((p) => ({
|
|
||||||
protocol: p.type,
|
|
||||||
port: p.port,
|
|
||||||
}));
|
|
||||||
}, [currentServer]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (initialValues) {
|
if (initialValues) {
|
||||||
@@ -176,12 +148,11 @@ export default function NodeForm(props: {
|
|||||||
fieldsToFill.push('address');
|
fieldsToFill.push('address');
|
||||||
}
|
}
|
||||||
|
|
||||||
const protocols =
|
const protocols = getAvailableProtocols(id);
|
||||||
(selectedServer.protocols as Array<{ type: ProtocolName; port?: number }>) || [];
|
|
||||||
const firstProtocol = protocols[0];
|
const firstProtocol = protocols[0];
|
||||||
|
|
||||||
if (firstProtocol && (!currentValues.protocol || autoFilledFields.has('protocol'))) {
|
if (firstProtocol && (!currentValues.protocol || autoFilledFields.has('protocol'))) {
|
||||||
form.setValue('protocol', firstProtocol.type, { shouldDirty: false });
|
form.setValue('protocol', firstProtocol.protocol, { shouldDirty: false });
|
||||||
fieldsToFill.push('protocol');
|
fieldsToFill.push('protocol');
|
||||||
|
|
||||||
if (!currentValues.port || currentValues.port === 0 || autoFilledFields.has('port')) {
|
if (!currentValues.port || currentValues.port === 0 || autoFilledFields.has('port')) {
|
||||||
@@ -203,7 +174,7 @@ export default function NodeForm(props: {
|
|||||||
const protocol = (nextProto || '') as ProtocolName | '';
|
const protocol = (nextProto || '') as ProtocolName | '';
|
||||||
form.setValue('protocol', protocol);
|
form.setValue('protocol', protocol);
|
||||||
|
|
||||||
if (!protocol || !currentServer) {
|
if (!protocol || !serverId) {
|
||||||
removeAutoFilledField('protocol');
|
removeAutoFilledField('protocol');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -214,9 +185,7 @@ export default function NodeForm(props: {
|
|||||||
removeAutoFilledField('protocol');
|
removeAutoFilledField('protocol');
|
||||||
|
|
||||||
if (!currentValues.port || currentValues.port === 0 || isPortAutoFilled) {
|
if (!currentValues.port || currentValues.port === 0 || isPortAutoFilled) {
|
||||||
const protocolData = (
|
const protocolData = availableProtocols.find((p) => p.protocol === protocol);
|
||||||
currentServer.protocols as Array<{ type: ProtocolName; port?: number }>
|
|
||||||
)?.find((p) => p.type === protocol);
|
|
||||||
|
|
||||||
if (protocolData) {
|
if (protocolData) {
|
||||||
const port = protocolData.port || 0;
|
const port = protocolData.port || 0;
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import {
|
|||||||
createNode,
|
createNode,
|
||||||
deleteNode,
|
deleteNode,
|
||||||
filterNodeList,
|
filterNodeList,
|
||||||
filterServerList,
|
|
||||||
resetSortWithNode,
|
resetSortWithNode,
|
||||||
toggleNodeStatus,
|
toggleNodeStatus,
|
||||||
updateNode,
|
updateNode,
|
||||||
} from '@/services/admin/server';
|
} from '@/services/admin/server';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useNode } from '@/store/node';
|
||||||
|
import { useServer } from '@/store/server';
|
||||||
import { Badge } from '@workspace/ui/components/badge';
|
import { Badge } from '@workspace/ui/components/badge';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import { Switch } from '@workspace/ui/components/switch';
|
import { Switch } from '@workspace/ui/components/switch';
|
||||||
@@ -25,24 +25,9 @@ export default function NodesPage() {
|
|||||||
const ref = useRef<ProTableActions>(null);
|
const ref = useRef<ProTableActions>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const { data: servers = [] } = useQuery({
|
// Use our zustand store for server data
|
||||||
queryKey: ['filterServerListAll'],
|
const { getServerName, getServerAddress, getProtocolPort } = useServer();
|
||||||
queryFn: async () => {
|
const { fetchNodes, fetchTags } = useNode();
|
||||||
const { data } = await filterServerList({ page: 1, size: 999999999 });
|
|
||||||
return data?.data?.list || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const getServerName = (id?: number) =>
|
|
||||||
id ? (servers.find((s) => s.id === id)?.name ?? `#${id}`) : '—';
|
|
||||||
const getServerOriginAddr = (id?: number) =>
|
|
||||||
id ? (servers.find((s) => s.id === id)?.address ?? '—') : '—';
|
|
||||||
const getProtocolOriginPort = (id?: number, proto?: string) => {
|
|
||||||
if (!id || !proto) return '—';
|
|
||||||
const hit = servers.find((s) => s.id === id)?.protocols?.find((p) => (p as any).type === proto);
|
|
||||||
const p = (hit as any)?.port as number | undefined;
|
|
||||||
return typeof p === 'number' ? String(p) : '—';
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ProTable<API.Node, { search: string }>
|
<ProTable<API.Node, { search: string }>
|
||||||
@@ -69,6 +54,8 @@ export default function NodesPage() {
|
|||||||
await createNode(body);
|
await createNode(body);
|
||||||
toast.success(t('created'));
|
toast.success(t('created'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchNodes();
|
||||||
|
fetchTags();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -90,6 +77,8 @@ export default function NodesPage() {
|
|||||||
await toggleNodeStatus({ id: row.original.id, enable: v });
|
await toggleNodeStatus({ id: row.original.id, enable: v });
|
||||||
toast.success(v ? t('enabled_on') : t('enabled_off'));
|
toast.success(v ? t('enabled_on') : t('enabled_off'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchNodes();
|
||||||
|
fetchTags();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
@@ -99,24 +88,20 @@ export default function NodesPage() {
|
|||||||
{
|
{
|
||||||
id: 'address_port',
|
id: 'address_port',
|
||||||
header: `${t('address')}:${t('port')}`,
|
header: `${t('address')}:${t('port')}`,
|
||||||
cell: ({ row }) => (row.original.address || '—') + ':' + (row.original.port ?? '—'),
|
cell: ({ row }) => `${row.original.address || '—'}:${row.original.port || '—'}`,
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
id: 'server_id',
|
id: 'server_id',
|
||||||
header: t('server'),
|
header: t('server'),
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) =>
|
||||||
<div className='flex flex-wrap gap-2'>
|
`${getServerName(row.original.server_id)}:${getServerAddress(row.original.server_id)}`,
|
||||||
<Badge variant='outline'>
|
},
|
||||||
{getServerName(row.original.server_id)} ·{' '}
|
{
|
||||||
{getServerOriginAddr(row.original.server_id)}
|
id: 'protocol',
|
||||||
</Badge>
|
header: ` ${t('protocol')}:${t('port')}`,
|
||||||
<Badge variant='outline'>
|
cell: ({ row }) =>
|
||||||
{row.original.protocol || '—'} ·{' '}
|
`${row.original.protocol}:${getProtocolPort(row.original.server_id, row.original.protocol)}`,
|
||||||
{getProtocolOriginPort(row.original.server_id, row.original.protocol)}
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'tags',
|
accessorKey: 'tags',
|
||||||
@@ -163,6 +148,8 @@ export default function NodesPage() {
|
|||||||
await updateNode(body);
|
await updateNode(body);
|
||||||
toast.success(t('updated'));
|
toast.success(t('updated'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchNodes();
|
||||||
|
fetchTags();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -180,6 +167,8 @@ export default function NodesPage() {
|
|||||||
await deleteNode({ id: row.id } as any);
|
await deleteNode({ id: row.id } as any);
|
||||||
toast.success(t('deleted'));
|
toast.success(t('deleted'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchNodes();
|
||||||
|
fetchTags();
|
||||||
}}
|
}}
|
||||||
cancelText={t('cancel')}
|
cancelText={t('cancel')}
|
||||||
confirmText={t('confirm')}
|
confirmText={t('confirm')}
|
||||||
@@ -195,6 +184,8 @@ export default function NodesPage() {
|
|||||||
});
|
});
|
||||||
toast.success(t('copied'));
|
toast.success(t('copied'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchNodes();
|
||||||
|
fetchTags();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t('copy')}
|
{t('copy')}
|
||||||
@@ -211,6 +202,8 @@ export default function NodesPage() {
|
|||||||
await Promise.all(rows.map((r) => deleteNode({ id: r.id } as any)));
|
await Promise.all(rows.map((r) => deleteNode({ id: r.id } as any)));
|
||||||
toast.success(t('deleted'));
|
toast.success(t('deleted'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchNodes();
|
||||||
|
fetchTags();
|
||||||
}}
|
}}
|
||||||
cancelText={t('cancel')}
|
cancelText={t('cancel')}
|
||||||
confirmText={t('confirm')}
|
confirmText={t('confirm')}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useSearchParams } from 'next/navigation';
|
import { useSearchParams } from 'next/navigation';
|
||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
@@ -8,7 +7,7 @@ import { useRef } from 'react';
|
|||||||
import { Display } from '@/components/display';
|
import { Display } from '@/components/display';
|
||||||
import { ProTable, ProTableActions } from '@/components/pro-table';
|
import { ProTable, ProTableActions } from '@/components/pro-table';
|
||||||
import { getOrderList, updateOrderStatus } from '@/services/admin/order';
|
import { getOrderList, updateOrderStatus } from '@/services/admin/order';
|
||||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
import { useSubscribe } from '@/store/subscribe';
|
||||||
import { formatDate } from '@/utils/common';
|
import { formatDate } from '@/utils/common';
|
||||||
import { Badge } from '@workspace/ui/components/badge';
|
import { Badge } from '@workspace/ui/components/badge';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
@@ -32,16 +31,7 @@ export default function Page() {
|
|||||||
|
|
||||||
const ref = useRef<ProTableActions>(null);
|
const ref = useRef<ProTableActions>(null);
|
||||||
|
|
||||||
const { data: subscribeList } = useQuery({
|
const { subscribes, getSubscribeName } = useSubscribe();
|
||||||
queryKey: ['getSubscribeList', 'all'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await getSubscribeList({
|
|
||||||
page: 1,
|
|
||||||
size: 999999999,
|
|
||||||
});
|
|
||||||
return data.data?.list as API.SubscribeGroup[];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const initialFilters = {
|
const initialFilters = {
|
||||||
search: sp.get('search') || undefined,
|
search: sp.get('search') || undefined,
|
||||||
@@ -68,9 +58,10 @@ export default function Page() {
|
|||||||
accessorKey: 'subscribe_id',
|
accessorKey: 'subscribe_id',
|
||||||
header: t('subscribe'),
|
header: t('subscribe'),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const name = subscribeList?.find(
|
if (row.original.type === 4) {
|
||||||
(item) => item.id === row.getValue('subscribe_id'),
|
return t(`type.${row.getValue('type')}`);
|
||||||
)?.name;
|
}
|
||||||
|
const name = getSubscribeName(row.getValue('subscribe_id'));
|
||||||
const quantity = row.original.quantity;
|
const quantity = row.original.quantity;
|
||||||
return name ? `${name} × ${quantity}` : '';
|
return name ? `${name} × ${quantity}` : '';
|
||||||
},
|
},
|
||||||
@@ -186,8 +177,8 @@ export default function Page() {
|
|||||||
{
|
{
|
||||||
key: 'subscribe_id',
|
key: 'subscribe_id',
|
||||||
placeholder: `${t('subscribe')}`,
|
placeholder: `${t('subscribe')}`,
|
||||||
options: subscribeList?.map((item) => ({
|
options: subscribes?.map((item) => ({
|
||||||
label: item.name,
|
label: item.name!,
|
||||||
value: String(item.id),
|
value: String(item.id),
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import { getTranslations } from 'next-intl/server';
|
|
||||||
|
|
||||||
import SubscribeTable from './subscribe-table';
|
import SubscribeTable from './subscribe-table';
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const t = await getTranslations('product');
|
|
||||||
|
|
||||||
return <SubscribeTable />;
|
return <SubscribeTable />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { filterNodeList, queryNodeTag } from '@/services/admin/server';
|
import { useNode } from '@/store/node';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import {
|
import {
|
||||||
Accordion,
|
Accordion,
|
||||||
AccordionContent,
|
AccordionContent,
|
||||||
@@ -229,35 +228,9 @@ export default function SubscribeForm<T extends Record<string, any>>({
|
|||||||
if (bool) setOpen(false);
|
if (bool) setOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: nodes } = useQuery({
|
const { nodes, getAllAvailableTags, getNodesByTag, getNodesWithoutTags } = useNode();
|
||||||
queryKey: ['filterNodeListAll'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await filterNodeList({ page: 1, size: 999999999 });
|
|
||||||
return (data.data?.list || []) as API.Node[];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data: allTagsData } = useQuery({
|
const tagGroups = getAllAvailableTags();
|
||||||
queryKey: ['queryNodeTag'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await queryNodeTag();
|
|
||||||
return data?.data?.tags || [];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const nodeExtractedTags = Array.from(
|
|
||||||
new Set(
|
|
||||||
((nodes as API.Node[]) || [])
|
|
||||||
.flatMap((n) => (Array.isArray(n.tags) ? n.tags : []))
|
|
||||||
.filter(Boolean),
|
|
||||||
),
|
|
||||||
) as string[];
|
|
||||||
|
|
||||||
const allAvailableTags = (allTagsData as string[]) || [];
|
|
||||||
|
|
||||||
const tagGroups = Array.from(new Set([...allAvailableTags, ...nodeExtractedTags])).filter(
|
|
||||||
Boolean,
|
|
||||||
);
|
|
||||||
|
|
||||||
const unit_time = form.watch('unit_time');
|
const unit_time = form.watch('unit_time');
|
||||||
|
|
||||||
@@ -806,10 +779,7 @@ export default function SubscribeForm<T extends Record<string, any>>({
|
|||||||
{tagGroups.map((tag) => {
|
{tagGroups.map((tag) => {
|
||||||
const value = field.value || [];
|
const value = field.value || [];
|
||||||
const tagId = tag;
|
const tagId = tag;
|
||||||
const nodesWithTag =
|
const nodesWithTag = getNodesByTag(tag);
|
||||||
(nodes as API.Node[])?.filter((n) =>
|
|
||||||
(n.tags || []).includes(tag),
|
|
||||||
) || [];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AccordionItem key={tag} value={String(tag)}>
|
<AccordionItem key={tag} value={String(tag)}>
|
||||||
@@ -836,22 +806,20 @@ export default function SubscribeForm<T extends Record<string, any>>({
|
|||||||
</AccordionTrigger>
|
</AccordionTrigger>
|
||||||
<AccordionContent>
|
<AccordionContent>
|
||||||
<ul className='space-y-1'>
|
<ul className='space-y-1'>
|
||||||
{(nodes as API.Node[])
|
{getNodesByTag(tag).map((node) => (
|
||||||
?.filter((n) => (n.tags || []).includes(tag))
|
<li
|
||||||
?.map((node) => (
|
key={node.id}
|
||||||
<li
|
className='flex items-center justify-between gap-3'
|
||||||
key={node.id}
|
>
|
||||||
className='flex items-center justify-between gap-3'
|
<span className='flex-1'>{node.name}</span>
|
||||||
>
|
<span className='flex-1'>
|
||||||
<span className='flex-1'>{node.name}</span>
|
{node.address}:{node.port}
|
||||||
<span className='flex-1'>
|
</span>
|
||||||
{node.address}:{node.port}
|
<span className='flex-1 text-right'>
|
||||||
</span>
|
{node.protocol}
|
||||||
<span className='flex-1 text-right'>
|
</span>
|
||||||
{node.protocol}
|
</li>
|
||||||
</span>
|
))}
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
</ul>
|
||||||
</AccordionContent>
|
</AccordionContent>
|
||||||
</AccordionItem>
|
</AccordionItem>
|
||||||
@@ -872,34 +840,32 @@ export default function SubscribeForm<T extends Record<string, any>>({
|
|||||||
<FormLabel>{t('form.node')}</FormLabel>
|
<FormLabel>{t('form.node')}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<div className='flex flex-col gap-2'>
|
<div className='flex flex-col gap-2'>
|
||||||
{(nodes as API.Node[])
|
{getNodesWithoutTags().map((item) => {
|
||||||
?.filter((item) => (item.tags || []).length === 0)
|
const value = field.value || [];
|
||||||
?.map((item) => {
|
|
||||||
const value = field.value || [];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex items-center gap-2' key={item.id}>
|
<div className='flex items-center gap-2' key={item.id}>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={value.includes(item.id!)}
|
checked={value.includes(item.id!)}
|
||||||
onCheckedChange={(checked) => {
|
onCheckedChange={(checked) => {
|
||||||
return checked
|
return checked
|
||||||
? form.setValue(field.name, [...value, item.id])
|
? form.setValue(field.name, [...value, item.id])
|
||||||
: form.setValue(
|
: form.setValue(
|
||||||
field.name,
|
field.name,
|
||||||
value.filter((value: number) => value !== item.id),
|
value.filter((value: number) => value !== item.id),
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Label className='flex w-full items-center justify-between gap-3'>
|
<Label className='flex w-full items-center justify-between gap-3'>
|
||||||
<span className='flex-1'>{item.name}</span>
|
<span className='flex-1'>{item.name}</span>
|
||||||
<span className='flex-1'>
|
<span className='flex-1'>
|
||||||
{item.address}:{item.port}
|
{item.address}:{item.port}
|
||||||
</span>
|
</span>
|
||||||
<span className='flex-1 text-right'>{item.protocol}</span>
|
<span className='flex-1 text-right'>{item.protocol}</span>
|
||||||
</Label>
|
</Label>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
subscribeSort,
|
subscribeSort,
|
||||||
updateSubscribe,
|
updateSubscribe,
|
||||||
} from '@/services/admin/subscribe';
|
} from '@/services/admin/subscribe';
|
||||||
|
import { useSubscribe } from '@/store/subscribe';
|
||||||
import { Badge } from '@workspace/ui/components/badge';
|
import { Badge } from '@workspace/ui/components/badge';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import { Switch } from '@workspace/ui/components/switch';
|
import { Switch } from '@workspace/ui/components/switch';
|
||||||
@@ -23,6 +24,7 @@ export default function SubscribeTable() {
|
|||||||
const t = useTranslations('product');
|
const t = useTranslations('product');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const ref = useRef<ProTableActions>(null);
|
const ref = useRef<ProTableActions>(null);
|
||||||
|
const { fetchSubscribes } = useSubscribe();
|
||||||
return (
|
return (
|
||||||
<ProTable<API.SubscribeItem, { group_id: number; query: string }>
|
<ProTable<API.SubscribeItem, { group_id: number; query: string }>
|
||||||
action={ref}
|
action={ref}
|
||||||
@@ -42,6 +44,7 @@ export default function SubscribeTable() {
|
|||||||
});
|
});
|
||||||
toast.success(t('createSuccess'));
|
toast.success(t('createSuccess'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchSubscribes();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -83,6 +86,7 @@ export default function SubscribeTable() {
|
|||||||
show: checked,
|
show: checked,
|
||||||
} as API.UpdateSubscribeRequest);
|
} as API.UpdateSubscribeRequest);
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchSubscribes();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -101,6 +105,7 @@ export default function SubscribeTable() {
|
|||||||
sell: checked,
|
sell: checked,
|
||||||
} as API.UpdateSubscribeRequest);
|
} as API.UpdateSubscribeRequest);
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchSubscribes();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -186,6 +191,7 @@ export default function SubscribeTable() {
|
|||||||
} as API.UpdateSubscribeRequest);
|
} as API.UpdateSubscribeRequest);
|
||||||
toast.success(t('updateSuccess'));
|
toast.success(t('updateSuccess'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchSubscribes();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -206,6 +212,7 @@ export default function SubscribeTable() {
|
|||||||
});
|
});
|
||||||
toast.success(t('deleteSuccess'));
|
toast.success(t('deleteSuccess'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchSubscribes();
|
||||||
}}
|
}}
|
||||||
cancelText={t('cancel')}
|
cancelText={t('cancel')}
|
||||||
confirmText={t('confirm')}
|
confirmText={t('confirm')}
|
||||||
@@ -224,6 +231,7 @@ export default function SubscribeTable() {
|
|||||||
} as API.CreateSubscribeRequest);
|
} as API.CreateSubscribeRequest);
|
||||||
toast.success(t('copySuccess'));
|
toast.success(t('copySuccess'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchSubscribes();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -248,6 +256,7 @@ export default function SubscribeTable() {
|
|||||||
|
|
||||||
toast.success(t('deleteSuccess'));
|
toast.success(t('deleteSuccess'));
|
||||||
ref.current?.reset();
|
ref.current?.reset();
|
||||||
|
fetchSubscribes();
|
||||||
}}
|
}}
|
||||||
cancelText={t('cancel')}
|
cancelText={t('cancel')}
|
||||||
confirmText={t('confirm')}
|
confirmText={t('confirm')}
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ export function getProtocolDefaultConfig(proto: ProtocolType) {
|
|||||||
case 'mieru':
|
case 'mieru':
|
||||||
return {
|
return {
|
||||||
type: 'mieru',
|
type: 'mieru',
|
||||||
|
enable: false,
|
||||||
port: null,
|
port: null,
|
||||||
multiplex: 'none',
|
multiplex: 'none',
|
||||||
transport: 'tcp',
|
transport: 'tcp',
|
||||||
@@ -98,6 +99,7 @@ export function getProtocolDefaultConfig(proto: ProtocolType) {
|
|||||||
case 'anytls':
|
case 'anytls':
|
||||||
return {
|
return {
|
||||||
type: 'anytls',
|
type: 'anytls',
|
||||||
|
enable: false,
|
||||||
port: null,
|
port: null,
|
||||||
security: 'tls',
|
security: 'tls',
|
||||||
padding_scheme: null,
|
padding_scheme: null,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export {
|
|||||||
} from './constants';
|
} from './constants';
|
||||||
|
|
||||||
// Re-export all types
|
// Re-export all types
|
||||||
export type { FieldConfig, ProtocolType, ServerFormValues } from './types';
|
export type { FieldConfig, ProtocolType } from './types';
|
||||||
|
|
||||||
// Re-export all schemas
|
// Re-export all schemas
|
||||||
export { formSchema, protocolApiScheme } from './schemas';
|
export { formSchema, protocolApiScheme } from './schemas';
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
import { protocols } from './constants';
|
import { protocols } from './constants';
|
||||||
import { formSchema } from './schemas';
|
|
||||||
|
|
||||||
export type FieldConfig = {
|
export type FieldConfig = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -22,6 +20,4 @@ export type FieldConfig = {
|
|||||||
gridSpan?: 1 | 2;
|
gridSpan?: 1 | 2;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ServerFormValues = z.infer<typeof formSchema>;
|
|
||||||
|
|
||||||
export type ProtocolType = (typeof protocols)[number];
|
export type ProtocolType = (typeof protocols)[number];
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
SheetTrigger,
|
SheetTrigger,
|
||||||
} from '@workspace/ui/components/sheet';
|
} from '@workspace/ui/components/sheet';
|
||||||
import { formatBytes } from '@workspace/ui/utils';
|
import { formatBytes } from '@workspace/ui/utils';
|
||||||
|
import { Users } from 'lucide-react';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
@@ -92,8 +93,7 @@ export default function OnlineUsersCell({ status }: { status?: API.ServerStatus
|
|||||||
<Sheet open={open} onOpenChange={setOpen}>
|
<Sheet open={open} onOpenChange={setOpen}>
|
||||||
<SheetTrigger asChild>
|
<SheetTrigger asChild>
|
||||||
<button className='hover:text-foreground text-muted-foreground flex items-center gap-2 bg-transparent p-0 text-sm'>
|
<button className='hover:text-foreground text-muted-foreground flex items-center gap-2 bg-transparent p-0 text-sm'>
|
||||||
<Badge variant='secondary'>{status?.online.length}</Badge>
|
<Users className='h-4 w-4' /> {status?.online.length}
|
||||||
<span>{t('onlineUsers')}</span>
|
|
||||||
</button>
|
</button>
|
||||||
</SheetTrigger>
|
</SheetTrigger>
|
||||||
<SheetContent className='h-screen w-screen max-w-none sm:h-auto sm:w-[900px] sm:max-w-[90vw]'>
|
<SheetContent className='h-screen w-screen max-w-none sm:h-auto sm:w-[900px] sm:max-w-[90vw]'>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
// Online users detail moved to separate component
|
|
||||||
import { ProTable, ProTableActions } from '@/components/pro-table';
|
import { ProTable, ProTableActions } from '@/components/pro-table';
|
||||||
import {
|
import {
|
||||||
createServer,
|
createServer,
|
||||||
@@ -10,6 +10,8 @@ import {
|
|||||||
resetSortWithServer,
|
resetSortWithServer,
|
||||||
updateServer,
|
updateServer,
|
||||||
} from '@/services/admin/server';
|
} from '@/services/admin/server';
|
||||||
|
import { useNode } from '@/store/node';
|
||||||
|
import { useServer } from '@/store/server';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { Badge } from '@workspace/ui/components/badge';
|
import { Badge } from '@workspace/ui/components/badge';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
@@ -23,18 +25,6 @@ import OnlineUsersCell from './online-users-cell';
|
|||||||
import ServerConfig from './server-config';
|
import ServerConfig from './server-config';
|
||||||
import ServerForm from './server-form';
|
import ServerForm from './server-form';
|
||||||
|
|
||||||
type ProtocolName = 'shadowsocks' | 'vmess' | 'vless' | 'trojan' | 'hysteria2' | 'tuic' | 'anytls';
|
|
||||||
|
|
||||||
const PROTOCOL_COLORS: Record<ProtocolName, string> = {
|
|
||||||
shadowsocks: 'bg-green-500',
|
|
||||||
vmess: 'bg-rose-500',
|
|
||||||
vless: 'bg-blue-500',
|
|
||||||
trojan: 'bg-yellow-500',
|
|
||||||
hysteria2: 'bg-purple-500',
|
|
||||||
tuic: 'bg-cyan-500',
|
|
||||||
anytls: 'bg-gray-500',
|
|
||||||
};
|
|
||||||
|
|
||||||
function PctBar({ value }: { value: number }) {
|
function PctBar({ value }: { value: number }) {
|
||||||
const v = value.toFixed(2);
|
const v = value.toFixed(2);
|
||||||
return (
|
return (
|
||||||
@@ -69,6 +59,8 @@ function RegionIpCell({
|
|||||||
|
|
||||||
export default function ServersPage() {
|
export default function ServersPage() {
|
||||||
const t = useTranslations('servers');
|
const t = useTranslations('servers');
|
||||||
|
const { isServerReferencedByNodes } = useNode();
|
||||||
|
const { fetchServers } = useServer();
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [migrating, setMigrating] = useState(false);
|
const [migrating, setMigrating] = useState(false);
|
||||||
@@ -129,6 +121,7 @@ export default function ServersPage() {
|
|||||||
await createServer(values as unknown as API.CreateServerRequest);
|
await createServer(values as unknown as API.CreateServerRequest);
|
||||||
toast.success(t('created'));
|
toast.success(t('created'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchServers();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -163,23 +156,16 @@ export default function ServersPage() {
|
|||||||
accessorKey: 'protocols',
|
accessorKey: 'protocols',
|
||||||
header: t('protocols'),
|
header: t('protocols'),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const list = (row.original.protocols || []) as API.Protocol[];
|
const list = row.original.protocols.filter(
|
||||||
if (!list.length) return t('noData');
|
(p) => p.enable !== false,
|
||||||
|
) as API.Protocol[];
|
||||||
|
if (!list.length) return '—';
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-wrap gap-1'>
|
<div className='flex flex-wrap gap-1'>
|
||||||
{list.map((p, idx) => {
|
{list.map((p, idx) => {
|
||||||
const proto = ((p as any)?.type || '') as ProtocolName | '';
|
|
||||||
if (!proto) return null;
|
|
||||||
const color = PROTOCOL_COLORS[proto as ProtocolName];
|
|
||||||
const port = (p as any)?.port as number | undefined;
|
|
||||||
const label = `${proto}${port ? ` (${port})` : ''}`;
|
|
||||||
return (
|
return (
|
||||||
<Badge
|
<Badge key={idx} variant='outline'>
|
||||||
key={idx}
|
{p.type} ({p.port})
|
||||||
variant='outline'
|
|
||||||
className={cn('text-primary-foreground', color)}
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</Badge>
|
</Badge>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -272,6 +258,7 @@ export default function ServersPage() {
|
|||||||
});
|
});
|
||||||
toast.success(t('updated'));
|
toast.success(t('updated'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchServers();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -282,13 +269,18 @@ export default function ServersPage() {
|
|||||||
/>,
|
/>,
|
||||||
<ConfirmButton
|
<ConfirmButton
|
||||||
key='delete'
|
key='delete'
|
||||||
trigger={<Button variant='destructive'>{t('delete')}</Button>}
|
trigger={
|
||||||
|
<Button variant='destructive' disabled={isServerReferencedByNodes(row.id)}>
|
||||||
|
{t('delete')}
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
title={t('confirmDeleteTitle')}
|
title={t('confirmDeleteTitle')}
|
||||||
description={t('confirmDeleteDesc')}
|
description={t('confirmDeleteDesc')}
|
||||||
onConfirm={async () => {
|
onConfirm={async () => {
|
||||||
await deleteServer({ id: row.id } as any);
|
await deleteServer({ id: row.id } as any);
|
||||||
toast.success(t('deleted'));
|
toast.success(t('deleted'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchServers();
|
||||||
}}
|
}}
|
||||||
cancelText={t('cancel')}
|
cancelText={t('cancel')}
|
||||||
confirmText={t('confirm')}
|
confirmText={t('confirm')}
|
||||||
@@ -311,6 +303,7 @@ export default function ServersPage() {
|
|||||||
await createServer(body);
|
await createServer(body);
|
||||||
toast.success(t('copied'));
|
toast.success(t('copied'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchServers();
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -318,16 +311,22 @@ export default function ServersPage() {
|
|||||||
</Button>,
|
</Button>,
|
||||||
],
|
],
|
||||||
batchRender(rows) {
|
batchRender(rows) {
|
||||||
|
const hasReferencedServers = rows.some((row) => isServerReferencedByNodes(row.id));
|
||||||
return [
|
return [
|
||||||
<ConfirmButton
|
<ConfirmButton
|
||||||
key='delete'
|
key='delete'
|
||||||
trigger={<Button variant='destructive'>{t('delete')}</Button>}
|
trigger={
|
||||||
|
<Button variant='destructive' disabled={hasReferencedServers}>
|
||||||
|
{t('delete')}
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
title={t('confirmDeleteTitle')}
|
title={t('confirmDeleteTitle')}
|
||||||
description={t('confirmDeleteDesc')}
|
description={t('confirmDeleteDesc')}
|
||||||
onConfirm={async () => {
|
onConfirm={async () => {
|
||||||
await Promise.all(rows.map((r) => deleteServer({ id: r.id })));
|
await Promise.all(rows.map((r) => deleteServer({ id: r.id })));
|
||||||
toast.success(t('deleted'));
|
toast.success(t('deleted'));
|
||||||
ref.current?.refresh();
|
ref.current?.refresh();
|
||||||
|
fetchServers();
|
||||||
}}
|
}}
|
||||||
cancelText={t('cancel')}
|
cancelText={t('cancel')}
|
||||||
confirmText={t('confirm')}
|
confirmText={t('confirm')}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import { ChartContainer, ChartTooltip } from '@workspace/ui/components/chart';
|
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
@@ -35,65 +35,11 @@ import { Icon } from '@workspace/ui/custom-components/icon';
|
|||||||
import { DicesIcon } from 'lucide-react';
|
import { DicesIcon } from 'lucide-react';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { uid } from 'radash';
|
import { uid } from 'radash';
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { Cell, Legend, Pie, PieChart } from 'recharts';
|
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
const COLORS = [
|
|
||||||
'hsl(var(--chart-1))',
|
|
||||||
'hsl(var(--chart-2))',
|
|
||||||
'hsl(var(--chart-3))',
|
|
||||||
'hsl(var(--chart-4))',
|
|
||||||
'hsl(var(--chart-5))',
|
|
||||||
];
|
|
||||||
|
|
||||||
const MINUTES_IN_DAY = 1440;
|
|
||||||
|
|
||||||
function getTimeRangeData(slots: API.TimePeriod[]) {
|
|
||||||
const timePoints = slots
|
|
||||||
.filter((slot) => slot.start_time && slot.end_time)
|
|
||||||
.flatMap((slot) => {
|
|
||||||
const [startH = 0, startM = 0] = slot.start_time.split(':').map(Number);
|
|
||||||
const [endH = 0, endM = 0] = slot.end_time.split(':').map(Number);
|
|
||||||
const start = startH * 60 + startM;
|
|
||||||
let end = endH * 60 + endM;
|
|
||||||
if (end < start) end += MINUTES_IN_DAY;
|
|
||||||
return { start, end, multiplier: slot.multiplier };
|
|
||||||
})
|
|
||||||
.sort((a, b) => a.start - b.start);
|
|
||||||
|
|
||||||
const result: { name: string; value: number; multiplier: number }[] = [];
|
|
||||||
let currentMinute = 0;
|
|
||||||
|
|
||||||
timePoints.forEach((point) => {
|
|
||||||
if (point.start > currentMinute) {
|
|
||||||
result.push({
|
|
||||||
name: `${Math.floor(currentMinute / 60)}:${String(currentMinute % 60).padStart(2, '0')} - ${Math.floor(point.start / 60)}:${String(point.start % 60).padStart(2, '0')}`,
|
|
||||||
value: point.start - currentMinute,
|
|
||||||
multiplier: 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
result.push({
|
|
||||||
name: `${Math.floor(point.start / 60)}:${String(point.start % 60).padStart(2, '0')} - ${Math.floor((point.end / 60) % 24)}:${String(point.end % 60).padStart(2, '0')}`,
|
|
||||||
value: point.end - point.start,
|
|
||||||
multiplier: point.multiplier,
|
|
||||||
});
|
|
||||||
currentMinute = point.end % MINUTES_IN_DAY;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (currentMinute < MINUTES_IN_DAY) {
|
|
||||||
result.push({
|
|
||||||
name: `${Math.floor(currentMinute / 60)}:${String(currentMinute % 60).padStart(2, '0')} - 24:00`,
|
|
||||||
value: MINUTES_IN_DAY - currentMinute,
|
|
||||||
multiplier: 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodeConfigSchema = z.object({
|
const nodeConfigSchema = z.object({
|
||||||
node_secret: z.string().optional(),
|
node_secret: z.string().optional(),
|
||||||
node_pull_interval: z.number().optional(),
|
node_pull_interval: z.number().optional(),
|
||||||
@@ -150,20 +96,6 @@ export default function ServerConfig() {
|
|||||||
}
|
}
|
||||||
}, [periodsResp]);
|
}, [periodsResp]);
|
||||||
|
|
||||||
const chartTimeSlots = useMemo(() => getTimeRangeData(timeSlots), [timeSlots]);
|
|
||||||
const chartConfig = useMemo(() => {
|
|
||||||
return chartTimeSlots.reduce(
|
|
||||||
(acc, item, index) => {
|
|
||||||
acc[item.name] = {
|
|
||||||
label: item.name,
|
|
||||||
color: COLORS[index % COLORS.length] || 'hsl(var(--default-chart-color))',
|
|
||||||
};
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{} as Record<string, { label: string; color: string }>,
|
|
||||||
);
|
|
||||||
}, [chartTimeSlots]);
|
|
||||||
|
|
||||||
async function onSubmit(values: NodeConfigFormData) {
|
async function onSubmit(values: NodeConfigFormData) {
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
try {
|
try {
|
||||||
@@ -293,8 +225,8 @@ export default function ServerConfig() {
|
|||||||
{t('config.dynamicMultiplierDescription')}
|
{t('config.dynamicMultiplierDescription')}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className='flex flex-col-reverse gap-8 md:flex-row md:items-start'>
|
<div className='flex flex-col gap-2'>
|
||||||
<div className='w-full md:w-1/2'>
|
<div className='w-full'>
|
||||||
<ArrayInput<API.TimePeriod>
|
<ArrayInput<API.TimePeriod>
|
||||||
fields={[
|
fields={[
|
||||||
{ name: 'start_time', prefix: t('config.startTime'), type: 'time' },
|
{ name: 'start_time', prefix: t('config.startTime'), type: 'time' },
|
||||||
@@ -311,74 +243,18 @@ export default function ServerConfig() {
|
|||||||
/>
|
/>
|
||||||
<div className='mt-3 flex gap-2'>
|
<div className='mt-3 flex gap-2'>
|
||||||
<Button
|
<Button
|
||||||
|
type='button'
|
||||||
size='sm'
|
size='sm'
|
||||||
variant='outline'
|
variant='outline'
|
||||||
onClick={() => setTimeSlots(periodsResp || [])}
|
onClick={() => setTimeSlots(periodsResp || [])}
|
||||||
>
|
>
|
||||||
{t('config.reset')}
|
{t('config.reset')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button size='sm' onClick={savePeriods}>
|
<Button size='sm' type='button' onClick={savePeriods}>
|
||||||
{t('config.save')}
|
{t('config.save')}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='w-full md:w-1/2'>
|
|
||||||
<ChartContainer
|
|
||||||
config={chartConfig}
|
|
||||||
className='mx-auto aspect-[4/3] max-w-[400px]'
|
|
||||||
>
|
|
||||||
<PieChart>
|
|
||||||
<Pie
|
|
||||||
data={chartTimeSlots}
|
|
||||||
cx='50%'
|
|
||||||
cy='50%'
|
|
||||||
labelLine={false}
|
|
||||||
outerRadius='80%'
|
|
||||||
fill='#8884d8'
|
|
||||||
dataKey='value'
|
|
||||||
label={({ percent, multiplier }) =>
|
|
||||||
`${(multiplier || 0)?.toFixed(2)}x (${(percent * 100).toFixed(0)}%)`
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{chartTimeSlots.map((entry, index) => (
|
|
||||||
<Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
|
|
||||||
))}
|
|
||||||
</Pie>
|
|
||||||
<ChartTooltip
|
|
||||||
content={({ payload }) => {
|
|
||||||
if (payload && payload.length) {
|
|
||||||
const d = payload[0]?.payload as any;
|
|
||||||
return (
|
|
||||||
<div className='bg-background rounded-lg border p-2 shadow-sm'>
|
|
||||||
<div className='grid grid-cols-2 gap-2'>
|
|
||||||
<div className='flex flex-col'>
|
|
||||||
<span className='text-muted-foreground text-[0.70rem] uppercase'>
|
|
||||||
{t('config.timeSlot')}
|
|
||||||
</span>
|
|
||||||
<span className='text-muted-foreground font-bold'>
|
|
||||||
{d.name || '—'}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className='flex flex-col'>
|
|
||||||
<span className='text-muted-foreground text-[0.70rem] uppercase'>
|
|
||||||
{t('config.multiplier')}
|
|
||||||
</span>
|
|
||||||
<span className='font-bold'>
|
|
||||||
{Number(d.multiplier).toFixed(2)}x
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Legend />
|
|
||||||
</PieChart>
|
|
||||||
</ChartContainer>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useNode } from '@/store/node';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import {
|
import {
|
||||||
Accordion,
|
Accordion,
|
||||||
@@ -48,7 +49,6 @@ import {
|
|||||||
getProtocolDefaultConfig,
|
getProtocolDefaultConfig,
|
||||||
PROTOCOL_FIELDS,
|
PROTOCOL_FIELDS,
|
||||||
protocols as PROTOCOLS,
|
protocols as PROTOCOLS,
|
||||||
ServerFormValues,
|
|
||||||
} from './form-schema';
|
} from './form-schema';
|
||||||
|
|
||||||
function DynamicField({
|
function DynamicField({
|
||||||
@@ -321,14 +321,16 @@ export default function ServerForm(props: {
|
|||||||
trigger: string;
|
trigger: string;
|
||||||
title: string;
|
title: string;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
initialValues?: Partial<ServerFormValues>;
|
initialValues?: Partial<API.Server>;
|
||||||
onSubmit: (values: ServerFormValues) => Promise<boolean> | boolean;
|
onSubmit: (values: Partial<API.Server>) => Promise<boolean> | boolean;
|
||||||
}) {
|
}) {
|
||||||
const { trigger, title, loading, initialValues, onSubmit } = props;
|
const { trigger, title, loading, initialValues, onSubmit } = props;
|
||||||
const t = useTranslations('servers');
|
const t = useTranslations('servers');
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [accordionValue, setAccordionValue] = useState<string>();
|
const [accordionValue, setAccordionValue] = useState<string>();
|
||||||
|
|
||||||
|
const { isProtocolUsedInNodes } = useNode();
|
||||||
|
|
||||||
const form = useForm({
|
const form = useForm({
|
||||||
resolver: zodResolver(formSchema),
|
resolver: zodResolver(formSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
@@ -337,7 +339,7 @@ export default function ServerForm(props: {
|
|||||||
country: '',
|
country: '',
|
||||||
city: '',
|
city: '',
|
||||||
ratio: 1,
|
ratio: 1,
|
||||||
protocols: [],
|
protocols: [] as any[],
|
||||||
...initialValues,
|
...initialValues,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -515,6 +517,7 @@ export default function ServerForm(props: {
|
|||||||
PROTOCOLS.findIndex((t) => t === type),
|
PROTOCOLS.findIndex((t) => t === type),
|
||||||
);
|
);
|
||||||
const current = (protocolsValues[i] || {}) as Record<string, any>;
|
const current = (protocolsValues[i] || {}) as Record<string, any>;
|
||||||
|
const isEnabled = current?.enable !== false;
|
||||||
const fields = PROTOCOL_FIELDS[type] || [];
|
const fields = PROTOCOL_FIELDS[type] || [];
|
||||||
return (
|
return (
|
||||||
<AccordionItem key={type} value={type} className='mb-2 rounded-lg border'>
|
<AccordionItem key={type} value={type} className='mb-2 rounded-lg border'>
|
||||||
@@ -539,16 +542,20 @@ export default function ServerForm(props: {
|
|||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
'text-xs',
|
'text-xs',
|
||||||
current.enable ? 'text-green-500' : 'text-muted-foreground',
|
isEnabled ? 'text-green-500' : 'text-muted-foreground',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{current.enable ? t('enabled') : t('disabled')}
|
{isEnabled ? t('enabled') : t('disabled')}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Switch
|
<Switch
|
||||||
className='mr-2'
|
className='mr-2'
|
||||||
checked={!!current.enable}
|
checked={!!isEnabled}
|
||||||
|
disabled={Boolean(
|
||||||
|
initialValues?.id &&
|
||||||
|
isProtocolUsedInNodes(initialValues?.id || 0, type),
|
||||||
|
)}
|
||||||
onCheckedChange={(checked) => {
|
onCheckedChange={(checked) => {
|
||||||
form.setValue(`protocols.${i}.enable`, checked);
|
form.setValue(`protocols.${i}.enable`, checked);
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ import { useRef, useState } from 'react';
|
|||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
import { subscribeSchema } from './schema';
|
||||||
import { TemplatePreview } from './template-preview';
|
import { TemplatePreview } from './template-preview';
|
||||||
|
|
||||||
const createClientFormSchema = (t: any) =>
|
const createClientFormSchema = (t: any) =>
|
||||||
@@ -662,137 +663,7 @@ export function ProtocolForm() {
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<GoTemplateEditor
|
<GoTemplateEditor
|
||||||
showLineNumbers
|
showLineNumbers
|
||||||
schema={{
|
schema={subscribeSchema}
|
||||||
SiteName: { type: 'string', description: 'Site name' },
|
|
||||||
SubscribeName: { type: 'string', description: 'Subscribe name' },
|
|
||||||
Proxies: {
|
|
||||||
type: 'array',
|
|
||||||
description: 'Array of proxy nodes',
|
|
||||||
items: {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
Name: { type: 'string', description: 'Node name' },
|
|
||||||
Server: { type: 'string', description: 'Server host' },
|
|
||||||
Port: { type: 'number', description: 'Server port' },
|
|
||||||
Type: { type: 'string', description: 'Proxy type' },
|
|
||||||
Tags: {
|
|
||||||
type: 'array',
|
|
||||||
description: 'Node tags',
|
|
||||||
items: { type: 'string' },
|
|
||||||
},
|
|
||||||
Sort: { type: 'number', description: 'Node sort order' },
|
|
||||||
// Security Options
|
|
||||||
Security: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Security protocol',
|
|
||||||
},
|
|
||||||
SNI: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Server Name Indication for TLS',
|
|
||||||
},
|
|
||||||
AllowInsecure: {
|
|
||||||
type: 'boolean',
|
|
||||||
description:
|
|
||||||
'Allow insecure connections (skip certificate verification)',
|
|
||||||
},
|
|
||||||
Fingerprint: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Client fingerprint for TLS connections',
|
|
||||||
},
|
|
||||||
RealityServerAddr: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Reality server address',
|
|
||||||
},
|
|
||||||
RealityServerPort: {
|
|
||||||
type: 'number',
|
|
||||||
description: 'Reality server port',
|
|
||||||
},
|
|
||||||
RealityPrivateKey: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Reality private key for authentication',
|
|
||||||
},
|
|
||||||
RealityPublicKey: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Reality public key for authentication',
|
|
||||||
},
|
|
||||||
RealityShortId: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Reality short ID for authentication',
|
|
||||||
},
|
|
||||||
// Transport Options
|
|
||||||
Transport: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Transport protocol (e.g., ws, http, grpc)',
|
|
||||||
},
|
|
||||||
Host: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'For WebSocket/HTTP/HTTPS',
|
|
||||||
},
|
|
||||||
Path: { type: 'string', description: 'For HTTP/HTTPS' },
|
|
||||||
ServiceName: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'For gRPC',
|
|
||||||
},
|
|
||||||
// Shadowsocks Options
|
|
||||||
Method: { type: 'string', description: 'Encryption method' },
|
|
||||||
ServerKey: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'For Shadowsocks 2022',
|
|
||||||
},
|
|
||||||
// Vmess/Vless/Trojan Options
|
|
||||||
Flow: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Flow for Vmess/Vless/Trojan',
|
|
||||||
},
|
|
||||||
// Hysteria2 Options
|
|
||||||
HopPorts: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Comma-separated list of hop ports',
|
|
||||||
},
|
|
||||||
HopInterval: {
|
|
||||||
type: 'number',
|
|
||||||
description: 'Interval for hop ports in seconds',
|
|
||||||
},
|
|
||||||
ObfsPassword: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Obfuscation password for Hysteria2',
|
|
||||||
},
|
|
||||||
// Tuic Options
|
|
||||||
DisableSNI: {
|
|
||||||
type: 'boolean',
|
|
||||||
description: 'Disable SNI',
|
|
||||||
},
|
|
||||||
ReduceRtt: {
|
|
||||||
type: 'boolean',
|
|
||||||
description: 'Reduce RTT',
|
|
||||||
},
|
|
||||||
UDPRelayMode: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'UDP relay mode (e.g., "full", "partial")',
|
|
||||||
},
|
|
||||||
CongestionController: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Congestion controller (e.g., "cubic", "bbr")',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
UserInfo: {
|
|
||||||
type: 'object',
|
|
||||||
description: 'User information',
|
|
||||||
properties: {
|
|
||||||
Password: { type: 'string', description: 'User password' },
|
|
||||||
ExpiredAt: { type: 'string', description: 'Expiration date' },
|
|
||||||
Download: { type: 'number', description: 'Downloaded bytes' },
|
|
||||||
Upload: { type: 'number', description: 'Uploaded bytes' },
|
|
||||||
Traffic: { type: 'number', description: 'Total traffic bytes' },
|
|
||||||
SubscribeURL: {
|
|
||||||
type: 'string',
|
|
||||||
description: 'Subscription URL',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
enableSprig
|
enableSprig
|
||||||
value={field.value || ''}
|
value={field.value || ''}
|
||||||
onChange={(value) => field.onChange(value)}
|
onChange={(value) => field.onChange(value)}
|
||||||
|
|||||||
@@ -0,0 +1,225 @@
|
|||||||
|
export const subscribeSchema = {
|
||||||
|
SiteName: { type: 'string', description: 'Site name' },
|
||||||
|
SubscribeName: { type: 'string', description: 'Subscribe name' },
|
||||||
|
Proxies: {
|
||||||
|
type: 'array',
|
||||||
|
description: 'Array of proxy nodes',
|
||||||
|
items: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
Name: { type: 'string', description: 'Node name' },
|
||||||
|
Server: { type: 'string', description: 'Server host' },
|
||||||
|
Port: { type: 'number', description: 'Server port' },
|
||||||
|
Type: { type: 'string', description: 'Proxy type' },
|
||||||
|
Tags: {
|
||||||
|
type: 'array',
|
||||||
|
description: 'Node tags',
|
||||||
|
items: { type: 'string' },
|
||||||
|
},
|
||||||
|
Sort: { type: 'number', description: 'Node sort order' },
|
||||||
|
// Security Options
|
||||||
|
Security: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Security protocol',
|
||||||
|
},
|
||||||
|
SNI: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Server Name Indication for TLS',
|
||||||
|
},
|
||||||
|
AllowInsecure: {
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'Allow insecure connections (skip certificate verification)',
|
||||||
|
},
|
||||||
|
Fingerprint: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Client fingerprint for TLS connections',
|
||||||
|
},
|
||||||
|
RealityServerAddr: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Reality server address',
|
||||||
|
},
|
||||||
|
RealityServerPort: {
|
||||||
|
type: 'number',
|
||||||
|
description: 'Reality server port',
|
||||||
|
},
|
||||||
|
RealityPrivateKey: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Reality private key for authentication',
|
||||||
|
},
|
||||||
|
RealityPublicKey: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Reality public key for authentication',
|
||||||
|
},
|
||||||
|
RealityShortId: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Reality short ID for authentication',
|
||||||
|
},
|
||||||
|
// Transport Options
|
||||||
|
Transport: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Transport protocol (e.g., ws, http, grpc)',
|
||||||
|
},
|
||||||
|
Host: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'For WebSocket/HTTP/HTTPS',
|
||||||
|
},
|
||||||
|
Path: { type: 'string', description: 'For HTTP/HTTPS' },
|
||||||
|
ServiceName: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'For gRPC',
|
||||||
|
},
|
||||||
|
// Shadowsocks Options
|
||||||
|
Method: { type: 'string', description: 'Encryption method' },
|
||||||
|
ServerKey: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'For Shadowsocks 2022',
|
||||||
|
},
|
||||||
|
// Vmess/Vless/Trojan Options
|
||||||
|
Flow: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Flow for Vmess/Vless/Trojan',
|
||||||
|
},
|
||||||
|
// Hysteria2 Options
|
||||||
|
HopPorts: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Comma-separated list of hop ports',
|
||||||
|
},
|
||||||
|
HopInterval: {
|
||||||
|
type: 'number',
|
||||||
|
description: 'Interval for hop ports in seconds',
|
||||||
|
},
|
||||||
|
ObfsPassword: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Obfuscation password for Hysteria2',
|
||||||
|
},
|
||||||
|
// Tuic Options
|
||||||
|
DisableSNI: {
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'Disable SNI',
|
||||||
|
},
|
||||||
|
ReduceRtt: {
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'Reduce RTT',
|
||||||
|
},
|
||||||
|
UDPRelayMode: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'UDP relay mode (e.g., "full", "partial")',
|
||||||
|
},
|
||||||
|
CongestionController: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Congestion controller (e.g., "cubic", "bbr")',
|
||||||
|
},
|
||||||
|
// Hysteria2 additional options
|
||||||
|
UpMbps: {
|
||||||
|
type: 'number',
|
||||||
|
description: 'Upload bandwidth in Mbps',
|
||||||
|
},
|
||||||
|
DownMbps: {
|
||||||
|
type: 'number',
|
||||||
|
description: 'Download bandwidth in Mbps',
|
||||||
|
},
|
||||||
|
// VLESS encryption options
|
||||||
|
Encryption: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Encryption type for VLESS',
|
||||||
|
},
|
||||||
|
EncryptionMode: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Encryption mode (e.g., "native", "xorpub", "random")',
|
||||||
|
},
|
||||||
|
EncryptionRtt: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Encryption RTT (e.g., "0rtt", "1rtt")',
|
||||||
|
},
|
||||||
|
EncryptionTicket: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Encryption ticket',
|
||||||
|
},
|
||||||
|
EncryptionServerPadding: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Server padding for encryption',
|
||||||
|
},
|
||||||
|
EncryptionClientPadding: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Client padding for encryption',
|
||||||
|
},
|
||||||
|
EncryptionPassword: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Encryption password',
|
||||||
|
},
|
||||||
|
EncryptionPrivateKey: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Private key for encryption',
|
||||||
|
},
|
||||||
|
// XHTTP options
|
||||||
|
XhttpMode: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'XHTTP mode (e.g., "auto", "packet-up", "stream-up", "stream-one")',
|
||||||
|
},
|
||||||
|
XhttpExtra: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'XHTTP extra parameters',
|
||||||
|
},
|
||||||
|
// Shadowsocks obfs options (combined with Hysteria2 obfs)
|
||||||
|
ObfsHost: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Obfuscation host',
|
||||||
|
},
|
||||||
|
ObfsPath: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Obfuscation path',
|
||||||
|
},
|
||||||
|
// Shadowsocks cipher
|
||||||
|
Cipher: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Shadowsocks cipher method',
|
||||||
|
},
|
||||||
|
// AnyTLS options
|
||||||
|
PaddingScheme: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Padding scheme for AnyTLS',
|
||||||
|
},
|
||||||
|
// Mieru options
|
||||||
|
Multiplex: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Multiplex level (e.g., "none", "low", "middle", "high")',
|
||||||
|
},
|
||||||
|
// General protocol field
|
||||||
|
Enable: {
|
||||||
|
type: 'boolean',
|
||||||
|
description: 'Whether this protocol is enabled',
|
||||||
|
},
|
||||||
|
// UUID for vmess/vless
|
||||||
|
UUID: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'User UUID for vmess/vless protocols',
|
||||||
|
},
|
||||||
|
// Alternative ID for vmess
|
||||||
|
AlterId: {
|
||||||
|
type: 'number',
|
||||||
|
description: 'Alternative ID for vmess (deprecated)',
|
||||||
|
},
|
||||||
|
// Password for trojan/tuic
|
||||||
|
Password: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Password for authentication',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
UserInfo: {
|
||||||
|
type: 'object',
|
||||||
|
description: 'User information',
|
||||||
|
properties: {
|
||||||
|
Password: { type: 'string', description: 'User password' },
|
||||||
|
ExpiredAt: { type: 'string', description: 'Expiration date' },
|
||||||
|
Download: { type: 'number', description: 'Downloaded bytes' },
|
||||||
|
Upload: { type: 'number', description: 'Uploaded bytes' },
|
||||||
|
Traffic: { type: 'number', description: 'Total traffic bytes' },
|
||||||
|
SubscribeURL: {
|
||||||
|
type: 'string',
|
||||||
|
description: 'Subscription URL',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -3,7 +3,13 @@
|
|||||||
import { previewSubscribeTemplate } from '@/services/admin/application';
|
import { previewSubscribeTemplate } from '@/services/admin/application';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import { Sheet, SheetContent, SheetHeader, SheetTitle } from '@workspace/ui/components/sheet';
|
import {
|
||||||
|
Sheet,
|
||||||
|
SheetContent,
|
||||||
|
SheetHeader,
|
||||||
|
SheetTitle,
|
||||||
|
SheetTrigger,
|
||||||
|
} from '@workspace/ui/components/sheet';
|
||||||
import { MonacoEditor } from '@workspace/ui/custom-components/editor/monaco-editor';
|
import { MonacoEditor } from '@workspace/ui/custom-components/editor/monaco-editor';
|
||||||
import { Icon } from '@workspace/ui/custom-components/icon';
|
import { Icon } from '@workspace/ui/custom-components/icon';
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
@@ -68,36 +74,33 @@ export function TemplatePreview({ applicationId, output_format }: TemplatePrevie
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOpenChange = (newOpen: boolean) => {
|
|
||||||
setIsOpen(newOpen);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Sheet open={isOpen} onOpenChange={setIsOpen}>
|
||||||
<Button variant='ghost' size='sm' onClick={() => setIsOpen(true)}>
|
<SheetTrigger asChild>
|
||||||
<Icon icon='mdi:eye' className='mr-2 h-4 w-4' />
|
<Button variant='ghost'>
|
||||||
{t('preview')}
|
<Icon icon='mdi:eye' className='h-4 w-4' />
|
||||||
</Button>
|
{t('preview')}
|
||||||
<Sheet open={isOpen} onOpenChange={handleOpenChange}>
|
</Button>
|
||||||
<SheetHeader>
|
</SheetTrigger>
|
||||||
<SheetTitle></SheetTitle>
|
<SheetHeader>
|
||||||
</SheetHeader>
|
<SheetTitle></SheetTitle>
|
||||||
<SheetContent className='w-[800px] max-w-[90vw] md:max-w-screen-md'>
|
</SheetHeader>
|
||||||
{isLoading ? (
|
<SheetContent className='w-[800px] max-w-[90vw] pt-10 md:max-w-screen-md'>
|
||||||
<div className='flex items-center justify-center'>
|
{isLoading ? (
|
||||||
<Icon icon='mdi:loading' className='h-6 w-6 animate-spin' />
|
<div className='flex items-center justify-center'>
|
||||||
<span className='ml-2'>{t('loading')}</span>
|
<Icon icon='mdi:loading' className='h-6 w-6 animate-spin' />
|
||||||
</div>
|
<span className='ml-2'>{t('loading')}</span>
|
||||||
) : (
|
</div>
|
||||||
<MonacoEditor
|
) : (
|
||||||
title={t('title')}
|
<MonacoEditor
|
||||||
value={getDisplayContent()}
|
title={t('title')}
|
||||||
language={mapLanguage(output_format)}
|
value={getDisplayContent()}
|
||||||
readOnly
|
language={mapLanguage(output_format)}
|
||||||
/>
|
showLineNumbers
|
||||||
)}
|
readOnly
|
||||||
</SheetContent>
|
/>
|
||||||
</Sheet>
|
)}
|
||||||
</>
|
</SheetContent>
|
||||||
|
</Sheet>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
|
||||||
import { getRegisterConfig, updateRegisterConfig } from '@/services/admin/system';
|
import { getRegisterConfig, updateRegisterConfig } from '@/services/admin/system';
|
||||||
|
import { useSubscribe } from '@/store/subscribe';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
@@ -61,17 +61,7 @@ export default function RegisterConfig() {
|
|||||||
enabled: open,
|
enabled: open,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { data: subscribe } = useQuery({
|
const { subscribes } = useSubscribe();
|
||||||
queryKey: ['getSubscribeList', 'all'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await getSubscribeList({
|
|
||||||
page: 1,
|
|
||||||
size: 9999,
|
|
||||||
});
|
|
||||||
return data.data?.list as API.Subscribe[];
|
|
||||||
},
|
|
||||||
enabled: open,
|
|
||||||
});
|
|
||||||
|
|
||||||
const form = useForm<RegisterFormData>({
|
const form = useForm<RegisterFormData>({
|
||||||
resolver: zodResolver(registerSchema),
|
resolver: zodResolver(registerSchema),
|
||||||
@@ -268,12 +258,10 @@ export default function RegisterConfig() {
|
|||||||
field.onChange(value);
|
field.onChange(value);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
options={
|
options={subscribes?.map((item) => ({
|
||||||
subscribe?.map((item) => ({
|
label: item.name!,
|
||||||
label: item.name,
|
value: item.id!,
|
||||||
value: item.id,
|
}))}
|
||||||
})) || []
|
|
||||||
}
|
|
||||||
className='bg-secondary w-32 rounded-r-none'
|
className='bg-secondary w-32 rounded-r-none'
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import { Display } from '@/components/display';
|
import { Display } from '@/components/display';
|
||||||
import { ProTable, ProTableActions } from '@/components/pro-table';
|
import { ProTable, ProTableActions } from '@/components/pro-table';
|
||||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
|
||||||
import {
|
import {
|
||||||
createUser,
|
createUser,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
@@ -10,6 +9,7 @@ import {
|
|||||||
getUserList,
|
getUserList,
|
||||||
updateUserBasicInfo,
|
updateUserBasicInfo,
|
||||||
} from '@/services/admin/user';
|
} from '@/services/admin/user';
|
||||||
|
import { useSubscribe } from '@/store/subscribe';
|
||||||
import { formatDate } from '@/utils/common';
|
import { formatDate } from '@/utils/common';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { Badge } from '@workspace/ui/components/badge';
|
import { Badge } from '@workspace/ui/components/badge';
|
||||||
@@ -49,16 +49,7 @@ export default function Page() {
|
|||||||
const ref = useRef<ProTableActions>(null);
|
const ref = useRef<ProTableActions>(null);
|
||||||
const sp = useSearchParams();
|
const sp = useSearchParams();
|
||||||
|
|
||||||
const { data: subscribeList } = useQuery({
|
const { subscribes } = useSubscribe();
|
||||||
queryKey: ['getSubscribeList', 'all'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await getSubscribeList({
|
|
||||||
page: 1,
|
|
||||||
size: 9999,
|
|
||||||
});
|
|
||||||
return data.data?.list as API.SubscribeGroup[];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const initialFilters = {
|
const initialFilters = {
|
||||||
search: sp.get('search') || undefined,
|
search: sp.get('search') || undefined,
|
||||||
@@ -69,6 +60,7 @@ export default function Page() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ProTable<API.User, API.GetUserListParams>
|
<ProTable<API.User, API.GetUserListParams>
|
||||||
|
key={initialFilters.user_id}
|
||||||
action={ref}
|
action={ref}
|
||||||
initialFilters={initialFilters}
|
initialFilters={initialFilters}
|
||||||
header={{
|
header={{
|
||||||
@@ -194,9 +186,9 @@ export default function Page() {
|
|||||||
{
|
{
|
||||||
key: 'subscribe_id',
|
key: 'subscribe_id',
|
||||||
placeholder: t('subscription'),
|
placeholder: t('subscription'),
|
||||||
options: subscribeList?.map((item) => ({
|
options: subscribes?.map((item) => ({
|
||||||
label: item.name,
|
label: item.name!,
|
||||||
value: String(item.id),
|
value: String(item.id!),
|
||||||
})),
|
})),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
import { useSubscribe } from '@/store/subscribe';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
import { Button } from '@workspace/ui/components/button';
|
import { Button } from '@workspace/ui/components/button';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
@@ -74,16 +73,7 @@ export function SubscriptionForm({ trigger, title, loading, initialData, onSubmi
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data: subscribe } = useQuery({
|
const { subscribes } = useSubscribe();
|
||||||
queryKey: ['getSubscribeList', 'all'],
|
|
||||||
queryFn: async () => {
|
|
||||||
const { data } = await getSubscribeList({
|
|
||||||
page: 1,
|
|
||||||
size: 9999,
|
|
||||||
});
|
|
||||||
return data.data?.list as API.Subscribe[];
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Sheet open={open} onOpenChange={setOpen}>
|
<Sheet open={open} onOpenChange={setOpen}>
|
||||||
@@ -117,9 +107,9 @@ export function SubscriptionForm({ trigger, title, loading, initialData, onSubmi
|
|||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
form.setValue(field.name, value);
|
form.setValue(field.name, value);
|
||||||
}}
|
}}
|
||||||
options={subscribe?.map((item: API.Subscribe) => ({
|
options={subscribes?.map((item) => ({
|
||||||
value: item.id,
|
value: item.id!,
|
||||||
label: item.name,
|
label: item.name!,
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
||||||
// API 更新时间:
|
// API 更新时间:
|
||||||
// API 唯一标识:
|
// API 唯一标识:
|
||||||
import * as ads from './ads';
|
import * as ads from './ads';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
||||||
// API 更新时间:
|
// API 更新时间:
|
||||||
// API 唯一标识:
|
// API 唯一标识:
|
||||||
import * as auth from './auth';
|
import * as auth from './auth';
|
||||||
|
|||||||
@@ -0,0 +1,145 @@
|
|||||||
|
import { filterNodeList, queryNodeTag } from '@/services/admin/server';
|
||||||
|
import { create } from 'zustand';
|
||||||
|
|
||||||
|
interface NodeState {
|
||||||
|
// Data
|
||||||
|
nodes: API.Node[];
|
||||||
|
tags: string[];
|
||||||
|
|
||||||
|
// Loading states
|
||||||
|
loading: boolean;
|
||||||
|
loadingTags: boolean;
|
||||||
|
loaded: boolean;
|
||||||
|
loadedTags: boolean;
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
fetchNodes: () => Promise<void>;
|
||||||
|
fetchTags: () => Promise<void>;
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
getNodeById: (nodeId: number) => API.Node | undefined;
|
||||||
|
isProtocolUsedInNodes: (serverId: number, protocolType: string) => boolean;
|
||||||
|
isServerReferencedByNodes: (serverId: number) => boolean;
|
||||||
|
getNodesByTag: (tag: string) => API.Node[];
|
||||||
|
getNodesWithoutTags: () => API.Node[];
|
||||||
|
getNodeTags: () => string[];
|
||||||
|
getAllAvailableTags: () => string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useNodeStore = create<NodeState>((set, get) => ({
|
||||||
|
// Initial state
|
||||||
|
nodes: [],
|
||||||
|
tags: [],
|
||||||
|
loading: false,
|
||||||
|
loadingTags: false,
|
||||||
|
loaded: false,
|
||||||
|
loadedTags: false,
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
fetchNodes: async () => {
|
||||||
|
if (get().loading) return;
|
||||||
|
|
||||||
|
set({ loading: true });
|
||||||
|
try {
|
||||||
|
const { data } = await filterNodeList({ page: 1, size: 999999999 });
|
||||||
|
set({
|
||||||
|
nodes: data?.data?.list || [],
|
||||||
|
loaded: true,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Handle error silently
|
||||||
|
set({ loaded: true });
|
||||||
|
} finally {
|
||||||
|
set({ loading: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
fetchTags: async () => {
|
||||||
|
if (get().loadingTags) return;
|
||||||
|
|
||||||
|
set({ loadingTags: true });
|
||||||
|
try {
|
||||||
|
const { data } = await queryNodeTag();
|
||||||
|
set({
|
||||||
|
tags: data?.data?.tags || [],
|
||||||
|
loadedTags: true,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Handle error silently
|
||||||
|
set({ loadedTags: true });
|
||||||
|
} finally {
|
||||||
|
set({ loadingTags: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
getNodeById: (nodeId: number) => {
|
||||||
|
return get().nodes.find((n) => n.id === nodeId);
|
||||||
|
},
|
||||||
|
|
||||||
|
isProtocolUsedInNodes: (serverId: number, protocolType: string) => {
|
||||||
|
return get().nodes.some(
|
||||||
|
(node) => node.server_id === serverId && node.protocol === protocolType,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
isServerReferencedByNodes: (serverId: number) => {
|
||||||
|
return get().nodes.some((node) => node.server_id === serverId);
|
||||||
|
},
|
||||||
|
|
||||||
|
getNodesByTag: (tag: string) => {
|
||||||
|
return get().nodes.filter((node) => (node.tags || []).includes(tag));
|
||||||
|
},
|
||||||
|
|
||||||
|
getNodesWithoutTags: () => {
|
||||||
|
return get().nodes.filter((node) => (node.tags || []).length === 0);
|
||||||
|
},
|
||||||
|
|
||||||
|
getNodeTags: () => {
|
||||||
|
return Array.from(
|
||||||
|
new Set(
|
||||||
|
get()
|
||||||
|
.nodes.flatMap((node) => (Array.isArray(node.tags) ? node.tags : []))
|
||||||
|
.filter(Boolean),
|
||||||
|
),
|
||||||
|
) as string[];
|
||||||
|
},
|
||||||
|
|
||||||
|
getAllAvailableTags: () => {
|
||||||
|
const nodeExtractedTags = get().getNodeTags();
|
||||||
|
const allApiTags = get().tags;
|
||||||
|
return Array.from(new Set([...allApiTags, ...nodeExtractedTags])).filter(Boolean);
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const useNode = () => {
|
||||||
|
const store = useNodeStore();
|
||||||
|
|
||||||
|
// Auto-fetch nodes and tags
|
||||||
|
if (!store.loaded && !store.loading) {
|
||||||
|
store.fetchNodes();
|
||||||
|
}
|
||||||
|
if (!store.loadedTags && !store.loadingTags) {
|
||||||
|
store.fetchTags();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
nodes: store.nodes,
|
||||||
|
tags: store.tags,
|
||||||
|
loading: store.loading,
|
||||||
|
loadingTags: store.loadingTags,
|
||||||
|
loaded: store.loaded,
|
||||||
|
loadedTags: store.loadedTags,
|
||||||
|
fetchNodes: store.fetchNodes,
|
||||||
|
fetchTags: store.fetchTags,
|
||||||
|
getNodeById: store.getNodeById,
|
||||||
|
isProtocolUsedInNodes: store.isProtocolUsedInNodes,
|
||||||
|
isServerReferencedByNodes: store.isServerReferencedByNodes,
|
||||||
|
getNodesByTag: store.getNodesByTag,
|
||||||
|
getNodesWithoutTags: store.getNodesWithoutTags,
|
||||||
|
getNodeTags: store.getNodeTags,
|
||||||
|
getAllAvailableTags: store.getAllAvailableTags,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useNodeStore;
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
import { filterServerList } from '@/services/admin/server';
|
||||||
|
import { create } from 'zustand';
|
||||||
|
|
||||||
|
interface ServerState {
|
||||||
|
// Data
|
||||||
|
servers: API.Server[];
|
||||||
|
|
||||||
|
// Loading states
|
||||||
|
loading: boolean;
|
||||||
|
loaded: boolean;
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
fetchServers: () => Promise<void>;
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
getServerById: (serverId: number) => API.Server | undefined;
|
||||||
|
getServerName: (serverId?: number) => string;
|
||||||
|
getServerAddress: (serverId?: number) => string;
|
||||||
|
getServerEnabledProtocols: (serverId: number) => API.Protocol[];
|
||||||
|
getProtocolPort: (serverId?: number, protocol?: string) => string;
|
||||||
|
getAvailableProtocols: (serverId?: number) => Array<{ protocol: string; port: number }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useServerStore = create<ServerState>((set, get) => ({
|
||||||
|
// Initial state
|
||||||
|
servers: [],
|
||||||
|
loading: false,
|
||||||
|
loaded: false,
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
fetchServers: async () => {
|
||||||
|
if (get().loading) return;
|
||||||
|
|
||||||
|
set({ loading: true });
|
||||||
|
try {
|
||||||
|
const { data } = await filterServerList({ page: 1, size: 999999999 });
|
||||||
|
set({
|
||||||
|
servers: data?.data?.list || [],
|
||||||
|
loaded: true,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Handle error silently
|
||||||
|
set({ loaded: true });
|
||||||
|
} finally {
|
||||||
|
set({ loading: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
getServerById: (serverId: number) => {
|
||||||
|
return get().servers.find((s) => s.id === serverId);
|
||||||
|
},
|
||||||
|
|
||||||
|
getServerName: (serverId?: number) => {
|
||||||
|
if (!serverId) return '—';
|
||||||
|
const server = get().servers.find((s) => s.id === serverId);
|
||||||
|
return server?.name ?? `#${serverId}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
getServerAddress: (serverId?: number) => {
|
||||||
|
if (!serverId) return '—';
|
||||||
|
const server = get().servers.find((s) => s.id === serverId);
|
||||||
|
return server?.address ?? '—';
|
||||||
|
},
|
||||||
|
|
||||||
|
getServerEnabledProtocols: (serverId: number) => {
|
||||||
|
const server = get().servers.find((s) => s.id === serverId);
|
||||||
|
return server?.protocols?.filter((p) => p.enable !== false) || [];
|
||||||
|
},
|
||||||
|
|
||||||
|
getProtocolPort: (serverId?: number, protocol?: string) => {
|
||||||
|
if (!serverId || !protocol) return '—';
|
||||||
|
const enabledProtocols = get().getServerEnabledProtocols(serverId);
|
||||||
|
const protocolConfig = enabledProtocols.find((p) => p.type === protocol);
|
||||||
|
return protocolConfig?.port ? String(protocolConfig.port) : '—';
|
||||||
|
},
|
||||||
|
|
||||||
|
getAvailableProtocols: (serverId?: number) => {
|
||||||
|
if (!serverId) return [];
|
||||||
|
return get()
|
||||||
|
.getServerEnabledProtocols(serverId)
|
||||||
|
.map((p) => ({
|
||||||
|
protocol: p.type,
|
||||||
|
port: p.port,
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const useServer = () => {
|
||||||
|
const store = useServerStore();
|
||||||
|
|
||||||
|
// Auto-fetch servers
|
||||||
|
if (!store.loaded && !store.loading) {
|
||||||
|
store.fetchServers();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
servers: store.servers,
|
||||||
|
loading: store.loading,
|
||||||
|
loaded: store.loaded,
|
||||||
|
fetchServers: store.fetchServers,
|
||||||
|
getServerById: store.getServerById,
|
||||||
|
getServerName: store.getServerName,
|
||||||
|
getServerAddress: store.getServerAddress,
|
||||||
|
getServerEnabledProtocols: store.getServerEnabledProtocols,
|
||||||
|
getProtocolPort: store.getProtocolPort,
|
||||||
|
getAvailableProtocols: store.getAvailableProtocols,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useServerStore;
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { getSubscribeList } from '@/services/admin/subscribe';
|
||||||
|
import { create } from 'zustand';
|
||||||
|
|
||||||
|
interface SubscribeState {
|
||||||
|
// Data
|
||||||
|
subscribes: API.SubscribeItem[];
|
||||||
|
|
||||||
|
// Loading states
|
||||||
|
loading: boolean;
|
||||||
|
loaded: boolean;
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
fetchSubscribes: () => Promise<void>;
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
getSubscribeName: (subscribeId?: number) => string;
|
||||||
|
getSubscribeById: (subscribeId: number) => API.SubscribeItem | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSubscribeStore = create<SubscribeState>((set, get) => ({
|
||||||
|
// Initial state
|
||||||
|
subscribes: [],
|
||||||
|
loading: false,
|
||||||
|
loaded: false,
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
fetchSubscribes: async () => {
|
||||||
|
if (get().loading) return;
|
||||||
|
|
||||||
|
set({ loading: true });
|
||||||
|
try {
|
||||||
|
const { data } = await getSubscribeList({ page: 1, size: 999999999 });
|
||||||
|
set({
|
||||||
|
subscribes: data?.data?.list || [],
|
||||||
|
loaded: true,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// Handle error silently
|
||||||
|
set({ loaded: true });
|
||||||
|
} finally {
|
||||||
|
set({ loading: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
getSubscribeName: (subscribeId?: number) => {
|
||||||
|
if (!subscribeId) return '--';
|
||||||
|
const subscribe = get().subscribes.find((s) => s.id === subscribeId);
|
||||||
|
return subscribe?.name ?? `Subscribe ${subscribeId}`;
|
||||||
|
},
|
||||||
|
|
||||||
|
getSubscribeById: (subscribeId: number) => {
|
||||||
|
return get().subscribes.find((s) => s.id === subscribeId);
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export const useSubscribe = () => {
|
||||||
|
const store = useSubscribeStore();
|
||||||
|
|
||||||
|
// Auto-fetch subscribes
|
||||||
|
if (!store.loaded && !store.loading) {
|
||||||
|
store.fetchSubscribes();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
subscribes: store.subscribes,
|
||||||
|
loading: store.loading,
|
||||||
|
loaded: store.loaded,
|
||||||
|
fetchSubscribes: store.fetchSubscribes,
|
||||||
|
getSubscribeName: store.getSubscribeName,
|
||||||
|
getSubscribeById: store.getSubscribeById,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useSubscribeStore;
|
||||||
@@ -11,6 +11,9 @@ NEXT_PUBLIC_HOME_USER_COUNT=999
|
|||||||
NEXT_PUBLIC_HOME_SERVER_COUNT=999
|
NEXT_PUBLIC_HOME_SERVER_COUNT=999
|
||||||
NEXT_PUBLIC_HOME_LOCATION_COUNT=999
|
NEXT_PUBLIC_HOME_LOCATION_COUNT=999
|
||||||
|
|
||||||
|
# Hidden Tutorial Document
|
||||||
|
NEXT_PUBLIC_HIDDEN_TUTORIAL_DOCUMENT=false # true or false
|
||||||
|
|
||||||
# Contact Email
|
# Contact Email
|
||||||
NEXT_PUBLIC_EMAIL=support@ppanel.dev
|
NEXT_PUBLIC_EMAIL=support@ppanel.dev
|
||||||
# Community Links
|
# Community Links
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ export default function Page() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Empty />
|
<Empty border />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import { useTranslations } from 'next-intl';
|
|||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { QRCodeCanvas } from 'qrcode.react';
|
import { QRCodeCanvas } from 'qrcode.react';
|
||||||
import { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import Subscribe from '../subscribe/page';
|
import Subscribe from '../subscribe/page';
|
||||||
@@ -75,9 +75,39 @@ export default function Content() {
|
|||||||
return data.data?.list || [];
|
return data.data?.list || [];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const [platform, setPlatform] = useState<keyof API.DownloadLink>(
|
|
||||||
getPlatform() === 'macos' ? 'mac' : (getPlatform() as keyof API.DownloadLink),
|
const availablePlatforms = React.useMemo(() => {
|
||||||
);
|
if (!applications || applications.length === 0) return platforms;
|
||||||
|
|
||||||
|
const platformsSet = new Set<keyof API.DownloadLink>();
|
||||||
|
|
||||||
|
applications.forEach((app) => {
|
||||||
|
if (app.download_link) {
|
||||||
|
platforms.forEach((platform) => {
|
||||||
|
if (app.download_link?.[platform]) {
|
||||||
|
platformsSet.add(platform);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return platforms.filter((platform) => platformsSet.has(platform));
|
||||||
|
}, [applications]);
|
||||||
|
|
||||||
|
const [platform, setPlatform] = useState<keyof API.DownloadLink>(() => {
|
||||||
|
const detectedPlatform =
|
||||||
|
getPlatform() === 'macos' ? 'mac' : (getPlatform() as keyof API.DownloadLink);
|
||||||
|
return detectedPlatform;
|
||||||
|
});
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (availablePlatforms.length > 0 && !availablePlatforms.includes(platform)) {
|
||||||
|
const firstAvailablePlatform = availablePlatforms[0];
|
||||||
|
if (firstAvailablePlatform) {
|
||||||
|
setPlatform(firstAvailablePlatform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [availablePlatforms, platform]);
|
||||||
|
|
||||||
const { data } = useQuery({
|
const { data } = useQuery({
|
||||||
queryKey: ['getStat'],
|
queryKey: ['getStat'],
|
||||||
@@ -122,31 +152,33 @@ export default function Content() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='flex flex-wrap justify-between gap-4'>
|
<div className='flex flex-wrap justify-between gap-4'>
|
||||||
<Tabs
|
{availablePlatforms.length > 0 && (
|
||||||
value={platform}
|
<Tabs
|
||||||
onValueChange={(value) => setPlatform(value as keyof API.DownloadLink)}
|
value={platform}
|
||||||
className='w-full max-w-full md:w-auto'
|
onValueChange={(value) => setPlatform(value as keyof API.DownloadLink)}
|
||||||
>
|
className='w-full max-w-full md:w-auto'
|
||||||
<TabsList className='flex *:flex-auto'>
|
>
|
||||||
{platforms.map((item) => (
|
<TabsList className='flex *:flex-auto'>
|
||||||
<TabsTrigger value={item} key={item} className='px-1 lg:px-3'>
|
{availablePlatforms.map((item) => (
|
||||||
<Icon
|
<TabsTrigger value={item} key={item} className='px-1 lg:px-3'>
|
||||||
icon={`${
|
<Icon
|
||||||
{
|
icon={`${
|
||||||
windows: 'mdi:microsoft-windows',
|
{
|
||||||
mac: 'uil:apple',
|
windows: 'mdi:microsoft-windows',
|
||||||
linux: 'uil:linux',
|
mac: 'uil:apple',
|
||||||
ios: 'simple-icons:ios',
|
linux: 'uil:linux',
|
||||||
android: 'uil:android',
|
ios: 'simple-icons:ios',
|
||||||
harmony: 'simple-icons:harmonyos',
|
android: 'uil:android',
|
||||||
}[item]
|
harmony: 'simple-icons:harmonyos',
|
||||||
}`}
|
}[item]
|
||||||
className='size-5'
|
}`}
|
||||||
/>
|
className='size-5'
|
||||||
</TabsTrigger>
|
/>
|
||||||
))}
|
</TabsTrigger>
|
||||||
</TabsList>
|
))}
|
||||||
</Tabs>
|
</TabsList>
|
||||||
|
</Tabs>
|
||||||
|
)}
|
||||||
{data?.protocol && data?.protocol.length > 1 && (
|
{data?.protocol && data?.protocol.length > 1 && (
|
||||||
<Tabs
|
<Tabs
|
||||||
value={protocol}
|
value={protocol}
|
||||||
@@ -325,9 +357,8 @@ export default function Content() {
|
|||||||
<div className='grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6'>
|
<div className='grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6'>
|
||||||
{applications
|
{applications
|
||||||
?.filter((application) => {
|
?.filter((application) => {
|
||||||
if (!application.download_link && !application.scheme) return false;
|
return !!(
|
||||||
return (
|
application.download_link?.[platform] && application.scheme
|
||||||
!!application.download_link?.[platform] || !!application.scheme
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.map((application) => {
|
.map((application) => {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ export function DocumentButton({ items }: { items: API.Document[] }) {
|
|||||||
layoutId={`card-${item.id}-${id}`}
|
layoutId={`card-${item.id}-${id}`}
|
||||||
key={`card-${item.id}-${id}`}
|
key={`card-${item.id}-${id}`}
|
||||||
onClick={() => setActive(item)}
|
onClick={() => setActive(item)}
|
||||||
className='bg-background hover:bg-accent flex cursor-pointer items-center justify-between rounded border p-4'
|
className='bg-background hover:bg-accent flex cursor-pointer items-center justify-between rounded-xl border p-4'
|
||||||
>
|
>
|
||||||
<div className='flex flex-row items-center gap-4'>
|
<div className='flex flex-row items-center gap-4'>
|
||||||
<motion.div layoutId={`image-${item.id}-${id}`}>
|
<motion.div layoutId={`image-${item.id}-${id}`}>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { Empty } from '@/components/empty';
|
||||||
|
import { NEXT_PUBLIC_HIDDEN_TUTORIAL_DOCUMENT } from '@/config/constants';
|
||||||
import { queryDocumentList } from '@/services/user/document';
|
import { queryDocumentList } from '@/services/user/document';
|
||||||
import { getTutorialList } from '@/utils/tutorial';
|
import { getTutorialList } from '@/utils/tutorial';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
@@ -31,8 +33,16 @@ export default function Page() {
|
|||||||
const list = await getTutorialList();
|
const list = await getTutorialList();
|
||||||
return list.get(locale);
|
return list.get(locale);
|
||||||
},
|
},
|
||||||
|
enabled: NEXT_PUBLIC_HIDDEN_TUTORIAL_DOCUMENT !== 'true',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (
|
||||||
|
(!DocumentList || DocumentList.length === 0) &&
|
||||||
|
(!TutorialList || TutorialList.length === 0)
|
||||||
|
) {
|
||||||
|
return <Empty border />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='space-y-4'>
|
<div className='space-y-4'>
|
||||||
{DocumentList?.length > 0 && (
|
{DocumentList?.length > 0 && (
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ export function TutorialButton({ items }: { items: Item[] }) {
|
|||||||
layoutId={`card-${item.title}-${id}`}
|
layoutId={`card-${item.title}-${id}`}
|
||||||
key={`card-${item.title}-${id}`}
|
key={`card-${item.title}-${id}`}
|
||||||
onClick={() => setActive(item)}
|
onClick={() => setActive(item)}
|
||||||
className='bg-background hover:bg-accent flex cursor-pointer items-center justify-between rounded border p-4'
|
className='bg-background hover:bg-accent flex cursor-pointer items-center justify-between rounded-xl border p-4'
|
||||||
>
|
>
|
||||||
<div className='flex flex-row items-center gap-4'>
|
<div className='flex flex-row items-center gap-4'>
|
||||||
<motion.div layoutId={`image-${item.title}-${id}`}>
|
<motion.div layoutId={`image-${item.title}-${id}`}>
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ import { default as _Empty } from '@workspace/ui/custom-components/empty';
|
|||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
export function Empty() {
|
interface EmptyProps {
|
||||||
|
border?: boolean;
|
||||||
|
}
|
||||||
|
export function Empty({ border }: EmptyProps) {
|
||||||
const t = useTranslations('common');
|
const t = useTranslations('common');
|
||||||
|
|
||||||
const [description, setDescription] = useState('');
|
const [description, setDescription] = useState('');
|
||||||
@@ -14,5 +17,5 @@ export function Empty() {
|
|||||||
setDescription(t(`empty.${random}`));
|
setDescription(t(`empty.${random}`));
|
||||||
}, [t]);
|
}, [t]);
|
||||||
|
|
||||||
return <_Empty description={description} />;
|
return <_Empty description={description} border={border} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,3 +53,6 @@ export const NEXT_PUBLIC_HOME_LOCATION_COUNT = (() => {
|
|||||||
if (isNaN(numberValue)) return 999;
|
if (isNaN(numberValue)) return 999;
|
||||||
return numberValue;
|
return numberValue;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
export const NEXT_PUBLIC_HIDDEN_TUTORIAL_DOCUMENT =
|
||||||
|
env('NEXT_PUBLIC_HIDDEN_TUTORIAL_DOCUMENT') ?? process.env.NEXT_PUBLIC_HIDDEN_TUTORIAL_DOCUMENT;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
||||||
// API 更新时间:
|
// API 更新时间:
|
||||||
// API 唯一标识:
|
// API 唯一标识:
|
||||||
import * as auth from './auth';
|
import * as auth from './auth';
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
||||||
// API 更新时间:
|
// API 更新时间:
|
||||||
// API 唯一标识:
|
// API 唯一标识:
|
||||||
import * as announcement from './announcement';
|
import * as announcement from './announcement';
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ppanel-web",
|
"name": "ppanel-web",
|
||||||
"version": "1.4.4",
|
"version": "1.4.8",
|
||||||
"private": true,
|
"private": true,
|
||||||
"homepage": "https://github.com/perfect-panel/ppanel-web",
|
"homepage": "https://github.com/perfect-panel/ppanel-web",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
|
|||||||
@@ -168,7 +168,12 @@ export function MonacoEditor({
|
|||||||
/>
|
/>
|
||||||
{!internalValue?.trim() && placeholder && (
|
{!internalValue?.trim() && placeholder && (
|
||||||
<pre
|
<pre
|
||||||
className='text-muted-foreground pointer-events-none absolute left-7 top-4 text-sm'
|
className={cn(
|
||||||
|
'text-muted-foreground pointer-events-none absolute left-7 top-4 text-sm',
|
||||||
|
{
|
||||||
|
'left-16': showLineNumbers,
|
||||||
|
},
|
||||||
|
)}
|
||||||
style={{ userSelect: 'none' }}
|
style={{ userSelect: 'none' }}
|
||||||
>
|
>
|
||||||
{placeholder}
|
{placeholder}
|
||||||
|
|||||||
@@ -1,6 +1,14 @@
|
|||||||
export default function Empty({ description }: { description?: React.ReactNode }) {
|
export default function Empty({
|
||||||
|
description,
|
||||||
|
border,
|
||||||
|
}: {
|
||||||
|
description?: React.ReactNode;
|
||||||
|
border?: boolean;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-col items-center justify-center p-6 py-16'>
|
<div
|
||||||
|
className={`flex flex-col items-center justify-center p-6 py-16 ${border ? 'rounded-xl border' : ''}`}
|
||||||
|
>
|
||||||
<svg
|
<svg
|
||||||
width='64'
|
width='64'
|
||||||
height='41'
|
height='41'
|
||||||
|
|||||||
Reference in New Issue
Block a user