From 92d72f674598cc8009afef68a171c4ec0f6a06e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 28 Feb 2026 12:25:29 -0500 Subject: [PATCH] refactor: remove admin.themes.getInstalled socket call, and just load the themes in the api call --- .../openapi/read/admin/appearance/themes.yaml | 32 ++++++++++++++++++- public/src/admin/appearance/themes.js | 19 +---------- src/controllers/admin/appearance.js | 7 ++-- src/privileges/admin.js | 1 - src/socket.io/admin/themes.js | 4 --- src/views/admin/appearance/themes.tpl | 6 +++- test/socket.io.js | 13 -------- 7 files changed, 42 insertions(+), 40 deletions(-) diff --git a/public/openapi/read/admin/appearance/themes.yaml b/public/openapi/read/admin/appearance/themes.yaml index d2b2eabb68..d9e5b0e602 100644 --- a/public/openapi/read/admin/appearance/themes.yaml +++ b/public/openapi/read/admin/appearance/themes.yaml @@ -8,4 +8,34 @@ get: content: application/json: schema: - $ref: ../../../components/schemas/CommonProps.yaml#/CommonProps \ No newline at end of file + allOf: + - type: object + properties: + themes: + type: array + items: + type: object + properties: + name: + type: string + id: + type: string + description: + type: string + screenshot: + type: string + screenshot_url: + type: string + type: + type: string + url: + type: string + baseTheme: + type: string + required: + - name + - id + - description + - type + - url + - $ref: ../../../components/schemas/CommonProps.yaml#/CommonProps diff --git a/public/src/admin/appearance/themes.js b/public/src/admin/appearance/themes.js index f2a023206f..2fe0022c77 100644 --- a/public/src/admin/appearance/themes.js +++ b/public/src/admin/appearance/themes.js @@ -72,24 +72,7 @@ define('admin/appearance/themes', ['bootbox', 'translator', 'alerts'], function }); }); - socket.emit('admin.themes.getInstalled', function (err, themes) { - if (err) { - return alerts.error(err); - } - - const instListEl = $('#installed_themes'); - - if (!themes.length) { - instListEl.append($('
  • ').addClass('no-themes').translateHtml('[[admin/appearance/themes:no-themes]]')); - } else { - app.parseAndTranslate('admin/partials/theme_list', { - themes: themes, - }, function (html) { - instListEl.html(html); - highlightSelectedTheme(config['theme:id']); - }); - } - }); + highlightSelectedTheme(config['theme:id']); }; function highlightSelectedTheme(themeId) { diff --git a/src/controllers/admin/appearance.js b/src/controllers/admin/appearance.js index a1384a4185..13fc2ea015 100644 --- a/src/controllers/admin/appearance.js +++ b/src/controllers/admin/appearance.js @@ -1,9 +1,12 @@ 'use strict'; +const meta = require('../../meta'); + const appearanceController = module.exports; -appearanceController.themes = function (req, res) { - res.render(`admin/appearance/themes`, {}); +appearanceController.themes = async function (req, res) { + const themes = await meta.themes.get(); + res.render(`admin/appearance/themes`, { themes }); }; appearanceController.skins = function (req, res) { diff --git a/src/privileges/admin.js b/src/privileges/admin.js index 422e9c1060..ae26ab069a 100644 --- a/src/privileges/admin.js +++ b/src/privileges/admin.js @@ -115,7 +115,6 @@ privsAdmin.socketMap = { 'admin.getSearchDict': 'admin:settings', 'admin.config.setMultiple': 'admin:settings', 'admin.config.remove': 'admin:settings', - 'admin.themes.getInstalled': 'admin:settings', 'admin.themes.set': 'admin:settings', 'admin.reloadAllSessions': 'admin:settings', 'admin.settings.get': 'admin:settings', diff --git a/src/socket.io/admin/themes.js b/src/socket.io/admin/themes.js index 7c8ad7da74..017f6d0c2c 100644 --- a/src/socket.io/admin/themes.js +++ b/src/socket.io/admin/themes.js @@ -5,10 +5,6 @@ const widgets = require('../../widgets'); const Themes = module.exports; -Themes.getInstalled = async function () { - return await meta.themes.get(); -}; - Themes.set = async function (socket, data) { if (!data) { throw new Error('[[error:invalid-data]]'); diff --git a/src/views/admin/appearance/themes.tpl b/src/views/admin/appearance/themes.tpl index 1daa2c24ac..1f01977e0d 100644 --- a/src/views/admin/appearance/themes.tpl +++ b/src/views/admin/appearance/themes.tpl @@ -10,7 +10,11 @@
    - [[admin/appearance/themes:checking-for-installed]] + {{{ if themes.length }}} + + {{{ else }}} +
    [[admin/appearance/themes:no-themes]]
    + {{{ end}}}
    diff --git a/test/socket.io.js b/test/socket.io.js index 2ef06eef4f..45ffb43dd8 100644 --- a/test/socket.io.js +++ b/test/socket.io.js @@ -84,19 +84,6 @@ describe('socket.io', () => { }); }); - it('should get installed themes', (done) => { - const themes = ['nodebb-theme-persona']; - io.emit('admin.themes.getInstalled', (err, data) => { - assert.ifError(err); - assert(data); - const installed = data.map(theme => theme.id); - themes.forEach((theme) => { - assert(installed.includes(theme)); - }); - done(); - }); - }); - it('should ban a user', async () => { const apiUser = require('../src/api/users'); await apiUser.ban({ uid: adminUid }, { uid: regularUid, reason: 'spammer' });