mirror of
https://github.com/zadam/trilium.git
synced 2025-11-15 09:45:52 +01:00
render PDF preview in electron for pdf notes
This commit is contained in:
@@ -31,7 +31,7 @@ async function updateFile(req) {
|
||||
};
|
||||
}
|
||||
|
||||
async function downloadNoteFile(noteId, res) {
|
||||
async function downloadNoteFile(noteId, res, contentDisposition = true) {
|
||||
const note = await repository.getNote(noteId);
|
||||
|
||||
if (!note) {
|
||||
@@ -42,9 +42,12 @@ async function downloadNoteFile(noteId, res) {
|
||||
return res.status(401).send("Protected session not available");
|
||||
}
|
||||
|
||||
// (one) reason we're not using the originFileName (available as label) is that it's not
|
||||
// available for older note revisions and thus would be inconsistent
|
||||
res.setHeader('Content-Disposition', utils.getContentDisposition(note.title || "untitled"));
|
||||
if (contentDisposition) {
|
||||
// (one) reason we're not using the originFileName (available as label) is that it's not
|
||||
// available for older note revisions and thus would be inconsistent
|
||||
res.setHeader('Content-Disposition', utils.getContentDisposition(note.title || "untitled"));
|
||||
}
|
||||
|
||||
res.setHeader('Content-Type', note.mime);
|
||||
|
||||
res.send(await note.getContent());
|
||||
@@ -54,11 +57,17 @@ async function downloadFile(req, res) {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
return await downloadNoteFile(noteId, res);
|
||||
}
|
||||
|
||||
async function openFile(req, res) {
|
||||
const noteId = req.params.noteId;
|
||||
|
||||
return await downloadNoteFile(noteId, res, false);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
updateFile,
|
||||
openFile,
|
||||
downloadFile,
|
||||
downloadNoteFile
|
||||
};
|
||||
@@ -156,6 +156,7 @@ function register(app) {
|
||||
route(PUT, '/api/notes/:noteId/file', [auth.checkApiAuthOrElectron, uploadMiddleware, csrfMiddleware],
|
||||
filesRoute.updateFile, apiResultHandler);
|
||||
|
||||
route(GET, '/api/notes/:noteId/open', [auth.checkApiAuthOrElectron], filesRoute.openFile);
|
||||
route(GET, '/api/notes/:noteId/download', [auth.checkApiAuthOrElectron], filesRoute.downloadFile);
|
||||
// this "hacky" path is used for easier referencing of CSS resources
|
||||
route(GET, '/api/notes/download/:noteId', [auth.checkApiAuthOrElectron], filesRoute.downloadFile);
|
||||
|
||||
Reference in New Issue
Block a user