source: Klonkt/src/routes/artists.js@ 00f669b

main
Last change on this file since 00f669b was 834bcc3, checked in by Robin Genis <roboburr@…>, 3 months ago

i18n: translate Dutch code comments to English across src/

Comments in routes/services/views/config/middleware/assets translated to
English for the public repo. A few dev-facing throw/console message strings
were Englished too. No user-facing UI strings or i18n dictionary values changed
(src/services/i18n.js untouched). Logic unchanged.

Co-Authored-By: Claude <noreply@…>

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * Artists directory — hub mode only.
3 *
4 * GET /leden?q=&page= -> searchable, paginated list of ALL
5 * Klonkt sites. The hub home shows only a limited selection; this page
6 * scales to hundreds/thousands of artists via search + pagination.
7 *
8 * In solo mode there is only one site -> next() (falls through to postsRoutes,
9 * which handles 'artiesten' as an unknown slug).
10 */
11
12import express from 'express';
13import db from '../config/database.js';
14import { renderPage } from '../middleware/render.js';
15import { getTenancy } from '../services/SettingsService.js';
16
17const router = express.Router();
18
19const PER_PAGE = 24;
20
21router.get('/', (req, res, next) => {
22 if (getTenancy() !== 'hub') return next();
23
24 const q = (req.query.q || '').toString().trim().slice(0, 80);
25 let page = parseInt(req.query.page, 10);
26 if (!Number.isFinite(page) || page < 1) page = 1;
27
28 // The main/label site (oldest) is not an artist -> exclude from the directory,
29 // consistent with the hub home which displays it separately.
30 const mainRow = db.prepare('SELECT id FROM sites ORDER BY created_at ASC LIMIT 1').get();
31 const mainId = mainRow ? mainRow.id : '';
32
33 // Search term against title/slug/tagline (case-insensitive via LIKE; SQLite LIKE is
34 // case-insensitive for ASCII by default). ESCAPE '\' makes %, _, and \
35 // in the search term literal (otherwise they would act as wildcards).
36 const like = '%' + q.replace(/[\\%_]/g, (m) => '\\' + m) + '%';
37 const conds = ['s.id != @mainId'];
38 if (q) conds.push("(s.title LIKE @like ESCAPE '\\' OR s.slug LIKE @like ESCAPE '\\' OR s.tagline LIKE @like ESCAPE '\\')");
39 const where = 'WHERE ' + conds.join(' AND ');
40 const params = q ? { mainId, like } : { mainId };
41
42 const total = db.prepare(`SELECT COUNT(*) AS c FROM sites s ${where}`)
43 .get(params).c;
44 const pages = Math.max(1, Math.ceil(total / PER_PAGE));
45 if (page > pages) page = pages;
46 const offset = (page - 1) * PER_PAGE;
47
48 const artists = db.prepare(`
49 SELECT s.slug, s.title, s.tagline, s.profile_photo, s.accent,
50 u.avatar_url AS owner_avatar,
51 (SELECT COUNT(*) FROM posts WHERE site_id = s.id AND status = 'published') AS post_count
52 FROM sites s
53 LEFT JOIN users u ON u.id = s.owner_id
54 ${where}
55 ORDER BY s.title COLLATE NOCASE ASC
56 LIMIT @limit OFFSET @offset
57 `).all({ ...params, limit: PER_PAGE, offset });
58
59 renderPage(req, res, 'pages/artists-directory', {
60 pageTitle: 'Leden',
61 bodyClass: 'on-hub',
62 q,
63 artists,
64 total,
65 page,
66 pages,
67 });
68});
69
70export default router;
Note: See TracBrowser for help on using the repository browser.