mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 14:39:06 +00:00
feat: allow download of current project
This commit is contained in:
@@ -58,6 +58,19 @@ export async function createProjectFile(req: Request, res: Response<{ filename:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows downloading of current project file
|
||||||
|
*/
|
||||||
|
export async function currentProjectDownload(_req: Request, res: Response) {
|
||||||
|
const { filename, pathToFile } = await projectService.getCurrentProject();
|
||||||
|
res.download(pathToFile, filename, (error) => {
|
||||||
|
if (error) {
|
||||||
|
const message = getErrorMessage(error);
|
||||||
|
res.status(500).send({ message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows downloading of project files
|
* Allows downloading of project files
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import express from 'express';
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
createProjectFile,
|
createProjectFile,
|
||||||
|
currentProjectDownload,
|
||||||
deleteProjectFile,
|
deleteProjectFile,
|
||||||
duplicateProjectFile,
|
duplicateProjectFile,
|
||||||
getInfo,
|
getInfo,
|
||||||
@@ -23,6 +24,7 @@ import {
|
|||||||
|
|
||||||
export const router = express.Router();
|
export const router = express.Router();
|
||||||
|
|
||||||
|
router.get('/', currentProjectDownload);
|
||||||
router.post('/download', validateFilenameBody, projectDownload);
|
router.post('/download', validateFilenameBody, projectDownload);
|
||||||
router.post('/upload', uploadProjectFile, postProjectFile);
|
router.post('/upload', uploadProjectFile, postProjectFile);
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,13 @@ function init() {
|
|||||||
ensureDirectory(resolveCorruptDirectory);
|
ensureDirectory(resolveCorruptDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getCurrentProject() {
|
||||||
|
const filename = await getLastLoadedProject();
|
||||||
|
const pathToFile = getPathToProject(filename);
|
||||||
|
|
||||||
|
return { filename, pathToFile };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private function loads a demo project
|
* Private function loads a demo project
|
||||||
* to be composed in the loading functions
|
* to be composed in the loading functions
|
||||||
|
|||||||
Reference in New Issue
Block a user