mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
Source version from package.json
Signed-off-by: Jonas Zohren <jonas.zohren@adesso.de>
This commit is contained in:
parent
95a809f0a3
commit
139e1156da
1 changed files with 32 additions and 7 deletions
|
@ -1,9 +1,39 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { ServerStatusDto } from './server-status.dto';
|
import { ServerStatusDto } from './server-status.dto';
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import { join as joinPath } from 'path';
|
||||||
|
|
||||||
|
let versionCache: null | {
|
||||||
|
major: number;
|
||||||
|
minor: number;
|
||||||
|
patch: number;
|
||||||
|
preRelease?: string;
|
||||||
|
commit?: string;
|
||||||
|
} = null;
|
||||||
|
async function getServerVersionFromPackageJson() {
|
||||||
|
if (versionCache === null) {
|
||||||
|
const rawFileContent: string = await fs.readFile(
|
||||||
|
joinPath(__dirname, '../../package.json'),
|
||||||
|
{ encoding: 'utf8' },
|
||||||
|
);
|
||||||
|
const packageInfo: { version: string } = JSON.parse(rawFileContent);
|
||||||
|
const versionParts: number[] = packageInfo.version
|
||||||
|
.split('.')
|
||||||
|
.map((x) => parseInt(x, 10));
|
||||||
|
versionCache = {
|
||||||
|
major: versionParts[0],
|
||||||
|
minor: versionParts[1],
|
||||||
|
patch: versionParts[2],
|
||||||
|
preRelease: 'dev', // TODO: Replace this?
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return versionCache;
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MonitoringService {
|
export class MonitoringService {
|
||||||
getServerStatus(): ServerStatusDto {
|
async getServerStatus(): Promise<ServerStatusDto> {
|
||||||
return {
|
return {
|
||||||
connectionSocketQueueLenght: 0,
|
connectionSocketQueueLenght: 0,
|
||||||
destictOnlineUsers: 0,
|
destictOnlineUsers: 0,
|
||||||
|
@ -16,12 +46,7 @@ export class MonitoringService {
|
||||||
onlineRegisteredUsers: 0,
|
onlineRegisteredUsers: 0,
|
||||||
onlineUsers: 0,
|
onlineUsers: 0,
|
||||||
registeredUsers: 0,
|
registeredUsers: 0,
|
||||||
serverVersion: {
|
serverVersion: await getServerVersionFromPackageJson(),
|
||||||
major: 2,
|
|
||||||
minor: 0,
|
|
||||||
patch: 0,
|
|
||||||
preRelease: 'dev',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue