share support for attachment file download

This commit is contained in:
zadam
2023-06-06 00:16:32 +02:00
parent 44bcfd47c0
commit 0234ff5fca
2 changed files with 44 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ const shareRoot = require("./share_root");
const contentRenderer = require("./content_renderer");
const assetPath = require("../services/asset_path");
const appPath = require("../services/app_path");
const utils = require("../services/utils.js");
function getSharedSubTreeRoot(note) {
if (note.noteId === shareRoot.SHARE_ROOT_NOTE_ID) {
@@ -253,6 +254,29 @@ function register(router) {
}
});
router.get('/share/api/attachments/:attachmentId/download', (req, res, next) => {
shacaLoader.ensureLoad();
let attachment;
if (!(attachment = checkAttachmentAccess(req.params.attachmentId, req, res))) {
return;
}
addNoIndexHeader(attachment.note, res);
const utils = require("../services/utils");
const filename = utils.formatDownloadTitle(attachment.title, null, attachment.mime);
res.setHeader('Content-Disposition', utils.getContentDisposition(filename));
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
res.setHeader('Content-Type', attachment.mime);
res.send(attachment.getContent());
});
// used for PDF viewing
router.get('/share/api/notes/:noteId/view', (req, res, next) => {
shacaLoader.ensureLoad();