mirror of
https://github.com/alangrainger/immich-public-proxy.git
synced 2024-12-29 12:21:57 +00:00
59 lines
No EOL
6.8 KiB
JavaScript
59 lines
No EOL
6.8 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const tslib_1 = require("tslib");
|
|
const types_1 = require("./types");
|
|
class Immich {
|
|
request(endpoint) {
|
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
const res = yield fetch(process.env.IMMICH_URL + '/api' + endpoint, {
|
|
headers: {
|
|
'x-api-key': process.env.API_KEY || ''
|
|
}
|
|
});
|
|
if (res.status === 200) {
|
|
const contentType = res.headers.get('Content-Type') || '';
|
|
if (contentType.includes('application/json')) {
|
|
return res.json();
|
|
}
|
|
else {
|
|
return res;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
getShareByKey(key) {
|
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
const res = ((yield this.request('/shared-links')) || []);
|
|
return res === null || res === void 0 ? void 0 : res.find(x => x.key === key);
|
|
});
|
|
}
|
|
getAssetBuffer(asset, size) {
|
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
switch (asset.type) {
|
|
case types_1.AssetType.image:
|
|
size = size === types_1.ImageSize.thumbnail ? types_1.ImageSize.thumbnail : types_1.ImageSize.original;
|
|
return this.request('/assets/' + asset.id + '/' + size);
|
|
case types_1.AssetType.video:
|
|
return this.request('/assets/' + asset.id + '/video/playback');
|
|
}
|
|
});
|
|
}
|
|
getContentType(asset) {
|
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
const assetBuffer = yield this.getAssetBuffer(asset);
|
|
return assetBuffer.headers.get('Content-Type');
|
|
});
|
|
}
|
|
photoUrl(id, size) {
|
|
return `${process.env.SERVER_URL}/photo/${id}` + (size ? `?size=${size}` : '');
|
|
}
|
|
videoUrl(id) {
|
|
return `${process.env.SERVER_URL}/video/${id}`;
|
|
}
|
|
isId(id) {
|
|
return !!id.match(/^[0-9a-f]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