diff --git a/api/src/controllers/server.ts b/api/src/controllers/server.ts index d6fb0f688f..0f20b5fd7c 100644 --- a/api/src/controllers/server.ts +++ b/api/src/controllers/server.ts @@ -20,12 +20,12 @@ router.get('/ping', (req, res) => res.send('pong')); router.get( '/info', - (req, res, next) => { + asyncHandler(async (req, res, next) => { const service = new ServerService({ accountability: req.accountability }); - const data = service.serverInfo(); + const data = await service.serverInfo(); res.locals.payload = { data }; return next(); - }, + }), respond ); diff --git a/api/src/database/seeds/02-rows/02-permissions.yaml b/api/src/database/seeds/02-rows/02-permissions.yaml deleted file mode 100644 index 4b32d9ede6..0000000000 --- a/api/src/database/seeds/02-rows/02-permissions.yaml +++ /dev/null @@ -1,17 +0,0 @@ -table: directus_permissions - -defaults: - role: null - collection: null - action: null - permissions: null - validation: null - presets: null - fields: null - limit: null - -data: - - collection: directus_settings - action: read - permissions: {} - fields: 'project_name,project_logo,project_color,public_foreground,public_background,public_note,custom_css' diff --git a/api/src/database/seeds/02-rows/03-presets.yaml b/api/src/database/seeds/02-rows/02-presets.yaml similarity index 100% rename from api/src/database/seeds/02-rows/03-presets.yaml rename to api/src/database/seeds/02-rows/02-presets.yaml diff --git a/api/src/database/seeds/02-rows/04-relations.yaml b/api/src/database/seeds/02-rows/03-relations.yaml similarity index 100% rename from api/src/database/seeds/02-rows/04-relations.yaml rename to api/src/database/seeds/02-rows/03-relations.yaml diff --git a/api/src/services/server.ts b/api/src/services/server.ts index 8c24228ae9..e734934c26 100644 --- a/api/src/services/server.ts +++ b/api/src/services/server.ts @@ -2,7 +2,6 @@ import { AbstractServiceOptions, Accountability } from '../types'; import Knex from 'knex'; import database from '../database'; import os from 'os'; -import { ForbiddenException } from '../exceptions'; // @ts-ignore import { version } from '../../package.json'; import macosRelease from 'macos-release'; @@ -16,31 +15,57 @@ export class ServerService { this.accountability = options?.accountability || null; } - serverInfo() { - if (this.accountability?.admin !== true) { - throw new ForbiddenException(); - } + async serverInfo() { + const info: Record = {}; - const osType = os.type() === 'Darwin' ? 'macOS' : os.type(); - const osVersion = - osType === 'macOS' - ? `${macosRelease().name} (${macosRelease().version})` - : os.release(); + const projectInfo = await this.knex + .select( + 'project_name', + 'project_logo', + 'project_color', + 'public_foreground', + 'public_background', + 'public_note', + 'custom_css' + ) + .from('directus_settings') + .first(); - return { - directus: { + info.project = projectInfo + ? { + name: projectInfo.project_name, + logo: projectInfo.project_logo, + color: projectInfo.project_color, + foreground: projectInfo.public_foreground, + background: projectInfo.public_background, + note: projectInfo.public_note, + customCSS: projectInfo.custom_css, + } + : null; + + if (this.accountability?.admin === true) { + const osType = os.type() === 'Darwin' ? 'macOS' : os.type(); + + const osVersion = + osType === 'macOS' + ? `${macosRelease().name} (${macosRelease().version})` + : os.release(); + + info.directus = { version, - }, - node: { + }; + info.node = { version: process.versions.node, uptime: Math.round(process.uptime()), - }, - os: { + }; + info.os = { type: osType, version: osVersion, uptime: Math.round(os.uptime()), totalmem: os.totalmem(), - }, - }; + }; + } + + return info; } }