This commit is contained in:
69
public/ts-build/core/app.js
Normal file
69
public/ts-build/core/app.js
Normal file
@@ -0,0 +1,69 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const api_js_1 = require("../services/api.js");
|
||||
const store_js_1 = require("../state/store.js");
|
||||
const navigation_js_1 = require("../ui/navigation.js");
|
||||
const toast_js_1 = require("../ui/toast.js");
|
||||
const guildSelect_js_1 = require("../components/guildSelect.js");
|
||||
const dashboard_js_1 = require("../components/dashboard.js");
|
||||
function readConfig() {
|
||||
const root = document.getElementById('app');
|
||||
if (!root)
|
||||
throw new Error('App-Container fehlt');
|
||||
const view = root.dataset.view || 'selection';
|
||||
const baseRoot = root.dataset.baseRoot || '/ucp';
|
||||
const baseDashboard = root.dataset.baseDashboard || `${baseRoot}/dashboard`;
|
||||
const baseAuth = root.dataset.baseAuth || `${baseRoot}/auth`;
|
||||
const baseApi = root.dataset.baseApi || `${baseRoot}/api`;
|
||||
const initialGuildId = root.dataset.guildId || undefined;
|
||||
const isAdmin = root.dataset.userAdmin === 'true';
|
||||
const userLabel = root.dataset.userName
|
||||
? `${root.dataset.userName}${root.dataset.userDisc ? '#' + root.dataset.userDisc : ''}`
|
||||
: undefined;
|
||||
(0, store_js_1.initConfig)({ baseRoot, baseDashboard, baseAuth, baseApi, view, initialGuildId, isAdmin, userLabel });
|
||||
}
|
||||
async function ensureAuth() {
|
||||
try {
|
||||
const me = await api_js_1.api.me();
|
||||
if (!me?.user) {
|
||||
const cfg = (0, store_js_1.getConfig)();
|
||||
window.location.href = (cfg?.baseAuth || '/auth') + '/discord';
|
||||
return null;
|
||||
}
|
||||
const userInfo = document.getElementById('userInfo');
|
||||
if (userInfo && me.user)
|
||||
userInfo.textContent = `${me.user.username}#${me.user.discriminator}`;
|
||||
(0, store_js_1.setState)({ isAdmin: !!me.user?.isAdmin, userLabel: me.user ? `${me.user.username}#${me.user.discriminator}` : undefined });
|
||||
return me;
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
(0, toast_js_1.showToast)('Authentifizierung fehlgeschlagen', true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
async function bootstrap() {
|
||||
readConfig();
|
||||
const cfg = (0, store_js_1.getConfig)();
|
||||
if (!cfg)
|
||||
return;
|
||||
const sidebarRoot = document.getElementById('sidebar-root');
|
||||
if (sidebarRoot)
|
||||
(0, navigation_js_1.renderSidebar)(sidebarRoot, !!cfg.isAdmin);
|
||||
if (cfg.view === 'selection') {
|
||||
(0, guildSelect_js_1.initSelectionView)();
|
||||
}
|
||||
else {
|
||||
await ensureAuth();
|
||||
(0, dashboard_js_1.initDashboardView)();
|
||||
(0, navigation_js_1.initNavigation)((section) => {
|
||||
// Sections werden innerhalb der jeweiligen Komponenten bedient
|
||||
if (section === 'admin' && !cfg.isAdmin)
|
||||
(0, toast_js_1.showToast)('Kein Admin-Recht', true);
|
||||
});
|
||||
}
|
||||
}
|
||||
bootstrap().catch((err) => {
|
||||
console.error(err);
|
||||
(0, toast_js_1.showToast)('Fehler beim Laden', true);
|
||||
});
|
||||
Reference in New Issue
Block a user