mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-05 22:39:11 +00:00
refactor: session resource
This commit is contained in:
committed by
Carlos Valente
parent
cf40001a2a
commit
71c468d069
@@ -1,5 +1,5 @@
|
|||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { AxiosResponse } from 'axios';
|
||||||
import { DatabaseModel, GetInfo, MessageResponse, ProjectData, ProjectFileListResponse } from 'ontime-types';
|
import { DatabaseModel, MessageResponse, ProjectData, ProjectFileListResponse } from 'ontime-types';
|
||||||
|
|
||||||
import { makeCSV, makeTable } from '../../features/cuesheet/cuesheetUtils';
|
import { makeCSV, makeTable } from '../../features/cuesheet/cuesheetUtils';
|
||||||
|
|
||||||
@@ -138,14 +138,6 @@ export async function deleteProject(filename: string): Promise<MessageResponse>
|
|||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* HTTP request to retrieve application info
|
|
||||||
*/
|
|
||||||
export async function getInfo(): Promise<GetInfo> {
|
|
||||||
const res = await axios.get(`${dbPath}/info`);
|
|
||||||
return res.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function gets project from db
|
* Utility function gets project from db
|
||||||
* @param fileName
|
* @param fileName
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
import { GetInfo } from 'ontime-types';
|
||||||
|
|
||||||
|
import { apiEntryUrl } from './constants';
|
||||||
|
|
||||||
|
const sessionPath = `${apiEntryUrl}/session`;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request to retrieve application info
|
||||||
|
*/
|
||||||
|
export async function getInfo(): Promise<GetInfo> {
|
||||||
|
const res = await axios.get(`${sessionPath}/info`);
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ import { GetInfo } from 'ontime-types';
|
|||||||
|
|
||||||
import { queryRefetchIntervalSlow } from '../../ontimeConfig';
|
import { queryRefetchIntervalSlow } from '../../ontimeConfig';
|
||||||
import { APP_INFO } from '../api/constants';
|
import { APP_INFO } from '../api/constants';
|
||||||
import { getInfo } from '../api/db';
|
import { getInfo } from '../api/session';
|
||||||
import { ontimePlaceholderInfo } from '../models/Info';
|
import { ontimePlaceholderInfo } from '../models/Info';
|
||||||
|
|
||||||
export default function useInfo() {
|
export default function useInfo() {
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
import {
|
import { DatabaseModel, ErrorResponse, MessageResponse, ProjectData, ProjectFileListResponse } from 'ontime-types';
|
||||||
DatabaseModel,
|
|
||||||
ErrorResponse,
|
|
||||||
GetInfo,
|
|
||||||
MessageResponse,
|
|
||||||
ProjectData,
|
|
||||||
ProjectFileListResponse,
|
|
||||||
} from 'ontime-types';
|
|
||||||
import { getErrorMessage } from 'ontime-utils';
|
import { getErrorMessage } from 'ontime-utils';
|
||||||
|
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
@@ -241,13 +234,3 @@ export async function deleteProjectFile(req: Request, res: Response<MessageRespo
|
|||||||
res.status(500).send({ message });
|
res.status(500).send({ message });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getInfo(_req: Request, res: Response<GetInfo | ErrorResponse>) {
|
|
||||||
try {
|
|
||||||
const info = await projectService.getInfo();
|
|
||||||
res.status(200).send(info);
|
|
||||||
} catch (error) {
|
|
||||||
const message = getErrorMessage(error);
|
|
||||||
res.status(500).send({ message });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import {
|
|||||||
currentProjectDownload,
|
currentProjectDownload,
|
||||||
deleteProjectFile,
|
deleteProjectFile,
|
||||||
duplicateProjectFile,
|
duplicateProjectFile,
|
||||||
getInfo,
|
|
||||||
listProjects,
|
listProjects,
|
||||||
loadProject,
|
loadProject,
|
||||||
patchPartialProjectFile,
|
patchPartialProjectFile,
|
||||||
@@ -37,5 +36,3 @@ router.post('/load', validateFilenameBody, loadProject);
|
|||||||
router.post('/:filename/duplicate', validateFilenameParam, validateNewFilenameBody, duplicateProjectFile);
|
router.post('/:filename/duplicate', validateFilenameParam, validateNewFilenameBody, duplicateProjectFile);
|
||||||
router.put('/:filename/rename', validateFilenameParam, validateNewFilenameBody, renameProjectFile);
|
router.put('/:filename/rename', validateFilenameParam, validateNewFilenameBody, renameProjectFile);
|
||||||
router.delete('/:filename', validateFilenameParam, deleteProjectFile);
|
router.delete('/:filename', validateFilenameParam, deleteProjectFile);
|
||||||
|
|
||||||
router.get('/info', getInfo);
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { router as rundownRouter } from './rundown/rundown.router.js';
|
|||||||
import { router as settingsRouter } from './settings/settings.router.js';
|
import { router as settingsRouter } from './settings/settings.router.js';
|
||||||
import { router as sheetsRouter } from './sheets/sheets.router.js';
|
import { router as sheetsRouter } from './sheets/sheets.router.js';
|
||||||
import { router as excelRouter } from './excel/excel.router.js';
|
import { router as excelRouter } from './excel/excel.router.js';
|
||||||
|
import { router as sessionRouter } from './session/session.router.js';
|
||||||
import { router as viewSettingsRouter } from './view-settings/viewSettings.router.js';
|
import { router as viewSettingsRouter } from './view-settings/viewSettings.router.js';
|
||||||
|
|
||||||
export const appRouter = express.Router();
|
export const appRouter = express.Router();
|
||||||
@@ -24,6 +25,7 @@ appRouter.use('/settings', settingsRouter);
|
|||||||
appRouter.use('/sheets', sheetsRouter);
|
appRouter.use('/sheets', sheetsRouter);
|
||||||
appRouter.use('/excel', excelRouter);
|
appRouter.use('/excel', excelRouter);
|
||||||
appRouter.use('/url-presets', urlPresetsRouter);
|
appRouter.use('/url-presets', urlPresetsRouter);
|
||||||
|
appRouter.use('/session', sessionRouter);
|
||||||
appRouter.use('/view-settings', viewSettingsRouter);
|
appRouter.use('/view-settings', viewSettingsRouter);
|
||||||
|
|
||||||
//we don't want to redirect to react index when using api routes
|
//we don't want to redirect to react index when using api routes
|
||||||
|
|||||||
@@ -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,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
import { DatabaseModel, GetInfo, LogOrigin, ProjectData, ProjectFileListResponse } from 'ontime-types';
|
import { DatabaseModel, LogOrigin, ProjectData, ProjectFileListResponse } from 'ontime-types';
|
||||||
import { getErrorMessage } from 'ontime-utils';
|
import { getErrorMessage } from 'ontime-utils';
|
||||||
|
|
||||||
import { copyFile, rename } from 'fs/promises';
|
import { copyFile, rename } from 'fs/promises';
|
||||||
|
|
||||||
import { logger } from '../../classes/Logger.js';
|
import { logger } from '../../classes/Logger.js';
|
||||||
import { getNetworkInterfaces } from '../../utils/networkInterfaces.js';
|
import { publicDir } from '../../setup/index.js';
|
||||||
import { publicDir, publicFiles } from '../../setup/index.js';
|
|
||||||
import {
|
import {
|
||||||
appendToName,
|
appendToName,
|
||||||
ensureDirectory,
|
ensureDirectory,
|
||||||
@@ -306,26 +305,6 @@ export async function deleteProjectFile(filename: string) {
|
|||||||
await deleteFile(projectFilePath);
|
await deleteFile(projectFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* applies a partial database model
|
* applies a partial database model
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user