Skip to content

Commit

Permalink
make sure shaca is loaded before any request
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed May 1, 2022
1 parent f9c0185 commit b3763ee
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/share/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ function register(router) {
});

router.get('/share/:shareId', (req, res, next) => {
const {shareId} = req.params;

shacaLoader.ensureLoad();

const {shareId} = req.params;

const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];

renderNote(note, res);
});

router.get('/share/api/notes/:noteId', (req, res, next) => {
shacaLoader.ensureLoad();

const {noteId} = req.params;
const note = shaca.getNote(noteId);

Expand All @@ -85,6 +87,8 @@ function register(router) {
});

router.get('/share/api/notes/:noteId/download', (req, res, next) => {
shacaLoader.ensureLoad();

const {noteId} = req.params;
const note = shaca.getNote(noteId);

Expand All @@ -107,6 +111,8 @@ function register(router) {
});

router.get('/share/api/images/:noteId/:filename', (req, res, next) => {
shacaLoader.ensureLoad();

const image = shaca.getNote(req.params.noteId);

if (!image) {
Expand All @@ -118,13 +124,15 @@ function register(router) {

addNoIndexHeader(image, res);

res.set('Content-Type', image.mime);
res.setHeader('Content-Type', image.mime);

res.send(image.getContent());
});

// used for PDF viewing
router.get('/share/api/notes/:noteId/view', (req, res, next) => {
shacaLoader.ensureLoad();

const {noteId} = req.params;
const note = shaca.getNote(noteId);

Expand Down

0 comments on commit b3763ee

Please sign in to comment.