diff --git a/Core/Api/ExtensionEndpoints.cs b/Core/Api/ExtensionEndpoints.cs
index a967057..8ff3b3f 100644
--- a/Core/Api/ExtensionEndpoints.cs
+++ b/Core/Api/ExtensionEndpoints.cs
@@ -52,6 +52,24 @@ Acepta un enlace de GitHub (owner/repo, …/tree/ref/carpeta, …/releases/tag/x
g.MapGet("/{id}/log", (string id, ExtensionManager m) => TypedResults.Ok(new ExtensionLogResponse(m.GetLog(id))))
.WithSummary("Registro de scripts de la extensión");
+ // Iconos: imágenes de terceros. Con "sandbox" y nosniff, un SVG abierto fuera de un
+ // no puede ejecutar nada con el origen del panel.
+ g.MapGet("/{id}/icon", (string id, HttpContext ctx, ExtensionManager m) =>
+ {
+ var file = m.ResolveIconFile(id);
+ if (file is null) return Results.NotFound();
+ IconHeaders(ctx);
+ return Results.File(file, ExtensionFormat.IconContentType(file));
+ }).WithSummary("Icono de una extensión instalada");
+
+ g.MapGet("/catalogs/icon", async (string url, int index, HttpContext ctx, ExtensionManager m, CancellationToken ct) =>
+ {
+ var icon = await m.GetCatalogIconAsync(url, index, ct);
+ if (icon is not { } i) return Results.NotFound();
+ IconHeaders(ctx);
+ return Results.Bytes(i.Bytes, i.ContentType);
+ }).WithSummary("Icono de una entrada de catálogo (se descarga de GitHub y se guarda una hora)");
+
g.MapGet("/catalogs", (bool? refresh, ExtensionManager m, CancellationToken ct) =>
Guard(async () => Results.Ok(await m.GetCatalogsAsync(refresh == true, ct))))
.WithSummary("Catálogos y sus extensiones");
@@ -84,6 +102,16 @@ Acepta un enlace de GitHub (owner/repo, …/tree/ref/carpeta, …/releases/tag/x
return app;
}
+ static void IconHeaders(HttpContext ctx)
+ {
+ var h = ctx.Response.Headers;
+ h["Content-Security-Policy"] = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
+ h["X-Content-Type-Options"] = "nosniff";
+ h["Cross-Origin-Resource-Policy"] = "same-origin";
+ // La URL lleva la versión (?v=), así que puede guardarse.
+ h["Cache-Control"] = "private, max-age=86400";
+ }
+
/// Errores esperables → 400/409/502 con el mensaje (ya traducido), no un 500.
static async Task Guard(Func> action)
{
diff --git a/Core/wwwroot/extensions.js b/Core/wwwroot/extensions.js
index 1b33f0d..6da0643 100644
--- a/Core/wwwroot/extensions.js
+++ b/Core/wwwroot/extensions.js
@@ -9,7 +9,73 @@ let extTimer = null;
let extPreview = null; // vista previa en el modal de instalación
let extOpWatch = null; // sondeo mientras corre una operación
+// Categorías que entiende el panel, en el orden del backend (ExtensionFormat.KnownCategories).
+const EXT_CATEGORIES = ['remote-desktop', 'streaming', 'display', 'input', 'audio', 'network', 'games', 'monitoring', 'tools'];
+let extCategory = ''; // filtro elegido ('' = todas); se recuerda en este navegador
+try { extCategory = localStorage.getItem('osms.ext.category') || ''; } catch { /* sin almacenamiento */ }
+
function extCapLabel(cap) { return t(`ext.cap.${cap}`); }
+function extCategoryLabel(cat) { return t(`ext.category.${cat}`); }
+
+// Entrada de catálogo de una instalada (para lo que no trae su manifiesto).
+function extCatalogEntryOf(x) {
+ for (const c of extCatalogs)
+ for (const e of c.extensions || [])
+ if (e.installedId === x.id) return e;
+ return null;
+}
+
+// Categorías e icono de una instalada: los suyos o, si no trae, los que le da su catálogo.
+function extInstalledCategories(x) {
+ if (x.categories && x.categories.length) return x.categories;
+ const e = extCatalogEntryOf(x);
+ return e && e.categories ? e.categories : [];
+}
+
+function extInstalledIcon(x) {
+ return x.iconUrl || (extCatalogEntryOf(x) || {}).iconUrl || null;
+}
+
+function extIcon(url, name) {
+ const letter = esc((name || '?').trim().charAt(0).toUpperCase() || '?');
+ // Si la imagen no carga, se queda la inicial (está debajo).
+ return `
${letter}${
+ url ? `` : ''}
`;
+}
+
+function extCategoryChips(cats) {
+ return (cats || []).map(c => `${esc(extCategoryLabel(c))}`).join('');
+}
+
+function setExtCategory(cat) {
+ extCategory = cat;
+ try { cat ? localStorage.setItem('osms.ext.category', cat) : localStorage.removeItem('osms.ext.category'); } catch { /* idem */ }
+ renderExtensions();
+}
+
+// Barra de filtros: "Todas" y cada categoría que tenga alguna extensión (instalada o en catálogos).
+function renderExtCategoryBar(installed, available) {
+ const counts = new Map();
+ const seen = new Set();
+ const add = (key, cats) => {
+ if (seen.has(key)) return;
+ seen.add(key);
+ for (const c of cats) counts.set(c, (counts.get(c) || 0) + 1);
+ };
+ for (const x of installed) add(`i:${x.id}`, extInstalledCategories(x));
+ for (const { e } of available) add(e.installedId ? `i:${e.installedId}` : `c:${e.repo}/${e.path || ''}`, e.categories || []);
+
+ const present = EXT_CATEGORIES.filter(c => counts.has(c));
+ if (extCategory && !present.includes(extCategory)) extCategory = '';
+ const bar = byId('ext-categories');
+ if (!present.length) { bar.classList.add('hidden'); renderInto(bar, ''); return; }
+ bar.classList.remove('hidden');
+ const btn = (cat, label, n) =>
+ ``;
+ renderInto(bar, btn('', t('ext.categoryAll'), seen.size) +
+ present.map(c => btn(c, extCategoryLabel(c), counts.get(c))).join(''));
+}
async function loadExtensions() {
const res = await api('GET', '/api/extensions');
@@ -29,24 +95,35 @@ async function loadExtensionCatalogs(refresh = false) {
// ── Vista principal ─────────────────────────────────────────────────────────
function renderExtensions() {
- const list = extState.installed || [];
- byId('ext-count').textContent = list.length;
- renderInto(byId('ext-installed-grid'), list.length
- ? list.map(extCard).join('')
- : `
${esc(t('ext.noneInstalled'))}
`);
+ const all = extState.installed || [];
+ byId('ext-count').textContent = all.length;
const q = (byId('ext-search').value || '').trim().toLowerCase();
- const rows = [];
+ const allRows = [];
for (const c of extCatalogs) {
for (const e of c.extensions || []) {
- const text = `${e.name} ${e.description || ''} ${e.repo} ${(e.tags || []).join(' ')}`.toLowerCase();
- if (!q || text.includes(q)) rows.push({ c, e });
+ const cats = (e.categories || []).map(extCategoryLabel).join(' ');
+ const text = `${e.name} ${e.description || ''} ${e.repo} ${(e.tags || []).join(' ')} ${cats}`.toLowerCase();
+ if (!q || text.includes(q)) allRows.push({ c, e });
}
}
+ renderExtCategoryBar(all, allRows);
+
+ const inCategory = cats => !extCategory || cats.includes(extCategory);
+ const list = all.filter(x => inCategory(extInstalledCategories(x)));
+ const rows = allRows.filter(({ e }) => inCategory(e.categories || []));
+ const emptyFiltered = `