Project files tweaks (#679)

* chore: fixed issue when loading first time; deleting excel file after upload; only json files from project list

* chore: added last loaded project to endpoint response

* chore: incremental file name

---------

Co-authored-by: Name <Email>
This commit is contained in:
Ary
2023-12-30 11:32:17 -07:00
committed by GitHub
parent c5c0401ac4
commit 7b9f64a630
9 changed files with 613 additions and 30 deletions
@@ -5,8 +5,8 @@ import type {
GetInfo,
HttpSettings,
ProjectData,
ProjectFileList,
ErrorResponse,
ProjectFileListResponse,
} from 'ontime-types';
import { RequestHandler, Request, Response } from 'express';
@@ -19,7 +19,7 @@ import { DataProvider } from '../classes/data-provider/DataProvider.js';
import { failEmptyObjects, failIsNotArray } from '../utils/routerUtils.js';
import { PlaybackService } from '../services/PlaybackService.js';
import { eventStore } from '../stores/EventStore.js';
import { getAppDataPath, isDocker, resolveDbPath, resolveStylesPath } from '../setup.js';
import { getAppDataPath, isDocker, lastLoadedProjectConfigPath, resolveDbPath, resolveStylesPath } from '../setup.js';
import { oscIntegration } from '../services/integration-service/OscIntegration.js';
import { httpIntegration } from '../services/integration-service/HttpIntegration.js';
import { logger } from '../classes/Logger.js';
@@ -28,7 +28,7 @@ import { deepmerge } from 'ontime-utils';
import { runtimeCacheStore } from '../stores/cachingStore.js';
import { delayedRundownCacheKey } from '../services/rundown-service/delayedRundown.utils.js';
import { integrationService } from '../services/integration-service/IntegrationService.js';
import { getFileListFromFolder } from '../utils/getFileListFromFolder.js';
import { getProjectFiles } from '../utils/getFileListFromFolder.js';
// Create controller for GET request to '/ontime/poll'
// Returns data for current state
@@ -471,11 +471,16 @@ export const postNew: RequestHandler = async (req, res) => {
* @param req
* @param res
*/
export const listProjects: RequestHandler = (_, res: Response<ProjectFileList | ErrorResponse>) => {
export const listProjects: RequestHandler = async (_, res: Response<ProjectFileListResponse | ErrorResponse>) => {
try {
const uploadsFolderPath = join(getAppDataPath(), 'uploads');
const fileList = getFileListFromFolder(uploadsFolderPath);
res.status(200).send(fileList);
const fileList = await getProjectFiles();
const lastLoadedProject = JSON.parse(fs.readFileSync(lastLoadedProjectConfigPath, 'utf8')).lastLoadedProject;
res.status(200).send({
files: fileList,
lastLoadedProject,
});
} catch (error) {
res.status(500).send({ message: error.toString() });
}