From d9bd631d16701bb508d28a9c2b8e56733ce10498 Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Mon, 21 Jul 2025 12:10:18 +0200 Subject: [PATCH] #112 Improve og:image base URL function --- README.md | 21 +++++++++++---------- app/config.json | 1 + app/package-lock.json | 18 +++++++++--------- app/package.json | 2 +- app/src/render.ts | 12 +++++------- app/views/gallery.ejs | 2 +- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index f495abc..e75fc9e 100644 --- a/README.md +++ b/README.md @@ -140,16 +140,17 @@ There are some additional configuration options you can change, for example the ### Immich Public Proxy options -| Option | Type | Description | -|-------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `responseHeaders` | `object` | Change the headers sent with your web responses. By default there is `cache-control` and CORS added. | -| `singleImageGallery` | `bool` | By default a link to a single image will directly open the image file. Set to `true` if you want to show a gallery page instead for a single item. | -| `downloadOriginalPhoto` | `bool` | Set to `false` if you only want people to be able to download the 'preview' quality photo, rather than your original photo. | -| `showGalleryTitle` | `bool` | Show a title on the gallery page. | -| `allowDownloadAll` | `int` | Allow visitors to download all files as a zip.
`0` disable downloads
`1` follow Immich setting per share ([example](https://github.com/user-attachments/assets/79ea8c08-71ce-42ab-b025-10aec384938a))
`2` always allowed | -| `showHomePage` | `bool` | Set to `false` to remove the IPP shield page at `/` and at `/share` | -| `showMetadata` | `object` | See the [Metadata](#metadata) section below. | -| `customInvalidResponse` | various | Send a custom response instead of the default 404 - see [Custom responses](docs/custom-responses.md) for more details. | +| Option | Type | Description | +|-------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `publicBaseUrl` | `string` | Set this to be the base public URL of your IPP instance. This is used for generating the `og:image` URL. If you want to use multiple public URLs, you can instead set this value to `null` and send a `publicBaseUrl` header on the request from your reverse proxy to IPP. | +| `responseHeaders` | `object` | Change the headers sent with your web responses. By default there is `cache-control` and CORS added. | +| `singleImageGallery` | `bool` | By default a link to a single image will directly open the image file. Set to `true` if you want to show a gallery page instead for a single item. | +| `downloadOriginalPhoto` | `bool` | Set to `false` if you only want people to be able to download the 'preview' quality photo, rather than your original photo. | +| `showGalleryTitle` | `bool` | Show a title on the gallery page. | +| `allowDownloadAll` | `int` | Allow visitors to download all files as a zip.
`0` disable downloads
`1` follow Immich setting per share ([example](https://github.com/user-attachments/assets/79ea8c08-71ce-42ab-b025-10aec384938a))
`2` always allowed | +| `showHomePage` | `bool` | Set to `false` to remove the IPP shield page at `/` and at `/share` | +| `showMetadata` | `object` | See the [Metadata](#metadata) section below. | +| `customInvalidResponse` | various | Send a custom response instead of the default 404 - see [Custom responses](docs/custom-responses.md) for more details. | For example, to disable the home page at `/` and at `/share` you need to change `showHomePage` to `false`: diff --git a/app/config.json b/app/config.json index a3413cb..5fdf6d3 100644 --- a/app/config.json +++ b/app/config.json @@ -1,5 +1,6 @@ { "ipp": { + "publicBaseUrl": "https://your-proxy-url.com", "responseHeaders": { "Cache-Control": "public, max-age=2592000", "Access-Control-Allow-Origin": "*" diff --git a/app/package-lock.json b/app/package-lock.json index e07e758..37e0807 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,12 +1,12 @@ { "name": "immich-public-proxy", - "version": "1.11.5", + "version": "1.12.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "immich-public-proxy", - "version": "1.11.5", + "version": "1.12.0", "license": "AGPL-3.0", "dependencies": { "archiver": "^7.0.1", @@ -1261,14 +1261,14 @@ } }, "node_modules/cookie-session": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/cookie-session/-/cookie-session-2.1.0.tgz", - "integrity": "sha512-u73BDmR8QLGcs+Lprs0cfbcAPKl2HnPcjpwRXT41sEV4DRJ2+W0vJEEZkG31ofkx+HZflA70siRIjiTdIodmOQ==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/cookie-session/-/cookie-session-2.1.1.tgz", + "integrity": "sha512-ji3kym/XZaFVew1+tIZk5ZLp9Z/fLv9rK1aZmpug0FsgE7Cu3ZDrUdRo7FT9vFjMYfNimrrUHJzywDwT7XEFlg==", "license": "MIT", "dependencies": { "cookies": "0.9.1", "debug": "3.2.7", - "on-headers": "~1.0.2", + "on-headers": "~1.1.0", "safe-buffer": "5.2.1" }, "engines": { @@ -3927,9 +3927,9 @@ } }, "node_modules/on-headers": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", - "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.1.0.tgz", + "integrity": "sha512-737ZY3yNnXy37FHkQxPzt4UZ2UWPWiCZWLvFZ4fu5cueciegX0zGPnrlY6bwRg4FdQOe9YU8MkmJwGhoMybl8A==", "license": "MIT", "engines": { "node": ">= 0.8" diff --git a/app/package.json b/app/package.json index 57d917c..6c34395 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "immich-public-proxy", - "version": "1.11.5", + "version": "1.12.0", "scripts": { "dev": "ts-node src/index.ts", "build": "npx tsc", diff --git a/app/src/render.ts b/app/src/render.ts index 7bcc9a4..45e80c2 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -89,12 +89,9 @@ class Render { async gallery (res: Response, share: SharedLink, openItem?: number) { const items = [] - // Originally I had the base URL as a config option in .env. - // The issue with that is people who may be wanting to route in via multiple - // public URLs. So instead we generate the base URL from the incoming request data. - // This may cause issues with some reverse proxies, in which case just make sure - // that you're sending the correct `host` header to IPP. - const baseUrl = res.req.protocol + '://' + res.req.headers.host + // publicBaseUrl is used for the og:image, which requires a fully qualified URL. + // You can specify this in your config.json file, or send it dynamically as a `host` header + const publicBaseUrl = getConfigOption('ipp.publicBaseUrl', null) || res.req.headers.publicBaseUrl || '' for (const asset of share.assets) { let video, downloadUrl @@ -118,7 +115,7 @@ class Render { downloadUrl = immich.photoUrl(share.key, asset.id, ImageSize.original) } - const thumbnailUrl = baseUrl + immich.photoUrl(share.key, asset.id, ImageSize.thumbnail) + const thumbnailUrl = immich.photoUrl(share.key, asset.id, ImageSize.thumbnail) const previewUrl = immich.photoUrl(share.key, asset.id, immich.getPreviewImageSize(asset)) const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string' ? asset.exifInfo.description.replace(/'/g, ''') : '' @@ -141,6 +138,7 @@ class Render { items, openItem, title: this.title(share), + publicBaseUrl, path: '/share/' + share.key, showDownload: canDownload(share), showTitle: getConfigOption('ipp.showGalleryTitle', false), diff --git a/app/views/gallery.ejs b/app/views/gallery.ejs index ab81f26..d728aa2 100644 --- a/app/views/gallery.ejs +++ b/app/views/gallery.ejs @@ -7,7 +7,7 @@ // Add an og-image using the first image's thumbnail if (items?.[0]?.thumbnailUrl) { %> - + <% } %>