mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
Co-authored-by: Anthony <anthony@infraly.co> Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
import type { UserData } from '@/api/account/types';
|
|
import type { SiteSettings } from '@/api/settings/types';
|
|
import type { SiteExtensionEntry } from '@/extensions/loader';
|
|
|
|
interface ExtendedWindow extends Window {
|
|
SiteConfiguration?: SiteSettings & { extensions?: SiteExtensionEntry[] };
|
|
PterodactylUser?: {
|
|
uuid: string;
|
|
username: string;
|
|
email: string;
|
|
root_admin: boolean;
|
|
use_totp: boolean;
|
|
language: string;
|
|
updated_at: string;
|
|
created_at: string;
|
|
};
|
|
}
|
|
|
|
export const getBootstrapUser = (): UserData | undefined => {
|
|
const user = (window as ExtendedWindow).PterodactylUser;
|
|
|
|
return user
|
|
? {
|
|
uuid: user.uuid,
|
|
username: user.username,
|
|
email: user.email,
|
|
language: user.language,
|
|
rootAdmin: user.root_admin,
|
|
useTotp: user.use_totp,
|
|
createdAt: new Date(user.created_at),
|
|
updatedAt: new Date(user.updated_at),
|
|
}
|
|
: undefined;
|
|
};
|
|
|
|
let sessionEnded = false;
|
|
|
|
export const endBootstrapSession = (): void => {
|
|
sessionEnded = true;
|
|
};
|
|
|
|
export const hasBootstrapSession = (): boolean => !sessionEnded && !!getBootstrapUser()?.uuid;
|
|
|
|
export const getBootstrapSiteSettings = (): SiteSettings | undefined => (window as ExtendedWindow).SiteConfiguration;
|
|
|
|
export const getBootstrapExtensions = (): SiteExtensionEntry[] =>
|
|
(window as ExtendedWindow).SiteConfiguration?.extensions ?? [];
|