mirror of
https://github.com/directus/directus.git
synced 2026-01-24 05:48:03 -05:00
Return project branding in /server/info endpoint at all times
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
|
||||
@@ -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'
|
||||
@@ -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<string, any> = {};
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user