Skip to content

Commit

Permalink
fix: get it working
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Nov 12, 2023
1 parent b8a626d commit ba273af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
15 changes: 5 additions & 10 deletions src/controllers/DownloadController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,15 @@ class DownloadController {
}
}

getAPKGFile(req: Request, res: Response) {
const { id, apkg } = req.params;
getLocalFile(req: Request, res: Response) {
const { id, filename } = req.params;
const workspace = path.join(process.env.WORKSPACE_BASE!, id);
const apkgFilePath = path.join(workspace, apkg);
const filePath = path.join(workspace, filename);

if (!fs.existsSync(apkgFilePath)) {
if (!fs.existsSync(filePath)) {
return res.status(404).end();
}

const fileContent = fs.readFileSync(apkgFilePath, 'utf8');
const contentLength = Buffer.byteLength(fileContent);
res.set('Content-Type', 'application/apkg');
res.set('Content-Length', contentLength.toString());
return res.send(fileContent);
return res.sendFile(filePath);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/routes/DownloadRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const DownloadRouter = () => {
controller.getDownloadPage(req, res);
});

router.get('/download/:id/:apkg', (req, res) => {
controller.getAPKGFile(req, res);
router.get('/download/:id/:filename', (req, res) => {
controller.getLocalFile(req, res);
});

return router;
Expand Down

0 comments on commit ba273af

Please sign in to comment.