diff --git a/.env.example b/.env.example index fbe85ab..e6241f1 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ IMMICH_URL=http://localhost:2283 -API_KEY="Get this from your Immich Account Settings page" PORT=3000 CACHE_AGE=2592000 diff --git a/README.md b/README.md index 4749fe5..8dace77 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,11 @@ git clone https://github.com/alangrainger/immich-public-proxy.git ``` IMMICH_URL=http://localhost:2283 -API_KEY="Get this from your Immich Account Settings page" PORT=3000 CACHE_AGE=2592000 ``` - `IMMICH_URL` is the URL to access Immich in your local network. This is not your public URL. -- `API_KEY` get this from the Account Settings page of your Immich user account. - `CACHE_AGE` this is setting the `cache-control` header, to tell the browser to cache the assets. Set to 0 to disable caching. 3. Start the docker container: diff --git a/dist/immich.js b/dist/immich.js index 9baa255..f615ebe 100644 --- a/dist/immich.js +++ b/dist/immich.js @@ -34,31 +34,19 @@ class Immich { /** * Query Immich for the SharedLink metadata for a given key. * The key is what is returned in the URL when you create a share in Immich. - * - * Immich doesn't have a method to query by key, so this method gets all - * known shared links, and returns the link which matches the provided key. */ getShareByKey(key) { return tslib_1.__awaiter(this, void 0, void 0, function* () { - var _a; - const res = ((yield this.request('/shared-links')) || []); - const link = res.find(x => x.key === key); + const link = ((yield this.request('/shared-links/me?key=' + encodeURIComponent(key))) || []); if (link) { if (link.expiresAt && (0, dayjs_1.default)(link.expiresAt) < (0, dayjs_1.default)()) { // This link has expired (0, index_1.log)('Expired link ' + key); } else { - if (link.type === 'ALBUM') { - // Fetch the assets from the album and populate the SharedLink assets array - const albumId = (_a = link.album) === null || _a === void 0 ? void 0 : _a.id; - if (albumId) { - const album = (yield this.request('/albums/' + encodeURIComponent(albumId))); - link.assets = album.assets || []; - } - } // Filter assets to exclude trashed assets - link.assets = link.assets.filter(x => !x.isTrashed); + link.assets = link.assets.filter(asset => !asset.isTrashed); + link.assets.forEach(asset => { asset.key = key; }); return link; } } @@ -75,9 +63,9 @@ class Immich { 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/' + encodeURIComponent(asset.id) + '/' + size); + return this.request('/assets/' + encodeURIComponent(asset.id) + '/' + size + '?key=' + encodeURIComponent(asset.key)); case types_1.AssetType.video: - return this.request('/assets/' + encodeURIComponent(asset.id) + '/video/playback'); + return this.request('/assets/' + encodeURIComponent(asset.id) + '/video/playback?key=' + encodeURIComponent(asset.key)); } }); } @@ -117,4 +105,4 @@ class Immich { } const immich = new Immich(); exports.default = immich; -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW1taWNoLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ltbWljaC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSxtQ0FBd0U7QUFDeEUsMERBQXlCO0FBQ3pCLG1DQUE2QjtBQUU3QixNQUFNLE1BQU07SUFDVjs7O09BR0c7SUFDRyxPQUFPLENBQUUsUUFBZ0I7O1lBQzdCLE1BQU0sR0FBRyxHQUFHLE1BQU0sS0FBSyxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsVUFBVSxHQUFHLE1BQU0sR0FBRyxRQUFRLEVBQUU7Z0JBQ2xFLE9BQU8sRUFBRTtvQkFDUCxXQUFXLEVBQUUsT0FBTyxDQUFDLEdBQUcsQ0FBQyxPQUFPLElBQUksRUFBRTtpQkFDdkM7YUFDRixDQUFDLENBQUE7WUFDRixJQUFJLEdBQUcsQ0FBQyxNQUFNLEtBQUssR0FBRyxFQUFFLENBQUM7Z0JBQ3ZCLE1BQU0sV0FBVyxHQUFHLEdBQUcsQ0FBQyxPQUFPLENBQUMsR0FBRyxDQUFDLGNBQWMsQ0FBQyxJQUFJLEVBQUUsQ0FBQTtnQkFDekQsSUFBSSxXQUFXLENBQUMsUUFBUSxDQUFDLGtCQUFrQixDQUFDLEVBQU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ICsgKHNpemUgPyBgP3NpemU9JHtzaXplfWAgOiAnJylcbiAgfVxuXG4gIC8qKlxuICAgKiBSZXR1cm4gdGhlIHZpZGVvIGRhdGEgVVJMIGZvciBhIHZpZGVvXG4gICAqL1xuICB2aWRlb1VybCAoa2V5OiBzdHJpbmcsIGlkOiBzdHJpbmcpIHtcbiAgICByZXR1cm4gYC92aWRlby8ke2tleX0vJHtpZH1gXG4gIH1cblxuICAvKipcbiAgICogQ2hlY2sgaWYgYSBwcm92aWRlZCBJRCBtYXRjaGVzIHRoZSBJbW1pY2ggSUQgZm9ybWF0XG4gICAqL1xuICBpc0lkIChpZDogc3RyaW5nKSB7XG4gICAgcmV0dXJuICEhaWQubWF0Y2goL15bMC05YS1mXXs4fS1bMC05YS1mXXs0fS1bMC05YS1mXXs0fS1bMC05YS1mXXs0fS1bMC05YS1mXXsxMn0kLylcbiAgfVxuXG4gIC8qKlxuICAgKiBDaGVjayBpZiBhIHByb3ZpZGVkIGtleSBtYXRjaGVzIHRoZSBJbW1pY2ggc2hhcmVkLWxpbmsga2V5IGZvcm1hdFxuICAgKi9cbiAgaXNLZXkgKGtleTogc3RyaW5nKSB7XG4gICAgcmV0dXJuICEha2V5Lm1hdGNoKC9eW1xcdy1dKyQvKVxuICB9XG59XG5cbmNvbnN0IGltbWljaCA9IG5ldyBJbW1pY2goKVxuXG5leHBvcnQgZGVmYXVsdCBpbW1pY2hcbiJdfQ== \ No newline at end of file diff --git a/dist/types.js b/dist/types.js index fdf5409..90d21e7 100644 --- a/dist/types.js +++ b/dist/types.js @@ -11,4 +11,4 @@ var ImageSize; ImageSize["thumbnail"] = "thumbnail"; ImageSize["original"] = "original"; })(ImageSize || (exports.ImageSize = ImageSize = {})); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwa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Ijs7O0FBQUEsSUFBWSxTQUdYO0FBSEQsV0FBWSxTQUFTO0lBQ25CLDRCQUFlLENBQUE7SUFDZiw0QkFBZSxDQUFBO0FBQ2pCLENBQUMsRUFIVyxTQUFTLHlCQUFULFNBQVMsUUFHcEI7QUF1QkQsSUFBWSxTQUdYO0FBSEQsV0FBWSxTQUFTO0lBQ25CLG9DQUF1QixDQUFBO0lBQ3ZCLGtDQUFxQixDQUFBO0FBQ3ZCLENBQUMsRUFIVyxTQUFTLHlCQUFULFNBQVMsUUFHcEIiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZW51bSBBc3NldFR5cGUge1xuICBpbWFnZSA9ICdJTUFHRScsXG4gIHZpZGVvID0gJ1ZJREVPJ1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIEFzc2V0IHtcbiAgaWQ6IHN0cmluZztcbiAga2V5OiBzdHJpbmc7XG4gIHR5cGU6IEFzc2V0VHlwZTtcbiAgaXNUcmFzaGVkOiBib29sZWFuO1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIFNoYXJlZExpbmsge1xuICBrZXk6IHN0cmluZztcbiAgdHlwZTogc3RyaW5nO1xuICBhc3NldHM6IEFzc2V0W107XG4gIGFsYnVtPzoge1xuICAgIGlkOiBzdHJpbmc7XG4gIH1cbiAgZXhwaXJlc0F0OiBzdHJpbmcgfCBudWxsO1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIEFsYnVtIHtcbiAgYXNzZXRzOiBBc3NldFtdXG59XG5cbmV4cG9ydCBlbnVtIEltYWdlU2l6ZSB7XG4gIHRodW1ibmFpbCA9ICd0aHVtYm5haWwnLFxuICBvcmlnaW5hbCA9ICdvcmlnaW5hbCdcbn1cbiJdfQ== \ No newline at end of file diff --git a/src/immich.ts b/src/immich.ts index 3228dd9..d815d37 100644 --- a/src/immich.ts +++ b/src/immich.ts @@ -29,28 +29,17 @@ class Immich { /** * Query Immich for the SharedLink metadata for a given key. * The key is what is returned in the URL when you create a share in Immich. - * - * Immich doesn't have a method to query by key, so this method gets all - * known shared links, and returns the link which matches the provided key. */ async getShareByKey (key: string) { - const res = (await this.request('/shared-links') || []) as SharedLink[] - const link = res.find(x => x.key === key) + const link = (await this.request('/shared-links/me?key=' + encodeURIComponent(key)) || []) as SharedLink if (link) { if (link.expiresAt && dayjs(link.expiresAt) < dayjs()) { // This link has expired log('Expired link ' + key) } else { - if (link.type === 'ALBUM') { - // Fetch the assets from the album and populate the SharedLink assets array - const albumId = link.album?.id - if (albumId) { - const album = (await this.request('/albums/' + encodeURIComponent(albumId))) as Album - link.assets = album.assets || [] - } - } // Filter assets to exclude trashed assets - link.assets = link.assets.filter(x => !x.isTrashed) + link.assets = link.assets.filter(asset => !asset.isTrashed) + link.assets.forEach(asset => { asset.key = key }) return link } } @@ -66,9 +55,9 @@ class Immich { switch (asset.type) { case AssetType.image: size = size === ImageSize.thumbnail ? ImageSize.thumbnail : ImageSize.original - return this.request('/assets/' + encodeURIComponent(asset.id) + '/' + size) + return this.request('/assets/' + encodeURIComponent(asset.id) + '/' + size + '?key=' + encodeURIComponent(asset.key)) case AssetType.video: - return this.request('/assets/' + encodeURIComponent(asset.id) + '/video/playback') + return this.request('/assets/' + encodeURIComponent(asset.id) + '/video/playback?key=' + encodeURIComponent(asset.key)) } } diff --git a/src/types.ts b/src/types.ts index ceadb0b..65f85b0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,6 +5,7 @@ export enum AssetType { export interface Asset { id: string; + key: string; type: AssetType; isTrashed: boolean; }