feat: allow download of current project

This commit is contained in:
Carlos Valente
2024-10-03 22:26:59 +02:00
parent a08ea3fee9
commit ea5de337cf
3 changed files with 22 additions and 0 deletions
@@ -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
View File
@@ -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