});
}
+export async function refreshAllMonsterData() {
+ await createFactions();
+ await createMonsters();
+}
+
// run this script manually
if(!module.parent) {
- createFactions().then(createMonsters).then(() => {
+ refreshAllMonsterData().then(() => {
console.log(stats.monsters);
console.log('Complete');
process.exit(0);
}
+export async function refreshAllShopItems() {
+ await createShopEquipment();
+ await createShopItems();
+}
+
if(!module.parent) {
- createShopEquipment().then(createShopItems).then(() => {
+ refreshAllShopItems().then(() => {
console.log('Complete');
process.exit(0);
}).catch(e => {
import { renderMonsterSelector, renderOnlyMonsterSelector } from './views/monster-selector';
import { renderFight, renderFightPreRound, renderRoundDetails } from './views/fight';
import { renderTravel, travelButton } from './views/travel';
+import { renderAdminActions } from './views/admin';
// TEMP!
import { completeDungeonFight, getActiveDungeon, getRoomVists, loadRoom } from './dungeon';
import { renderDungeon, renderDungeonRoom } from './views/dungeons/room';
import { flushBuffer, addEvent } from './events';
+import { Permission } from './permissions';
dotenv();
warning += `<div class="alert error">If you log out without signing up first, this account is lost forever.</div>`;
}
+ if(req.player.permissions.includes(Permission.ADMIN)) {
+ html += `<div class="admin-actions">${renderAdminActions()}</div>`;
+ }
+
html += '<a href="#" hx-post="/logout">Logout</a>';
res.send(warning + html);
});
--- /dev/null
+
+export enum Permission {
+ ADMIN = 'admin',
+ MODERATOR = 'moderator'
+}
--- /dev/null
+import { authEndpoint } from '@server/auth';
+import { Permission } from '@server/permissions';
+import { Request, Response, Router } from 'express';
+import { createAllCitiesAndLocations } from '@seeds/cities';
+import { refreshAllShopItems } from '@seeds/shop_items';
+import { refreshAllMonsterData } from '@seeds/monsters';
+import { createDropTables } from '@seeds/drop-tables';
+import { Alert } from '@server/views/alert';
+import { ADMIN_ACTIONS } from '@server/views/admin';
+
+export const adminRouter = Router();
+
+
+adminRouter.post('/admin/content/refresh/:type', authEndpoint, async (req: Request, res: Response) => {
+ if(!req.player.permissions.includes(Permission.ADMIN)) {
+ return res.sendStatus(403);
+ }
+
+ switch(req.params.type) {
+ case 'cities':
+ await createAllCitiesAndLocations();
+ res.send(Alert('success', 'Cities refreshed') + ADMIN_ACTIONS.get('cities')?.label);
+ break;
+ case 'items':
+ await refreshAllShopItems();
+ res.send(Alert('success', 'Shop items refreshed') + ADMIN_ACTIONS.get('items')?.label);
+ break;
+ case 'monsters':
+ await refreshAllMonsterData();
+ await createDropTables();
+ res.send(Alert('success', 'Monsters and Drop tables refreshed') + ADMIN_ACTIONS.get('monsters')?.label);
+ break;
+ }
+});
export { healerRouter } from './locations/healer';
export { recruiterRouter } from './locations/recruiter';
export { repairRouter } from './locations/repair';
+export { adminRouter } from './admin';
\ No newline at end of file
--- /dev/null
+
+export const ADMIN_ACTIONS = new Map<string, { label: string, action: string }>();
+
+ADMIN_ACTIONS.set('cities', {
+ label: 'Refresh Cities',
+ action: 'cities'
+});
+
+
+ADMIN_ACTIONS.set('items', {
+ label: 'Refresh All Items',
+ action: 'items'
+});
+
+ADMIN_ACTIONS.set('monsters', {
+ label: 'Refresh Monsters',
+ action: 'monsters'
+});
+
+export function renderAdminActions() {
+ return Array.from(ADMIN_ACTIONS.values()).map(action => `<button hx-post="/admin/content/refresh/${action.action}">${action.label}</button>`).join('');
+}
"@shared/*": ["src/shared/*"],
"@server/*": ["src/server/*"],
"@client/*": ["src/client/*"],
- "@assets/*": ["public/assets/*"]
+ "@assets/*": ["public/assets/*"],
+ "@seeds/*": ["seeds/*"]
}
},
"include": ["src/server/api.ts"]