"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const express_1 = tslib_1.__importDefault(require("express")); const immich_1 = tslib_1.__importDefault(require("./immich")); const render_1 = tslib_1.__importDefault(require("./render")); const dayjs_1 = tslib_1.__importDefault(require("dayjs")); const types_1 = require("./types"); require('dotenv').config(); const app = (0, express_1.default)(); app.set('view engine', 'ejs'); app.use(express_1.default.static('public')); const getSize = (req) => { var _a; return ((_a = req === null || req === void 0 ? void 0 : req.query) === null || _a === void 0 ? void 0 : _a.size) === 'thumbnail' ? types_1.ImageSize.thumbnail : types_1.ImageSize.original; }; app.get('/share/:key', (req, res) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { if (req.params.key.match(/[^\w-]/)) { // Invalid characters in the incoming URL res.status(404).send(); } else { const share = yield immich_1.default.getShareByKey(req.params.key); if (!share || !share.assets.length) { res.status(404).send(); } else if (share.assets.length === 1) { // This is an individual item (not a gallery) const asset = share.assets[0]; if (asset.type === types_1.AssetType.image) { // Output the image directly yield render_1.default.assetBuffer(res, share.assets[0], getSize(req)); } else if (asset.type === types_1.AssetType.video) { // Show the video as a web player yield render_1.default.gallery(res, share.assets, 1); } } else { // Multiple images - render as a gallery yield render_1.default.gallery(res, share.assets); } } })); // Output the buffer data for an photo or video app.get('/:type(photo|video)/:id', (req, res) => { if (!immich_1.default.isId(req.params.id)) { // Invalid characters in the incoming URL res.status(404).send(); return; } const asset = { id: req.params.id, type: req.params.type === 'video' ? types_1.AssetType.video : types_1.AssetType.image }; switch (req.params.type) { case 'photo': case 'video': render_1.default.assetBuffer(res, asset, getSize(req)).then(); break; } }); app.listen(3000, () => { console.log((0, dayjs_1.default)().format() + ' Server started'); }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0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