immich-public-proxy/dist/index.js

66 lines
8.3 KiB
JavaScript
Raw Normal View History

2024-10-28 04:56:11 -04:00
"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"));
2024-10-29 05:31:40 -04:00
const render_1 = tslib_1.__importDefault(require("./render"));
2024-10-28 04:56:11 -04:00
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
2024-10-29 05:31:40 -04:00
const types_1 = require("./types");
2024-10-28 04:56:11 -04:00
require('dotenv').config();
2024-10-29 05:31:40 -04:00
const app = (0, express_1.default)();
app.set('view engine', 'ejs');
app.use(express_1.default.static('public'));
const getSize = (req) => {
2024-10-28 04:56:11 -04:00
var _a;
2024-10-29 05:31:40 -04:00
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* () {
2024-10-28 05:09:59 -04:00
if (req.params.key.match(/[^\w-]/)) {
2024-10-28 04:56:11 -04:00
// Invalid characters in the incoming URL
res.status(404).send();
}
else {
const share = yield immich_1.default.getShareByKey(req.params.key);
2024-10-29 05:31:40 -04:00
if (!share || !share.assets.length) {
res.status(404).send();
}
else if (share.assets.length === 1) {
2024-10-28 04:56:11 -04:00
// This is an individual item (not a gallery)
2024-10-29 05:31:40 -04:00
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);
2024-10-28 04:56:11 -04:00
}
}
else {
2024-10-29 05:31:40 -04:00
// Multiple images - render as a gallery
yield render_1.default.gallery(res, share.assets);
2024-10-28 04:56:11 -04:00
}
}
}));
2024-10-29 05:31:40 -04:00
// 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;
}
});
2024-10-28 04:56:11 -04:00
app.listen(3000, () => {
console.log((0, dayjs_1.default)().format() + ' Server started');
});
2024-10-29 05:31:40 -04:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsOERBQTZCO0FBQzdCLDhEQUE2QjtBQUM3Qiw4REFBNkI7QUFDN0IsMERBQXlCO0FBQ3pCLG1DQUE4QztBQUc5QyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUMsTUFBTSxFQUFFLENBQUE7QUFFMUIsTUFBTSxHQUFHLEdBQUcsSUFBQSxpQkFBTyxHQUFFLENBQUE7QUFDckIsR0FBRyxDQUFDLEdBQUcsQ0FBQyxhQUFhLEVBQUUsS0FBSyxDQUFDLENBQUE7QUFDN0IsR0FBRyxDQUFDLEdBQUcsQ0FBQyxpQkFBTyxDQUFDLE1BQU0sQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFBO0FBRWpDLE1BQU0sT0FBTyxHQUFHLENBQUMsR0FBWSxFQUFFLEVBQUU7O0lBQy9CLE9BQU8sQ0FBQSxNQUFBLEdBQUcsYUFBSCxHQUFHLHVCQUFILEdBQUcsQ0FBRSxLQUFLLDBDQUFFLElBQUksTUFBSyxXQUFXLENBQUMsQ0FBQyxDQUFDLGlCQUFTLENBQUMsU0FBUyxDQUFDLENBQUMsQ0FBQyxpQkFBUyxDQUFDLFFBQ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