Return project branding in /server/info endpoint at all times

This commit is contained in:
rijkvanzanten
2020-10-26 18:52:51 +01:00
parent 58a6aa3f2f
commit b4f82efcee
5 changed files with 46 additions and 38 deletions

View File

@@ -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
);

View File

@@ -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'

View File

@@ -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;
}
}