1
0
Fork 0
mirror of https://github.com/alangrainger/immich-public-proxy.git synced 2024-12-29 12:21:57 +00:00

Removed API key requirement thanks to #3

This commit is contained in:
Alan Grainger 2024-10-30 20:21:12 +01:00
parent 6df65ec5b6
commit 0304b0b787
6 changed files with 13 additions and 38 deletions

View file

@ -1,4 +1,3 @@
IMMICH_URL=http://localhost:2283 IMMICH_URL=http://localhost:2283
API_KEY="Get this from your Immich Account Settings page"
PORT=3000 PORT=3000
CACHE_AGE=2592000 CACHE_AGE=2592000

View file

@ -31,13 +31,11 @@ git clone https://github.com/alangrainger/immich-public-proxy.git
``` ```
IMMICH_URL=http://localhost:2283 IMMICH_URL=http://localhost:2283
API_KEY="Get this from your Immich Account Settings page"
PORT=3000 PORT=3000
CACHE_AGE=2592000 CACHE_AGE=2592000
``` ```
- `IMMICH_URL` is the URL to access Immich in your local network. This is not your public URL. - `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. - `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: 3. Start the docker container:

24
dist/immich.js vendored

File diff suppressed because one or more lines are too long

2
dist/types.js vendored
View file

@ -11,4 +11,4 @@ var ImageSize;
ImageSize["thumbnail"] = "thumbnail"; ImageSize["thumbnail"] = "thumbnail";
ImageSize["original"] = "original"; ImageSize["original"] = "original";
})(ImageSize || (exports.ImageSize = ImageSize = {})); })(ImageSize || (exports.ImageSize = ImageSize = {}));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsSUFBWSxTQUdYO0FBSEQsV0FBWSxTQUFTO0lBQ25CLDRC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w0QkFBZSxDQUFBO0FBQ2pCLENBQUMsRUFIVyxTQUFTLHlCQUFULFNBQVMsUUFHcEI7QUF1QkQsSUFBWSxTQUdYO0FBSEQsV0FBWSxTQUFTO0lBQ25CLG9DQUF1QixDQUFBO0lBQ3ZCLGtDQUFxQixDQUFBO0FBQ3ZCLENBQUMsRUFIVyxTQUFTLHlCQUFULFNBQVMsUUFHcEIiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZW51bSBBc3NldFR5cGUge1xuICBpbWFnZSA9ICdJTUFHRScsXG4gIHZpZGVvID0gJ1ZJREVPJ1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIEFzc2V0IHtcbiAgaWQ6IHN0cmluZztcbiAga2V5OiBzdHJpbmc7XG4gIHR5cGU6IEFzc2V0VHlwZTtcbiAgaXNUcmFzaGVkOiBib29sZWFuO1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIFNoYXJlZExpbmsge1xuICBrZXk6IHN0cmluZztcbiAgdHlwZTogc3RyaW5nO1xuICBhc3NldHM6IEFzc2V0W107XG4gIGFsYnVtPzoge1xuICAgIGlkOiBzdHJpbmc7XG4gIH1cbiAgZXhwaXJlc0F0OiBzdHJpbmcgfCBudWxsO1xufVxuXG5leHBvcnQgaW50ZXJmYWNlIEFsYnVtIHtcbiAgYXNzZXRzOiBBc3NldFtdXG59XG5cbmV4cG9ydCBlbnVtIEltYWdlU2l6ZSB7XG4gIHRodW1ibmFpbCA9ICd0aHVtYm5haWwnLFxuICBvcmlnaW5hbCA9ICdvcmlnaW5hbCdcbn1cbiJdfQ==

View file

@ -29,28 +29,17 @@ class Immich {
/** /**
* Query Immich for the SharedLink metadata for a given key. * 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. * 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) { async getShareByKey (key: string) {
const res = (await this.request('/shared-links') || []) as SharedLink[] const link = (await this.request('/shared-links/me?key=' + encodeURIComponent(key)) || []) as SharedLink
const link = res.find(x => x.key === key)
if (link) { if (link) {
if (link.expiresAt && dayjs(link.expiresAt) < dayjs()) { if (link.expiresAt && dayjs(link.expiresAt) < dayjs()) {
// This link has expired // This link has expired
log('Expired link ' + key) log('Expired link ' + key)
} else { } 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 // 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 return link
} }
} }
@ -66,9 +55,9 @@ class Immich {
switch (asset.type) { switch (asset.type) {
case AssetType.image: case AssetType.image:
size = size === ImageSize.thumbnail ? ImageSize.thumbnail : ImageSize.original 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: 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))
} }
} }

View file

@ -5,6 +5,7 @@ export enum AssetType {
export interface Asset { export interface Asset {
id: string; id: string;
key: string;
type: AssetType; type: AssetType;
isTrashed: boolean; isTrashed: boolean;
} }