Redesign admin peering settings and catalogs

This commit is contained in:
Codex committed 2026-10-11 01:06:03 +02:00
1 parent 492477f86a
commit da40d73f02
16 files changed
+1037 -85

No files matched your search

+14 -8
View File
@@ -54,9 +54,9 @@ function serverName(value) {
return name;
}
function normalizeScopes(value) {
const scopes = [...new Set((Array.isArray(value) ? value : []).map(String))].filter(scope => GRANT_SCOPES.has(scope));
if (scopes.includes('download') && !scopes.includes('catalog')) scopes.push('catalog');
return scopes;
const scopes = new Set((Array.isArray(value) ? value : []).map(String).filter(scope => GRANT_SCOPES.has(scope)));
if (scopes.has('download')) scopes.add('catalog');
return [...GRANT_SCOPES].filter(scope => scopes.has(scope));
}
function scopesFor(peer) {
return Array.isArray(peer.grantScopes) ? normalizeScopes(peer.grantScopes) : ['catalog', 'download'];
@@ -190,12 +190,18 @@ class PeeringState {
return publicPeer(peer, this.outbound());
}
setShare(id, mangaId, enabled) {
const peer = requirePeer(this.load(), id), ids = new Set((peer.shares || []).map(s => s.mangaId));
if (enabled) ids.add(mangaId); else ids.delete(mangaId);
return this.setShares(id, [...ids]);
}
setShares(id, mangaIds) {
const state = this.load(), peer = requirePeer(state, id);
if (typeof mangaId !== 'string' || !mangaId || mangaId.startsWith('.') || mangaId.includes('/') || mangaId.includes('\\')) throw new Error('Invalid manga ID');
peer.shares ||= [];
const existing = peer.shares.find(s => s.mangaId === mangaId);
if (enabled && !existing) peer.shares.push({ mangaId, id: `m${crypto.randomBytes(12).toString('hex')}` });
if (!enabled) peer.shares = peer.shares.filter(s => s.mangaId !== mangaId);
if (!Array.isArray(mangaIds) || mangaIds.length > 5000) throw new Error('Choose no more than 5,000 manga');
const unique = [...new Set(mangaIds)];
if (unique.some(mangaId => typeof mangaId !== 'string' || !mangaId || mangaId.startsWith('.') || mangaId.includes('/') || mangaId.includes('\\')))
throw new Error('Invalid manga ID');
const existing = new Map((peer.shares || []).map(share => [share.mangaId, share]));
peer.shares = unique.map(mangaId => existing.get(mangaId) || { mangaId, id: `m${crypto.randomBytes(12).toString('hex')}` });
atomic(this.stateFile(), state);
return publicPeer(peer, this.outbound());
}