1
0
Fork 0
mirror of https://github.com/alangrainger/immich-public-proxy.git synced 2024-12-29 12:21:57 +00:00
immich-public-proxy/dist/render.js
Alan Grainger 9ddfbcec67 Add docs
2024-10-29 15:07:54 +01:00

58 lines
No EOL
6.4 KiB
JavaScript

"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");
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
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]);
}
console.log(`${(0, dayjs_1.default)().format()} Serving asset ${asset.id}`);
res.send(Buffer.from(yield data.arrayBuffer()));
}
else {
res.status(404).send();
}
});
}
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVuZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3JlbmRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw4REFBNkI7QUFFN0IsbUNBQWlFO0FBQ2pFLDBEQUF5QjtBQUV6QixNQUFNLE1BQU07SUFDSixXQUFXLENBQUUsR0FBYSxFQUFFLEtBQV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