Skip to content

Commit

Permalink
feat: pdf support
Browse files Browse the repository at this point in the history
  • Loading branch information
sealsrock12 committed Dec 31, 2020
1 parent c82e727 commit 1635741
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import meta from "./meta";
import midi from "./midi";
import musicxml from "./musicxml";
import audio from "./audio";
import sheet from "./sheet";

import { RequestHandler } from "express";
import LocalError, { handleHTTP } from "./error";
Expand All @@ -17,7 +18,9 @@ const endpointDefs = {
"mp3": audio,
"ogg": audio,
"flac": audio,
"wav": audio
"wav": audio,

"pdf": sheet
};

export default (async (req, res) => {
Expand Down
24 changes: 24 additions & 0 deletions src/sheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import winston from "winston";
import webmscore from "webmscore";
import { RequestHandler } from "express";
import * as mscore from "./mscore";
import * as error from "./error";

export default (async (req, res) => {
winston.http("SHEET accessed.");

let score: webmscore;
try { score = await mscore.mkScore(req.body, req.params.eid, false); }
catch (e) {
return error.handleHTTP(res, e);
}

const sheet = await (score.savePdf());

// Send it off.
res.setHeader("Content-Disposition", `attachement; filename=${await score.titleFilenameSafe()}_${req.params.eid || "FULLSCORE"}.pdf`);
res.contentType("application/pdf");
res.send(Buffer.from(sheet));

score.destroy();
}) as RequestHandler;

0 comments on commit 1635741

Please sign in to comment.