| 1 | /**
|
|---|
| 2 | * Admin: Site management — Phase E.
|
|---|
| 3 | *
|
|---|
| 4 | * GET /admin/sites -> list all sites
|
|---|
| 5 | * GET /admin/sites/new -> create form
|
|---|
| 6 | * POST /admin/sites/create -> insert + redirect to edit
|
|---|
| 7 | * GET /admin/sites/:slug/edit -> edit form
|
|---|
| 8 | * POST /admin/sites/:slug/save -> update
|
|---|
| 9 | * POST /admin/sites/:slug/delete-> delete (refuses if site has posts)
|
|---|
| 10 | *
|
|---|
| 11 | * God-only (requireGod middleware). Slug is immutable after create — too
|
|---|
| 12 | * many things hang off it (URLs, manifest scope, federation). If you really
|
|---|
| 13 | * need to rename: delete + re-create.
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | import express from 'express';
|
|---|
| 17 | import path from 'path';
|
|---|
| 18 | import fs from 'fs';
|
|---|
| 19 | import { fileURLToPath } from 'url';
|
|---|
| 20 | import multer from 'multer';
|
|---|
| 21 | import { v4 as uuid } from 'uuid';
|
|---|
| 22 | import db from '../config/database.js';
|
|---|
| 23 | import { renderPage } from '../middleware/render.js';
|
|---|
| 24 | import { requireGod, requireAuth, requireSiteManagerBySlug } from '../middleware/auth.js';
|
|---|
| 25 | import ThemeService from '../services/ThemeService.js';
|
|---|
| 26 | import { listPlatforms, PLATFORMS } from '../services/PlatformIcons.js';
|
|---|
| 27 | import { toWebp } from '../services/ImageWebpService.js';
|
|---|
| 28 |
|
|---|
| 29 | const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|---|
| 30 |
|
|---|
| 31 | // Profile photos share the avatar directory with user avatars — same physical
|
|---|
| 32 | // folder, same URL prefix. Filenames are uuid-prefixed so site photos and
|
|---|
| 33 | // user avatars never collide.
|
|---|
| 34 | const PHOTO_DIR = path.resolve(
|
|---|
| 35 | process.env.AVATAR_PATH || path.join(__dirname, '..', '..', 'storage', 'media', 'avatars')
|
|---|
| 36 | );
|
|---|
| 37 | fs.mkdirSync(PHOTO_DIR, { recursive: true });
|
|---|
| 38 |
|
|---|
| 39 | const ALLOWED_PHOTO_EXT = new Set(['.jpg', '.jpeg', '.png', '.webp', '.gif']);
|
|---|
| 40 | const MAX_PHOTO_BYTES = 5 * 1024 * 1024;
|
|---|
| 41 | const photoUpload = multer({
|
|---|
| 42 | storage: multer.diskStorage({
|
|---|
| 43 | destination: (req, file, cb) => cb(null, PHOTO_DIR),
|
|---|
| 44 | filename: (req, file, cb) => {
|
|---|
| 45 | const ext = path.extname(file.originalname || '').toLowerCase() || '.jpg';
|
|---|
| 46 | cb(null, `site-${uuid()}${ext}`);
|
|---|
| 47 | },
|
|---|
| 48 | }),
|
|---|
| 49 | limits: { fileSize: MAX_PHOTO_BYTES },
|
|---|
| 50 | fileFilter: (req, file, cb) => {
|
|---|
| 51 | const ext = path.extname(file.originalname || '').toLowerCase();
|
|---|
| 52 | if (!ALLOWED_PHOTO_EXT.has(ext)) {
|
|---|
| 53 | return cb(new Error('Alleen JPG/PNG/WebP/GIF toegestaan'));
|
|---|
| 54 | }
|
|---|
| 55 | cb(null, true);
|
|---|
| 56 | },
|
|---|
| 57 | });
|
|---|
| 58 |
|
|---|
| 59 | /** Coerce req.body fields into the JSON profile_links array. */
|
|---|
| 60 | function buildProfileLinks(body) {
|
|---|
| 61 | const platforms = body.profile_link_platform || [];
|
|---|
| 62 | const urls = body.profile_link_url || [];
|
|---|
| 63 | const arr = [];
|
|---|
| 64 | const platformsArr = Array.isArray(platforms) ? platforms : [platforms];
|
|---|
| 65 | const urlsArr = Array.isArray(urls) ? urls : [urls];
|
|---|
| 66 | for (let i = 0; i < platformsArr.length; i++) {
|
|---|
| 67 | const p = (platformsArr[i] || '').toString().trim();
|
|---|
| 68 | const u = (urlsArr[i] || '').toString().trim();
|
|---|
| 69 | if (!p || !u) continue;
|
|---|
| 70 | if (!PLATFORMS[p]) continue;
|
|---|
| 71 | if (!/^https?:\/\//i.test(u) && p !== 'email') continue;
|
|---|
| 72 | if (p === 'email' && !/^mailto:|^[^\s@]+@[^\s@]+$/i.test(u)) continue;
|
|---|
| 73 | arr.push({ platform: p, url: u });
|
|---|
| 74 | }
|
|---|
| 75 | return arr.length ? JSON.stringify(arr) : null;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | const router = express.Router();
|
|---|
| 79 |
|
|---|
| 80 | // ==================== UPLOAD PROFILE PHOTO (JSON) ====================
|
|---|
| 81 | // POST /admin/sites/upload-photo → { ok: true, url: '/media/avatars/<filename>' }
|
|---|
| 82 | // Used by the admin-site-edit form's photo picker. The form itself still
|
|---|
| 83 | // holds the URL string in `profile_photo` — this endpoint just stores the
|
|---|
| 84 | // file and hands back a URL that the form can paste into the input field.
|
|---|
| 85 | router.post('/upload-photo', requireAuth, (req, res) => {
|
|---|
| 86 | photoUpload.single('photo')(req, res, (err) => {
|
|---|
| 87 | if (err) return res.status(400).json({ ok: false, error: err.message });
|
|---|
| 88 | if (!req.file) return res.status(400).json({ ok: false, error: 'Geen bestand ontvangen' });
|
|---|
| 89 | res.json({
|
|---|
| 90 | ok: true,
|
|---|
| 91 | url: `/media/avatars/${toWebp(req.file)}`,
|
|---|
| 92 | size: req.file.size,
|
|---|
| 93 | mime: req.file.mimetype,
|
|---|
| 94 | });
|
|---|
| 95 | });
|
|---|
| 96 | });
|
|---|
| 97 |
|
|---|
| 98 | const RESERVED_SITE_SLUGS = new Set([
|
|---|
| 99 | 'auth', 'admin', 'login', 'register', 'logout', 'archive', 'search',
|
|---|
| 100 | 'account', 'sites', 'comments', 'posts', 'media', 'audio', 'prutter',
|
|---|
| 101 | 'forum', 'tag', 'user', 'users', 'artiesten', 'leden', 'feed.xml', 'atom.xml', 'sitemap.xml',
|
|---|
| 102 | 'manifest.webmanifest', 'sw.js', 'favicon.ico', 'favicon.svg', 'assets',
|
|---|
| 103 | ]);
|
|---|
| 104 |
|
|---|
| 105 | function siteEditableFields() {
|
|---|
| 106 | return {
|
|---|
| 107 | title: '',
|
|---|
| 108 | description: '',
|
|---|
| 109 | tagline: '',
|
|---|
| 110 | language: 'nl',
|
|---|
| 111 | palette: 'klonkt',
|
|---|
| 112 | accent: '#e8b04b',
|
|---|
| 113 | profile_photo: '',
|
|---|
| 114 | profile_enabled: 1,
|
|---|
| 115 | profile_name: '',
|
|---|
| 116 | profile_bio: '',
|
|---|
| 117 | is_public: 1,
|
|---|
| 118 | robots_index: 1,
|
|---|
| 119 | require_login_to_comment: 1,
|
|---|
| 120 | enable_audio_player: 1,
|
|---|
| 121 | enable_prutter: 1,
|
|---|
| 122 | comments_moderation_mode: 'moderate',
|
|---|
| 123 | feed_view_default: 'grid',
|
|---|
| 124 | feed_view_switch: 1,
|
|---|
| 125 | show_search: 1,
|
|---|
| 126 | show_archive_link: 1,
|
|---|
| 127 | title_template: '{title} — {site}',
|
|---|
| 128 | twitter: '',
|
|---|
| 129 | canonical: '',
|
|---|
| 130 | google_verification: '',
|
|---|
| 131 | bing_verification: '',
|
|---|
| 132 | pinterest_verification: '',
|
|---|
| 133 | yandex_verification: '',
|
|---|
| 134 | custom_css: '',
|
|---|
| 135 | custom_head_html: '',
|
|---|
| 136 | custom_foot_html: '',
|
|---|
| 137 | };
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | /** Geldige user-id voor owner-toewijzing, of null bij leeg/onbekend. */
|
|---|
| 141 | function validOwnerId(raw) {
|
|---|
| 142 | const id = (raw || '').toString().trim();
|
|---|
| 143 | if (!id) return null;
|
|---|
| 144 | return db.prepare('SELECT 1 FROM users WHERE id = ?').get(id) ? id : null;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | /** Geef een user admin-rechten op een site (idempotent upsert). */
|
|---|
| 148 | function grantSiteAdmin(siteId, userId) {
|
|---|
| 149 | db.prepare(`
|
|---|
| 150 | INSERT INTO site_members (site_id, user_id, role) VALUES (?, ?, 'admin')
|
|---|
| 151 | ON CONFLICT(site_id, user_id) DO UPDATE SET role = 'admin'
|
|---|
| 152 | `).run(siteId, userId);
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | /** Kandidaat-owners voor het owner-keuzeveld (god-only). */
|
|---|
| 156 | function listOwnerCandidates() {
|
|---|
| 157 | return db.prepare('SELECT id, username, role FROM users ORDER BY username').all();
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | // ==================== LIST ====================
|
|---|
| 161 | router.get('/', requireGod, (req, res) => {
|
|---|
| 162 | const sites = db.prepare(`
|
|---|
| 163 | SELECT s.id, s.slug, s.title, s.description, s.created_at,
|
|---|
| 164 | s.is_public, s.robots_index, s.is_primary,
|
|---|
| 165 | u.username AS owner_username,
|
|---|
| 166 | (SELECT COUNT(*) FROM posts WHERE site_id = s.id) AS post_count
|
|---|
| 167 | FROM sites s LEFT JOIN users u ON u.id = s.owner_id
|
|---|
| 168 | ORDER BY s.is_primary DESC, s.created_at DESC
|
|---|
| 169 | `).all();
|
|---|
| 170 |
|
|---|
| 171 | renderPage(req, res, 'pages/admin-sites', {
|
|---|
| 172 | pageTitle: 'Sites',
|
|---|
| 173 | bodyClass: 'on-admin',
|
|---|
| 174 | sites,
|
|---|
| 175 | success: req.query.success || null,
|
|---|
| 176 | error: req.query.error || null,
|
|---|
| 177 | });
|
|---|
| 178 | });
|
|---|
| 179 |
|
|---|
| 180 | // ==================== NEW (form) ====================
|
|---|
| 181 | router.get('/new', requireGod, (req, res) => {
|
|---|
| 182 | renderPage(req, res, 'pages/admin-site-edit', {
|
|---|
| 183 | pageTitle: 'New site',
|
|---|
| 184 | bodyClass: 'on-admin',
|
|---|
| 185 | isNew: true,
|
|---|
| 186 | // ?owner=<id> (vanaf de gebruikers-pagina: "geef deze user een Klonkt") wordt
|
|---|
| 187 | // voorgeselecteerd; anders de aanmakende god.
|
|---|
| 188 | site: { slug: '', owner_id: validOwnerId(req.query.owner) || req.session.user.id, ...siteEditableFields() },
|
|---|
| 189 | users: listOwnerCandidates(),
|
|---|
| 190 | palettes: ThemeService.listPalettes(),
|
|---|
| 191 | accents: ThemeService.listAccents(),
|
|---|
| 192 | platforms: listPlatforms(),
|
|---|
| 193 | parsedLinks: [],
|
|---|
| 194 | error: null,
|
|---|
| 195 | });
|
|---|
| 196 | });
|
|---|
| 197 |
|
|---|
| 198 | // ==================== CREATE ====================
|
|---|
| 199 | router.post('/create', requireGod, (req, res) => {
|
|---|
| 200 | const slug = (req.body.slug || '').toString().toLowerCase().trim();
|
|---|
| 201 | if (!/^[a-z0-9_-]{2,40}$/.test(slug)) {
|
|---|
| 202 | return res.redirect('/admin/sites/new?error=' + encodeURIComponent('Slug: 2-40 chars, letters/numbers/underscore/dash'));
|
|---|
| 203 | }
|
|---|
| 204 | if (RESERVED_SITE_SLUGS.has(slug)) {
|
|---|
| 205 | return res.redirect('/admin/sites/new?error=' + encodeURIComponent('That slug is reserved'));
|
|---|
| 206 | }
|
|---|
| 207 | const existing = db.prepare('SELECT id FROM sites WHERE slug = ?').get(slug);
|
|---|
| 208 | if (existing) {
|
|---|
| 209 | return res.redirect('/admin/sites/new?error=' + encodeURIComponent('Slug already taken'));
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | const f = { ...siteEditableFields(), ...req.body };
|
|---|
| 213 |
|
|---|
| 214 | // Owner: god mag de site aan een ANDERE gebruiker toewijzen — dit is de kern
|
|---|
| 215 | // van hub-modus (elke gebruiker z'n eigen, zelf te beheren Klonkt). Leeg of
|
|---|
| 216 | // ongeldig → de aanmakende god zelf.
|
|---|
| 217 | const ownerId = validOwnerId(req.body.owner_id) || req.session.user.id;
|
|---|
| 218 |
|
|---|
| 219 | const siteId = uuid();
|
|---|
| 220 | db.prepare(`
|
|---|
| 221 | INSERT INTO sites (
|
|---|
| 222 | id, slug, title, description, tagline, owner_id,
|
|---|
| 223 | language, palette, accent, profile_photo,
|
|---|
| 224 | is_public, robots_index, require_login_to_comment, enable_audio_player,
|
|---|
| 225 | feed_view_default, comments_moderation_mode
|
|---|
| 226 | ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|---|
| 227 | `).run(
|
|---|
| 228 | siteId, slug,
|
|---|
| 229 | (f.title || slug).slice(0, 200),
|
|---|
| 230 | (f.description || '').slice(0, 500),
|
|---|
| 231 | (f.tagline || '').slice(0, 200),
|
|---|
| 232 | ownerId,
|
|---|
| 233 | f.language || 'nl',
|
|---|
| 234 | f.palette || 'klonkt',
|
|---|
| 235 | ThemeService.validateAccent(f.accent) || '#e8b04b',
|
|---|
| 236 | f.profile_photo || null,
|
|---|
| 237 | f.is_public ? 1 : 0,
|
|---|
| 238 | f.robots_index ? 1 : 0,
|
|---|
| 239 | f.require_login_to_comment ? 1 : 0,
|
|---|
| 240 | (f.enable_audio_player !== undefined ? (f.enable_audio_player ? 1 : 0) : 1),
|
|---|
| 241 | f.feed_view_default === 'timeline' ? 'timeline' : 'grid',
|
|---|
| 242 | f.comments_moderation_mode === 'trust' ? 'trust' : 'moderate',
|
|---|
| 243 | );
|
|---|
| 244 |
|
|---|
| 245 | // De OWNER (niet per se de aanmaker) krijgt een site_members-admin-rij → zo komt
|
|---|
| 246 | // 'ie door canAdminSite + de requireSiteManager-gates en beheert 'ie z'n site.
|
|---|
| 247 | grantSiteAdmin(siteId, ownerId);
|
|---|
| 248 |
|
|---|
| 249 | res.redirect(`/admin/sites/${slug}/edit?success=` + encodeURIComponent('Site aangemaakt'));
|
|---|
| 250 | });
|
|---|
| 251 |
|
|---|
| 252 | // ==================== EDIT (form) ====================
|
|---|
| 253 | router.get('/:slug/edit', requireSiteManagerBySlug, (req, res) => {
|
|---|
| 254 | const site = db.prepare('SELECT * FROM sites WHERE slug = ?').get(req.params.slug);
|
|---|
| 255 | if (!site) return res.redirect('/admin/sites?error=Not+found');
|
|---|
| 256 |
|
|---|
| 257 | let parsedLinks = [];
|
|---|
| 258 | if (site.profile_links) {
|
|---|
| 259 | try { parsedLinks = JSON.parse(site.profile_links) || []; } catch {}
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | renderPage(req, res, 'pages/admin-site-edit', {
|
|---|
| 263 | pageTitle: `Edit: ${site.title}`,
|
|---|
| 264 | bodyClass: 'on-admin',
|
|---|
| 265 | isNew: false,
|
|---|
| 266 | site,
|
|---|
| 267 | users: listOwnerCandidates(),
|
|---|
| 268 | palettes: ThemeService.listPalettes(),
|
|---|
| 269 | accents: ThemeService.listAccents(),
|
|---|
| 270 | platforms: listPlatforms(),
|
|---|
| 271 | parsedLinks,
|
|---|
| 272 | success: req.query.success || null,
|
|---|
| 273 | error: req.query.error || null,
|
|---|
| 274 | });
|
|---|
| 275 | });
|
|---|
| 276 |
|
|---|
| 277 | // ==================== SAVE ====================
|
|---|
| 278 | router.post('/:slug/save', requireSiteManagerBySlug, (req, res) => {
|
|---|
| 279 | const site = db.prepare('SELECT id FROM sites WHERE slug = ?').get(req.params.slug);
|
|---|
| 280 | if (!site) return res.redirect('/admin/sites?error=Not+found');
|
|---|
| 281 |
|
|---|
| 282 | const f = req.body;
|
|---|
| 283 | const moderationMode = f.comments_moderation_mode === 'moderate' ? 'moderate' : 'trust';
|
|---|
| 284 | const feedViewDef = f.feed_view_default === 'grid' ? 'grid' : 'timeline';
|
|---|
| 285 | const profileLinksJson = buildProfileLinks(f);
|
|---|
| 286 |
|
|---|
| 287 | // theme_override: only accept the three legal values. Empty string means
|
|---|
| 288 | // "Auto" — defer to user's prefers-color-scheme on first paint.
|
|---|
| 289 | const themeOverride = ['light', 'dark'].includes(f.theme_override) ? f.theme_override : '';
|
|---|
| 290 |
|
|---|
| 291 | // accent: only accept colors from the curated ACCENTS list. Falls back to
|
|---|
| 292 | // the orange default if the submitted value isn't recognised.
|
|---|
| 293 | const accent = ThemeService.validateAccent(f.accent) || '#e8b04b';
|
|---|
| 294 |
|
|---|
| 295 | db.prepare(`
|
|---|
| 296 | UPDATE sites SET
|
|---|
| 297 | title = ?, description = ?, tagline = ?, language = ?,
|
|---|
| 298 | palette = ?, accent = ?, theme_override = ?, profile_photo = ?,
|
|---|
| 299 | profile_enabled = ?,
|
|---|
| 300 | profile_links = ?,
|
|---|
| 301 | is_public = ?, robots_index = ?, require_login_to_comment = ?,
|
|---|
| 302 | enable_audio_player = ?, enable_prutter = ?,
|
|---|
| 303 | comments_moderation_mode = ?,
|
|---|
| 304 | feed_view_default = ?, feed_view_switch = ?,
|
|---|
| 305 | show_search = ?, show_archive_link = ?,
|
|---|
| 306 | custom_css = ?, custom_head_html = ?, custom_foot_html = ?,
|
|---|
| 307 | updated_at = CURRENT_TIMESTAMP
|
|---|
| 308 | WHERE id = ?
|
|---|
| 309 | `).run(
|
|---|
| 310 | (f.title || '').slice(0, 200),
|
|---|
| 311 | (f.description || '').slice(0, 500),
|
|---|
| 312 | (f.tagline || '').slice(0, 200),
|
|---|
| 313 | f.language || 'nl',
|
|---|
| 314 | f.palette || 'klonkt',
|
|---|
| 315 | accent,
|
|---|
| 316 | themeOverride,
|
|---|
| 317 | f.profile_photo || null,
|
|---|
| 318 | f.profile_enabled ? 1 : 0,
|
|---|
| 319 | profileLinksJson,
|
|---|
| 320 | f.is_public ? 1 : 0,
|
|---|
| 321 | f.robots_index ? 1 : 0,
|
|---|
| 322 | f.require_login_to_comment ? 1 : 0,
|
|---|
| 323 | f.enable_audio_player ? 1 : 0,
|
|---|
| 324 | f.enable_prutter ? 1 : 0,
|
|---|
| 325 | moderationMode,
|
|---|
| 326 | feedViewDef,
|
|---|
| 327 | f.feed_view_switch ? 1 : 0,
|
|---|
| 328 | f.show_search ? 1 : 0,
|
|---|
| 329 | f.show_archive_link ? 1 : 0,
|
|---|
| 330 | f.custom_css || null,
|
|---|
| 331 | f.custom_head_html || null,
|
|---|
| 332 | f.custom_foot_html || null,
|
|---|
| 333 | site.id,
|
|---|
| 334 | );
|
|---|
| 335 |
|
|---|
| 336 | // Owner (her)toewijzen — ALLEEN god. Een site-owner die z'n eigen site bewerkt
|
|---|
| 337 | // kan de eigenaar niet wijzigen (het veld wordt voor niet-god ook niet getoond).
|
|---|
| 338 | if (req.session.user.role === 'god') {
|
|---|
| 339 | const newOwner = validOwnerId(req.body.owner_id);
|
|---|
| 340 | if (newOwner) {
|
|---|
| 341 | db.prepare('UPDATE sites SET owner_id = ? WHERE id = ?').run(newOwner, site.id);
|
|---|
| 342 | grantSiteAdmin(site.id, newOwner);
|
|---|
| 343 | }
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | res.redirect(`/admin/sites/${req.params.slug}/edit?success=` + encodeURIComponent('Opgeslagen'));
|
|---|
| 347 | });
|
|---|
| 348 |
|
|---|
| 349 | // ==================== MAAK PRIMAIR ====================
|
|---|
| 350 | // God kiest welke site de primaire/hoofd-site is (de label-/bedrijfssite in hub;
|
|---|
| 351 | // in solo dé site). Precies één site is primair → eerst alles uit, dan deze aan.
|
|---|
| 352 | router.post('/:slug/make-primary', requireGod, (req, res) => {
|
|---|
| 353 | const site = db.prepare('SELECT id FROM sites WHERE slug = ?').get(req.params.slug);
|
|---|
| 354 | if (!site) return res.redirect('/admin/sites?error=Niet+gevonden');
|
|---|
| 355 | db.transaction(() => {
|
|---|
| 356 | db.prepare('UPDATE sites SET is_primary = 0').run();
|
|---|
| 357 | db.prepare('UPDATE sites SET is_primary = 1 WHERE id = ?').run(site.id);
|
|---|
| 358 | })();
|
|---|
| 359 | res.redirect('/admin/sites?success=' + encodeURIComponent('Primaire site bijgewerkt'));
|
|---|
| 360 | });
|
|---|
| 361 |
|
|---|
| 362 | // ==================== DELETE ====================
|
|---|
| 363 | router.post('/:slug/delete', requireGod, (req, res) => {
|
|---|
| 364 | const site = db.prepare('SELECT id FROM sites WHERE slug = ?').get(req.params.slug);
|
|---|
| 365 | if (!site) return res.redirect('/admin/sites?error=Not+found');
|
|---|
| 366 |
|
|---|
| 367 | const postCount = db.prepare('SELECT COUNT(*) AS c FROM posts WHERE site_id = ?').get(site.id).c;
|
|---|
| 368 | if (postCount > 0) {
|
|---|
| 369 | return res.redirect('/admin/sites?error=' + encodeURIComponent(`Cannot delete: site has ${postCount} post(s). Delete posts first.`));
|
|---|
| 370 | }
|
|---|
| 371 |
|
|---|
| 372 | // Clean up site_members and audio_tracks (no posts to worry about).
|
|---|
| 373 | db.prepare('DELETE FROM site_members WHERE site_id = ?').run(site.id);
|
|---|
| 374 | db.prepare('DELETE FROM audio_tracks WHERE site_id = ?').run(site.id);
|
|---|
| 375 | db.prepare('DELETE FROM sites WHERE id = ?').run(site.id);
|
|---|
| 376 |
|
|---|
| 377 | res.redirect('/admin/sites?success=' + encodeURIComponent('Site deleted'));
|
|---|
| 378 | });
|
|---|
| 379 |
|
|---|
| 380 | export default router;
|
|---|