shaca now loads attributes, added favicon and shareJs

This commit is contained in:
zadam
2022-01-01 13:23:09 +01:00
parent dad82ea4e8
commit 1fed71a92e
8 changed files with 86 additions and 34 deletions

View File

@@ -46,19 +46,15 @@ function register(router) {
}
});
router.get('/share/api/images/:noteId/:filename', (req, res, next) => {
const image = shaca.getNote(req.params.noteId);
router.get('/share/api/notes/:noteId', (req, res, next) => {
const {noteId} = req.params;
const note = shaca.getNote(noteId);
if (!image) {
return res.status(404).send("Not found");
}
else if (image.type !== 'image') {
return res.status(400).send("Requested note is not an image");
if (!note) {
return res.status(404).send(`Note ${noteId} not found`);
}
res.set('Content-Type', image.mime);
res.send(image.getContent());
res.json(note.getPojoWithAttributes());
});
router.get('/share/api/notes/:noteId/download', (req, res, next) => {
@@ -66,7 +62,7 @@ function register(router) {
const note = shaca.getNote(noteId);
if (!note) {
return res.status(404).send(`Not found`);
return res.status(404).send(`Note ${noteId} not found`);
}
const utils = require("../services/utils");
@@ -81,20 +77,30 @@ function register(router) {
res.send(note.getContent());
});
router.get('/share/api/images/:noteId/:filename', (req, res, next) => {
const image = shaca.getNote(req.params.noteId);
if (!image) {
return res.status(404).send(`Note ${noteId} not found`);
}
else if (image.type !== 'image') {
return res.status(400).send("Requested note is not an image");
}
res.set('Content-Type', image.mime);
res.send(image.getContent());
});
// used for PDF viewing
router.get('/share/api/notes/:noteId/view', (req, res, next) => {
const {noteId} = req.params;
const note = shaca.getNote(noteId);
if (!note) {
return res.status(404).send(`Not found`);
return res.status(404).send(`Note ${noteId} not found`);
}
const utils = require("../services/utils");
const filename = utils.formatDownloadTitle(note.title, note.type, note.mime);
// res.setHeader('Content-Disposition', utils.getContentDisposition(filename));
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
res.setHeader('Content-Type', note.mime);

View File

@@ -89,6 +89,18 @@ class Attribute extends AbstractEntity {
return this.shaca.getNote(this.value);
}
getPojo() {
return {
attributeId: this.attributeId,
noteId: this.noteId,
type: this.type,
name: this.name,
position: this.position,
value: this.value,
isInheritable: this.isInheritable
};
}
}
module.exports = Attribute;

View File

@@ -410,6 +410,19 @@ class Note extends AbstractEntity {
return sharedAlias || this.noteId;
}
getPojoWithAttributes() {
return {
noteId: this.noteId,
title: this.title,
type: this.type,
mime: this.mime,
utcDateModified: this.utcDateModified,
attributes: this.getAttributes().map(attr => attr.getPojo()),
parentNoteIds: this.parents.map(parentNote => parentNote.noteId),
childNoteIds: this.children.map(child => child.noteId)
};
}
}
module.exports = Note;

View File

@@ -59,11 +59,7 @@ function load() {
SELECT attributeId, noteId, type, name, value, isInheritable, position, utcDateModified
FROM attributes
WHERE isDeleted = 0
AND noteId IN (${noteIdStr})
AND (
(type = 'label' AND name IN ('archived', 'shareHiddenFromTree', 'shareAlias', 'shareOmitDefaultCss'))
OR (type = 'relation' AND name IN ('imageLink', 'template', 'shareCss'))
)`, []);
AND noteId IN (${noteIdStr})`);
for (const row of rawAttributeRows) {
new Attribute(row);