"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const immich_1 = tslib_1.__importDefault(require("./immich")); const types_1 = require("./types"); class Render { assetBuffer(res, asset, size) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const data = yield immich_1.default.getAssetBuffer(asset, size); if (data) { for (const header of ['content-type', 'content-length']) { res.set(header, data.headers[header]); } res.send(Buffer.from(yield data.arrayBuffer())); } else { res.status(404).send(); } }); } /** * Render a gallery page for a given SharedLink, using EJS and lightGallery. * * @param res - ExpressJS Response * @param share - Immich `shared-link` containing the assets to show in the gallery * @param [openItem] - Immediately open a lightbox to the Nth item when the gallery loads */ gallery(res, share, openItem) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const items = []; for (const asset of share.assets) { let video; if (asset.type === types_1.AssetType.video) { // Populate the data-video property video = JSON.stringify({ source: [ { src: immich_1.default.videoUrl(share.key, asset.id), type: yield immich_1.default.getContentType(asset) } ], attributes: { preload: false, controls: true } }); } items.push({ originalUrl: immich_1.default.photoUrl(share.key, asset.id), thumbnailUrl: immich_1.default.photoUrl(share.key, asset.id, types_1.ImageSize.thumbnail), video }); } res.render('gallery', { items, openItem }); }); } } const render = new Render(); exports.default = render; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVuZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3JlbmRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw4REFBNkI7QUFFN0IsbUNBQWlFO0FBRWpFLE1BQU0sTUFBTTtJQUNKLFdBQVcsQ0FBRSxHQUFhLEVBQUUsS0FBWSxFQUFFLElBQWdCOztZQUM5RCxNQUFNLElBQUksR0FBRyxNQUFNLGdCQUFNLENBQUMsY0FBYyxDQUFDLEtBQUssRUFBRSxJQUFJLENBQUMsQ0FBQTtZQUNyRCxJQUFJLElBQUksRUFBRSxDQUFDO2dCQUNULEtBQUss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