mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-08 00:43:54 +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
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@ import express from 'express';
|
||||
|
||||
import {
|
||||
createProjectFile,
|
||||
currentProjectDownload,
|
||||
deleteProjectFile,
|
||||
duplicateProjectFile,
|
||||
getInfo,
|
||||
@@ -23,6 +24,7 @@ import {
|
||||
|
||||
export const router = express.Router();
|
||||
|
||||
router.get('/', currentProjectDownload);
|
||||
router.post('/download', validateFilenameBody, projectDownload);
|
||||
router.post('/upload', uploadProjectFile, postProjectFile);
|
||||
|
||||
|
||||
@@ -51,6 +51,13 @@ function init() {
|
||||
ensureDirectory(resolveCorruptDirectory);
|
||||
}
|
||||
|
||||
export async function getCurrentProject() {
|
||||
const filename = await getLastLoadedProject();
|
||||
const pathToFile = getPathToProject(filename);
|
||||
|
||||
return { filename, pathToFile };
|
||||
}
|
||||
|
||||
/**
|
||||
* Private function loads a demo project
|
||||
* to be composed in the loading functions
|
||||
|
||||
Reference in New Issue
Block a user