mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-22 15:39:11 +00:00
refactor: expose api for loading demo project
This commit is contained in:
committed by
Carlos Valente
parent
a518dc4882
commit
7bf90d669a
@@ -112,6 +112,14 @@ export async function loadProject(filename: string): Promise<MessageResponse> {
|
|||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HTTP request to load the demo project file
|
||||||
|
*/
|
||||||
|
export async function loadDemo(): Promise<MessageResponse> {
|
||||||
|
const res = await axios.post(`${dbPath}/demo`);
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HTTP request to duplicate a project file
|
* HTTP request to duplicate a project file
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -192,6 +192,25 @@ export async function loadProject(req: Request, res: Response<MessageResponse |
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the demo project
|
||||||
|
*/
|
||||||
|
export async function loadDemo(req: Request, res: Response<MessageResponse | ErrorResponse>) {
|
||||||
|
try {
|
||||||
|
const projectName = await projectService.loadDemoProject();
|
||||||
|
|
||||||
|
res.status(201).send({
|
||||||
|
message: `Loaded demo project: ${projectName}`,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
const message = getErrorMessage(error);
|
||||||
|
if (message.startsWith('Project file')) {
|
||||||
|
return res.status(403).send({ message });
|
||||||
|
}
|
||||||
|
res.status(500).send({ message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Duplicates a project file.
|
* Duplicates a project file.
|
||||||
* Receives the original project filename (`filename`) from the request parameters
|
* Receives the original project filename (`filename`) from the request parameters
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
deleteProjectFile,
|
deleteProjectFile,
|
||||||
duplicateProjectFile,
|
duplicateProjectFile,
|
||||||
listProjects,
|
listProjects,
|
||||||
|
loadDemo,
|
||||||
loadProject,
|
loadProject,
|
||||||
patchPartialProjectFile,
|
patchPartialProjectFile,
|
||||||
postProjectFile,
|
postProjectFile,
|
||||||
@@ -36,6 +37,7 @@ router.post('/quick', validateQuickProject, quickProjectFile);
|
|||||||
router.get('/all', listProjects);
|
router.get('/all', listProjects);
|
||||||
|
|
||||||
router.post('/load', validateFilenameBody, loadProject);
|
router.post('/load', validateFilenameBody, loadProject);
|
||||||
|
router.post('/demo', loadDemo);
|
||||||
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);
|
||||||
|
|||||||
@@ -59,10 +59,9 @@ export async function getCurrentProject() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private function loads a demo project
|
* Loads the demo project
|
||||||
* to be composed in the loading functions
|
|
||||||
*/
|
*/
|
||||||
async function loadDemoProject(): Promise<string> {
|
export async function loadDemoProject(): Promise<string> {
|
||||||
const pathToNewFile = generateUniqueFileName(publicDir.projectsDir, config.demoProject);
|
const pathToNewFile = generateUniqueFileName(publicDir.projectsDir, config.demoProject);
|
||||||
await initPersistence(getPathToProject(pathToNewFile), demoDb);
|
await initPersistence(getPathToProject(pathToNewFile), demoDb);
|
||||||
const newName = getFileNameFromPath(pathToNewFile);
|
const newName = getFileNameFromPath(pathToNewFile);
|
||||||
|
|||||||
Reference in New Issue
Block a user