misc_pterodactyl-panel/resources/scripts/routers/routes.ts

169 lines
5.4 KiB
TypeScript
Raw Normal View History

2022-11-25 20:25:03 +00:00
import type { ComponentType } from 'react';
import { lazy } from 'react';
import ServerConsole from '@/components/server/console/ServerConsoleContainer';
import DatabasesContainer from '@/components/server/databases/DatabasesContainer';
import ScheduleContainer from '@/components/server/schedules/ScheduleContainer';
import UsersContainer from '@/components/server/users/UsersContainer';
import BackupContainer from '@/components/server/backups/BackupContainer';
import NetworkContainer from '@/components/server/network/NetworkContainer';
import StartupContainer from '@/components/server/startup/StartupContainer';
import FileManagerContainer from '@/components/server/files/FileManagerContainer';
import SettingsContainer from '@/components/server/settings/SettingsContainer';
import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer';
import AccountApiContainer from '@/components/dashboard/AccountApiContainer';
import AccountSSHContainer from '@/components/dashboard/ssh/AccountSSHContainer';
import ActivityLogContainer from '@/components/dashboard/activity/ActivityLogContainer';
2022-06-12 19:16:48 +00:00
import ServerActivityLogContainer from '@/components/server/ServerActivityLogContainer';
// Each of the router files is already code split out appropriately — so
2022-11-25 20:25:03 +00:00
// all the items above will only be loaded in when that router is loaded.
//
// These specific lazy loaded routes are to avoid loading in heavy screens
// for the server dashboard when they're only needed for specific instances.
const FileEditContainer = lazy(() => import('@/components/server/files/FileEditContainer'));
const ScheduleEditContainer = lazy(() => import('@/components/server/schedules/ScheduleEditContainer'));
interface RouteDefinition {
2022-11-25 20:25:03 +00:00
/**
* Route is the path that will be matched against, this field supports wildcards.
*/
route: string;
/**
* Path is the path that will be used for any navbars or links, do not use wildcards or fancy
* matchers here. If this field is left undefined, this route will not have a navigation element,
*/
path?: string;
// If undefined is passed this route is still rendered into the router itself
// but no navigation link is displayed in the sub-navigation menu.
name: string | undefined;
2022-11-25 20:25:03 +00:00
component: ComponentType;
end?: boolean;
}
interface ServerRouteDefinition extends RouteDefinition {
2022-11-25 20:25:03 +00:00
permission?: string | string[];
}
interface Routes {
2022-11-25 20:25:03 +00:00
// All the routes available under "/account"
account: RouteDefinition[];
2022-11-25 20:25:03 +00:00
// All the routes available under "/server/:id"
server: ServerRouteDefinition[];
}
export default {
account: [
{
2022-11-25 20:25:03 +00:00
route: '',
path: '',
name: 'Account',
component: AccountOverviewContainer,
2022-11-25 20:25:03 +00:00
end: true,
},
{
2022-11-25 20:25:03 +00:00
route: 'api',
path: 'api',
name: 'API Credentials',
component: AccountApiContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'ssh',
path: 'ssh',
name: 'SSH Keys',
component: AccountSSHContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'activity',
path: 'activity',
name: 'Activity',
component: ActivityLogContainer,
},
],
server: [
{
2022-11-25 20:25:03 +00:00
route: '',
path: '',
permission: null,
name: 'Console',
component: ServerConsole,
2022-11-25 20:25:03 +00:00
end: true,
},
{
2022-11-25 20:25:03 +00:00
route: 'files/*',
path: 'files',
permission: 'file.*',
name: 'Files',
component: FileManagerContainer,
},
{
route: 'files/:action/*',
permission: 'file.*',
name: undefined,
component: FileEditContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'databases/*',
path: 'databases',
permission: 'database.*',
name: 'Databases',
component: DatabasesContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'schedules/*',
path: 'schedules',
permission: 'schedule.*',
name: 'Schedules',
component: ScheduleContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'schedules/:id/*',
permission: 'schedule.*',
name: undefined,
component: ScheduleEditContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'users/*',
path: 'users',
permission: 'user.*',
name: 'Users',
component: UsersContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'backups/*',
path: 'backups',
permission: 'backup.*',
name: 'Backups',
component: BackupContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'network/*',
path: 'network',
permission: 'allocation.*',
name: 'Network',
component: NetworkContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'startup/*',
path: 'startup',
permission: 'startup.*',
name: 'Startup',
component: StartupContainer,
},
{
2022-11-25 20:25:03 +00:00
route: 'settings/*',
path: 'settings',
permission: ['settings.*', 'file.sftp'],
name: 'Settings',
component: SettingsContainer,
},
2022-06-12 19:16:48 +00:00
{
2022-11-25 20:25:03 +00:00
route: 'activity/*',
path: 'activity',
2022-06-12 19:16:48 +00:00
permission: 'activity.*',
name: 'Activity',
component: ServerActivityLogContainer,
},
],
} as Routes;