mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 02:43:50 +00:00
refactor: session resource
This commit is contained in:
committed by
Carlos Valente
parent
cf40001a2a
commit
71c468d069
@@ -0,0 +1,16 @@
|
||||
import { getErrorMessage } from 'ontime-utils';
|
||||
import { ErrorResponse, GetInfo } from 'ontime-types';
|
||||
|
||||
import type { Request, Response } from 'express';
|
||||
|
||||
import * as sessionService from './session.service.js';
|
||||
|
||||
export async function getInfo(_req: Request, res: Response<GetInfo | ErrorResponse>) {
|
||||
try {
|
||||
const info = await sessionService.getInfo();
|
||||
res.status(200).send(info);
|
||||
} catch (error) {
|
||||
const message = getErrorMessage(error);
|
||||
res.status(500).send({ message });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import express from 'express';
|
||||
|
||||
import { getInfo } from './session.controller.js';
|
||||
|
||||
export const router = express.Router();
|
||||
|
||||
router.get('/info', getInfo);
|
||||
@@ -0,0 +1,25 @@
|
||||
import { GetInfo } from 'ontime-types';
|
||||
|
||||
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||
import { publicFiles } from '../../setup/index.js';
|
||||
import { getNetworkInterfaces } from '../../utils/networkInterfaces.js';
|
||||
|
||||
/**
|
||||
* Adds business logic to gathering data for the info endpoint
|
||||
*/
|
||||
export async function getInfo(): Promise<GetInfo> {
|
||||
const { version, serverPort } = getDataProvider().getSettings();
|
||||
const osc = getDataProvider().getOsc();
|
||||
|
||||
// get nif and inject localhost
|
||||
const ni = getNetworkInterfaces();
|
||||
ni.unshift({ name: 'localhost', address: '127.0.0.1' });
|
||||
|
||||
return {
|
||||
networkInterfaces: ni,
|
||||
version,
|
||||
serverPort,
|
||||
osc,
|
||||
cssOverride: publicFiles.cssOverride,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user