mirror of
https://github.com/alangrainger/immich-public-proxy.git
synced 2024-12-29 12:21:57 +00:00
58 lines
No EOL
6.2 KiB
JavaScript
58 lines
No EOL
6.2 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, assets, openItem) {
|
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
const items = [];
|
|
for (const asset of assets) {
|
|
let video;
|
|
if (asset.type === types_1.AssetType.video) {
|
|
// Populate the data-video property
|
|
video = JSON.stringify({
|
|
source: [
|
|
{
|
|
src: immich_1.default.videoUrl(asset.id),
|
|
type: yield immich_1.default.getContentType(asset)
|
|
}
|
|
],
|
|
attributes: {
|
|
preload: false,
|
|
controls: true
|
|
}
|
|
});
|
|
}
|
|
items.push({
|
|
originalUrl: immich_1.default.photoUrl(asset.id),
|
|
thumbnailUrl: immich_1.default.photoUrl(asset.id, types_1.ImageSize.thumbnail),
|
|
video
|
|
});
|
|
}
|
|
res.render('gallery', {
|
|
items,
|
|
openItem
|
|
});
|
|
});
|
|
}
|
|
}
|
|
const render = new Render();
|
|
exports.default = render;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVuZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNv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gICAvLyBQb3B1bGF0ZSB0aGUgZGF0YS12aWRlbyBwcm9wZXJ0eVxuICAgICAgICB2aWRlbyA9IEpTT04uc3RyaW5naWZ5KHtcbiAgICAgICAgICBzb3VyY2U6IFtcbiAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgc3JjOiBpbW1pY2gudmlkZW9VcmwoYXNzZXQuaWQpLFxuICAgICAgICAgICAgICB0eXBlOiBhd2FpdCBpbW1pY2guZ2V0Q29udGVudFR5cGUoYXNzZXQpXG4gICAgICAgICAgICB9XG4gICAgICAgICAgXSxcbiAgICAgICAgICBhdHRyaWJ1dGVzOiB7XG4gICAgICAgICAgICBwcmVsb2FkOiBmYWxzZSxcbiAgICAgICAgICAgIGNvbnRyb2xzOiB0cnVlXG4gICAgICAgICAgfVxuICAgICAgICB9KVxuICAgICAgfVxuICAgICAgaXRlbXMucHVzaCh7XG4gICAgICAgIG9yaWdpbmFsVXJsOiBpbW1pY2gucGhvdG9VcmwoYXNzZXQuaWQpLFxuICAgICAgICB0aHVtYm5haWxVcmw6IGltbWljaC5waG90b1VybChhc3NldC5pZCwgSW1hZ2VTaXplLnRodW1ibmFpbCksXG4gICAgICAgIHZpZGVvXG4gICAgICB9KVxuICAgIH1cbiAgICByZXMucmVuZGVyKCdnYWxsZXJ5Jywge1xuICAgICAgaXRlbXMsXG4gICAgICBvcGVuSXRlbVxuICAgIH0pXG4gIH1cbn1cblxuY29uc3QgcmVuZGVyID0gbmV3IFJlbmRlcigpXG5cbmV4cG9ydCBkZWZhdWx0IHJlbmRlclxuIl19
|