Make screen slugs editable

This commit is contained in:
2026-07-14 14:49:08 +01:00
parent 1043f26b3e
commit 440b8683f7
5 changed files with 22 additions and 6 deletions
+8 -2
View File
@@ -7,12 +7,18 @@ function slugify(value) {
.replace(/-{2,}/g, '-');
}
async function uniqueScreenSlug(pool, baseSlug) {
async function uniqueScreenSlug(pool, baseSlug, excludeId) {
const start = baseSlug || `screen-${Date.now()}`;
let candidate = start;
let counter = 2;
while (true) {
const [rows] = await pool.query('SELECT id FROM screens WHERE slug = ?', [candidate]);
const params = [candidate];
let sql = 'SELECT id FROM screens WHERE slug = ?';
if (excludeId !== undefined && excludeId !== null) {
sql += ' AND id <> ?';
params.push(excludeId);
}
const [rows] = await pool.query(sql, params);
if (!rows.length) {
return candidate;
}