mirror of
https://github.com/alangrainger/immich-public-proxy.git
synced 2024-12-29 12:21:57 +00:00
37 lines
No EOL
5 KiB
JavaScript
37 lines
No EOL
5 KiB
JavaScript
"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 dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
const app = (0, express_1.default)();
|
|
require('dotenv').config();
|
|
app.get('/share/:key', (req, res) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
var _a;
|
|
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 (((_a = share === null || share === void 0 ? void 0 : share.assets) === null || _a === void 0 ? void 0 : _a.length) === 1) {
|
|
// This is an individual item (not a gallery)
|
|
// Return the full-size image.
|
|
const size = req.query.size === 'thumbnail' ? 'thumbnail' : 'original';
|
|
const image = yield immich_1.default.getImage(share.assets[0].id, size);
|
|
for (const header of ['content-type', 'content-length']) {
|
|
res.set(header, image.headers[header]);
|
|
}
|
|
const data = yield image.arrayBuffer();
|
|
console.log((0, dayjs_1.default)().format() + ' Serving image ' + share.assets[0].id);
|
|
res.send(Buffer.from(data));
|
|
}
|
|
else {
|
|
res.send();
|
|
}
|
|
}
|
|
}));
|
|
app.listen(3000, () => {
|
|
console.log((0, dayjs_1.default)().format() + ' Server started');
|
|
});
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsOERBQTZCO0FBQzdCLDhEQUEwQjtBQUMxQiwwREFBeUI7QUFFekIsT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