add bookmarks section and fix group cover lightbox
- add bookmarks table, API, admin page and public launcher - persist bookmarks in backup/restore and orphan sweep - fix group cover lightbox via shared image modal - add optional idle unload and trim-after-each to photo-ai - document bookmarks in AGENTS.md
This commit is contained in:
+123
-1
@@ -471,4 +471,126 @@ moduleInput.addEventListener('input', () => {
|
||||
});
|
||||
moduleInput.addEventListener('focus', async () => {
|
||||
if (!moduleInput.value.trim()) renderModuleOptions(await fetchModules('', 50));
|
||||
});
|
||||
});
|
||||
|
||||
(async () => {
|
||||
const fab = document.getElementById('bmFab');
|
||||
const btn = document.getElementById('bmBtn');
|
||||
const modal = document.getElementById('bmModal');
|
||||
const body = document.getElementById('bmModalBody');
|
||||
const closeBtn = document.getElementById('bmClose');
|
||||
if (!fab || !btn || !modal || !body || !closeBtn) return;
|
||||
const authToken = sessionStorage.getItem('authToken');
|
||||
if (!authToken) return;
|
||||
let items = [];
|
||||
try {
|
||||
const res = await fetch(`${API}/api/bookmarks`, { headers: { 'X-Auth-Token': authToken } });
|
||||
if (!res.ok) return;
|
||||
const data = await res.json();
|
||||
items = Array.isArray(data.items) ? data.items : [];
|
||||
} catch (e) { return; }
|
||||
if (!items.length) return;
|
||||
|
||||
function fullSrc(p) {
|
||||
if (!p) return p;
|
||||
if (/^https?:\/\//i.test(p)) return p;
|
||||
return API + p;
|
||||
}
|
||||
function logoSrc(p) {
|
||||
if (!p) return p;
|
||||
if (p.startsWith('/uploads/')) return `${API}/uploads/thumb/${p.slice('/uploads/'.length)}`;
|
||||
if (p.includes('/api/files/')) return p + (p.includes('?') ? '&' : '?') + 'thumb=1';
|
||||
return p;
|
||||
}
|
||||
function hostOf(url) {
|
||||
try { return new URL(url, location.origin).host; } catch (e) { return ''; }
|
||||
}
|
||||
function linkFor(b) {
|
||||
const a = document.createElement('a');
|
||||
a.href = b.url;
|
||||
if (b.open_new_tab) { a.target = '_blank'; a.rel = 'noopener noreferrer'; }
|
||||
return a;
|
||||
}
|
||||
function nameEl(b, cls) {
|
||||
const n = document.createElement('span');
|
||||
n.className = cls;
|
||||
n.textContent = b.title || b.url;
|
||||
return n;
|
||||
}
|
||||
|
||||
const covers = items.filter(b => b.image_mode === 'cover');
|
||||
const logos = items.filter(b => b.image_mode !== 'cover');
|
||||
|
||||
if (covers.length) {
|
||||
const section = document.createElement('div');
|
||||
section.className = 'bm-section';
|
||||
const grid = document.createElement('div');
|
||||
grid.className = 'bm-covers';
|
||||
covers.forEach(b => {
|
||||
const a = linkFor(b);
|
||||
a.className = 'bm-cover-card';
|
||||
if (b.photo_path) {
|
||||
const img = document.createElement('img');
|
||||
img.className = 'bm-cover-img';
|
||||
img.src = fullSrc(b.photo_path);
|
||||
img.alt = '';
|
||||
img.loading = 'lazy';
|
||||
a.appendChild(img);
|
||||
}
|
||||
const info = document.createElement('div');
|
||||
info.className = 'bm-cover-body';
|
||||
info.appendChild(nameEl(b, 'bm-cover-name'));
|
||||
const host = hostOf(b.url);
|
||||
if (host) {
|
||||
const h = document.createElement('span');
|
||||
h.className = 'bm-host';
|
||||
h.textContent = host;
|
||||
info.appendChild(h);
|
||||
}
|
||||
a.appendChild(info);
|
||||
grid.appendChild(a);
|
||||
});
|
||||
section.append(grid);
|
||||
body.appendChild(section);
|
||||
}
|
||||
|
||||
if (logos.length) {
|
||||
const section = document.createElement('div');
|
||||
section.className = 'bm-section';
|
||||
const row = document.createElement('div');
|
||||
row.className = 'bm-logos';
|
||||
logos.forEach(b => {
|
||||
const a = linkFor(b);
|
||||
a.className = 'bm-logo-card';
|
||||
if (b.photo_path) {
|
||||
const img = document.createElement('img');
|
||||
img.className = 'bm-logo-img';
|
||||
img.src = logoSrc(b.photo_path);
|
||||
img.alt = '';
|
||||
img.loading = 'lazy';
|
||||
a.appendChild(img);
|
||||
} else {
|
||||
const ph = document.createElement('span');
|
||||
ph.className = 'bm-logo-ph';
|
||||
ph.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"/></svg>';
|
||||
a.appendChild(ph);
|
||||
}
|
||||
a.appendChild(nameEl(b, 'bm-logo-name'));
|
||||
row.appendChild(a);
|
||||
});
|
||||
section.append(row);
|
||||
body.appendChild(section);
|
||||
}
|
||||
|
||||
fab.hidden = false;
|
||||
|
||||
function setOpen(open) {
|
||||
modal.classList.toggle('open', open);
|
||||
modal.setAttribute('aria-hidden', open ? 'false' : 'true');
|
||||
btn.setAttribute('aria-expanded', open ? 'true' : 'false');
|
||||
}
|
||||
btn.addEventListener('click', () => setOpen(!modal.classList.contains('open')));
|
||||
closeBtn.addEventListener('click', () => setOpen(false));
|
||||
modal.addEventListener('click', (e) => { if (e.target === modal) setOpen(false); });
|
||||
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && modal.classList.contains('open')) setOpen(false); });
|
||||
})();
|
||||
Reference in New Issue
Block a user