mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 17:03:53 +00:00
refactor: use strict typing
This commit is contained in:
committed by
Carlos Valente
parent
4ed38340e0
commit
178640bfc4
@@ -91,7 +91,7 @@ export async function quickProjectFile(req: Request, res: Response<{ filename: s
|
||||
*/
|
||||
export async function currentProjectDownload(_req: Request, res: Response) {
|
||||
const { filename, pathToFile } = await projectService.getCurrentProject();
|
||||
res.download(pathToFile, filename, (error) => {
|
||||
res.download(pathToFile, filename, (error: Error | null) => {
|
||||
if (error) {
|
||||
const message = getErrorMessage(error);
|
||||
res.status(500).send({ message });
|
||||
|
||||
@@ -9,7 +9,8 @@ import { CustomFields, Rundown } from 'ontime-types';
|
||||
|
||||
export async function postExcel(req: Request, res: Response) {
|
||||
try {
|
||||
const filePath = req.file.path;
|
||||
// file has been validated by middleware
|
||||
const filePath = (req.file as Express.Multer.File).path;
|
||||
await saveExcelFile(filePath);
|
||||
res.status(200).send();
|
||||
} catch (error) {
|
||||
|
||||
@@ -60,6 +60,5 @@ export function triggerReportEntry(
|
||||
sendRefetch({
|
||||
target: 'REPORT',
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||
import { publicDir } from '../../setup/index.js';
|
||||
import { socket } from '../../adapters/WebsocketAdapter.js';
|
||||
import { getLastRequest } from '../../api-integration/integration.controller.js';
|
||||
import { getLastLoadedProject } from '../../services/app-state-service/AppStateService.js';
|
||||
import { getCurrentProject } from '../../services/project-service/ProjectService.js';
|
||||
import { runtimeService } from '../../services/runtime-service/RuntimeService.js';
|
||||
import { getNetworkInterfaces } from '../../utils/network.js';
|
||||
import { getTimezoneLabel } from '../../utils/time.js';
|
||||
@@ -17,7 +17,7 @@ const startedAt = new Date();
|
||||
export async function getSessionStats(): Promise<SessionStats> {
|
||||
const { connectedClients, lastConnection } = socket.getStats();
|
||||
const lastRequest = getLastRequest();
|
||||
const projectName = await getLastLoadedProject();
|
||||
const { filename } = await getCurrentProject();
|
||||
const { playback } = runtimeService.getRuntimeState();
|
||||
|
||||
return {
|
||||
@@ -25,7 +25,7 @@ export async function getSessionStats(): Promise<SessionStats> {
|
||||
connectedClients,
|
||||
lastConnection: lastConnection !== null ? lastConnection.toISOString() : null,
|
||||
lastRequest: lastRequest !== null ? lastRequest.toISOString() : null,
|
||||
projectName,
|
||||
projectName: filename,
|
||||
playback,
|
||||
timezone: getTimezoneLabel(startedAt),
|
||||
};
|
||||
|
||||
@@ -25,10 +25,11 @@ export async function requestConnection(
|
||||
res: Response<{ verification_url: string; user_code: string } | ErrorResponse>,
|
||||
) {
|
||||
const { sheetId } = req.params;
|
||||
const file = req.file.path;
|
||||
// the check for the file is done in the validation middleware
|
||||
const filePath = (req.file as Express.Multer.File).path;
|
||||
|
||||
try {
|
||||
const client = readFileSync(file, 'utf-8');
|
||||
const client = readFileSync(filePath, 'utf-8');
|
||||
const clientSecret = handleClientSecret(client);
|
||||
const { verification_url, user_code } = await handleInitialConnection(clientSecret, sheetId);
|
||||
|
||||
@@ -40,7 +41,7 @@ export async function requestConnection(
|
||||
|
||||
// delete uploaded file after parsing
|
||||
try {
|
||||
deleteFile(file);
|
||||
await deleteFile(filePath);
|
||||
} catch (_error) {
|
||||
/** we dont handle failure here */
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ export const validateRequestConnection = [
|
||||
(req: Request, res: Response, next: NextFunction) => {
|
||||
const errors = validationResult(req);
|
||||
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
||||
// check that the file exists
|
||||
if (!req.file) {
|
||||
return res.status(422).json({ errors: 'File not found' });
|
||||
}
|
||||
next();
|
||||
},
|
||||
];
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function postUrlPresets(req: Request, res: Response<URLPreset[] | E
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const newPresets: URLPreset[] = req.body.map((preset) => ({
|
||||
const newPresets: URLPreset[] = req.body.map((preset: URLPreset) => ({
|
||||
enabled: preset.enabled,
|
||||
alias: preset.alias,
|
||||
pathAndParams: preset.pathAndParams,
|
||||
|
||||
Reference in New Issue
Block a user