diff --git a/src/endpoints.ts b/src/endpoints.ts index 00ea371..2cce8cd 100644 --- a/src/endpoints.ts +++ b/src/endpoints.ts @@ -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"; @@ -17,7 +18,9 @@ const endpointDefs = { "mp3": audio, "ogg": audio, "flac": audio, - "wav": audio + "wav": audio, + + "pdf": sheet }; export default (async (req, res) => { diff --git a/src/sheet.ts b/src/sheet.ts new file mode 100644 index 0000000..f15a225 --- /dev/null +++ b/src/sheet.ts @@ -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;