#112 Improve og:image base URL function

This commit is contained in:
Alan Grainger
2025-07-21 12:10:18 +02:00
parent a7d7bf22b8
commit d9bd631d16
6 changed files with 28 additions and 28 deletions
+2 -1
View File
@@ -141,7 +141,8 @@ There are some additional configuration options you can change, for example the
### Immich Public Proxy options ### Immich Public Proxy options
| Option | Type | Description | | 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. | | `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. | | `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. | | `downloadOriginalPhoto` | `bool` | Set to `false` if you only want people to be able to download the 'preview' quality photo, rather than your original photo. |
+1
View File
@@ -1,5 +1,6 @@
{ {
"ipp": { "ipp": {
"publicBaseUrl": "https://your-proxy-url.com",
"responseHeaders": { "responseHeaders": {
"Cache-Control": "public, max-age=2592000", "Cache-Control": "public, max-age=2592000",
"Access-Control-Allow-Origin": "*" "Access-Control-Allow-Origin": "*"
+9 -9
View File
@@ -1,12 +1,12 @@
{ {
"name": "immich-public-proxy", "name": "immich-public-proxy",
"version": "1.11.5", "version": "1.12.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "immich-public-proxy", "name": "immich-public-proxy",
"version": "1.11.5", "version": "1.12.0",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"dependencies": { "dependencies": {
"archiver": "^7.0.1", "archiver": "^7.0.1",
@@ -1261,14 +1261,14 @@
} }
}, },
"node_modules/cookie-session": { "node_modules/cookie-session": {
"version": "2.1.0", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/cookie-session/-/cookie-session-2.1.0.tgz", "resolved": "https://registry.npmjs.org/cookie-session/-/cookie-session-2.1.1.tgz",
"integrity": "sha512-u73BDmR8QLGcs+Lprs0cfbcAPKl2HnPcjpwRXT41sEV4DRJ2+W0vJEEZkG31ofkx+HZflA70siRIjiTdIodmOQ==", "integrity": "sha512-ji3kym/XZaFVew1+tIZk5ZLp9Z/fLv9rK1aZmpug0FsgE7Cu3ZDrUdRo7FT9vFjMYfNimrrUHJzywDwT7XEFlg==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"cookies": "0.9.1", "cookies": "0.9.1",
"debug": "3.2.7", "debug": "3.2.7",
"on-headers": "~1.0.2", "on-headers": "~1.1.0",
"safe-buffer": "5.2.1" "safe-buffer": "5.2.1"
}, },
"engines": { "engines": {
@@ -3927,9 +3927,9 @@
} }
}, },
"node_modules/on-headers": { "node_modules/on-headers": {
"version": "1.0.2", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.1.0.tgz",
"integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==", "integrity": "sha512-737ZY3yNnXy37FHkQxPzt4UZ2UWPWiCZWLvFZ4fu5cueciegX0zGPnrlY6bwRg4FdQOe9YU8MkmJwGhoMybl8A==",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">= 0.8" "node": ">= 0.8"
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "immich-public-proxy", "name": "immich-public-proxy",
"version": "1.11.5", "version": "1.12.0",
"scripts": { "scripts": {
"dev": "ts-node src/index.ts", "dev": "ts-node src/index.ts",
"build": "npx tsc", "build": "npx tsc",
+5 -7
View File
@@ -89,12 +89,9 @@ class Render {
async gallery (res: Response, share: SharedLink, openItem?: number) { async gallery (res: Response, share: SharedLink, openItem?: number) {
const items = [] const items = []
// Originally I had the base URL as a config option in .env. // publicBaseUrl is used for the og:image, which requires a fully qualified URL.
// The issue with that is people who may be wanting to route in via multiple // You can specify this in your config.json file, or send it dynamically as a `host` header
// public URLs. So instead we generate the base URL from the incoming request data. const publicBaseUrl = getConfigOption('ipp.publicBaseUrl', null) || res.req.headers.publicBaseUrl || ''
// 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
for (const asset of share.assets) { for (const asset of share.assets) {
let video, downloadUrl let video, downloadUrl
@@ -118,7 +115,7 @@ class Render {
downloadUrl = immich.photoUrl(share.key, asset.id, ImageSize.original) 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 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, ''') : '' const description = getConfigOption('ipp.showMetadata.description', false) && typeof asset?.exifInfo?.description === 'string' ? asset.exifInfo.description.replace(/'/g, ''') : ''
@@ -141,6 +138,7 @@ class Render {
items, items,
openItem, openItem,
title: this.title(share), title: this.title(share),
publicBaseUrl,
path: '/share/' + share.key, path: '/share/' + share.key,
showDownload: canDownload(share), showDownload: canDownload(share),
showTitle: getConfigOption('ipp.showGalleryTitle', false), showTitle: getConfigOption('ipp.showGalleryTitle', false),
+1 -1
View File
@@ -7,7 +7,7 @@
// Add an og-image using the first image's thumbnail // Add an og-image using the first image's thumbnail
if (items?.[0]?.thumbnailUrl) { if (items?.[0]?.thumbnailUrl) {
%> %>
<meta property="og:image" content="<%- items[0].thumbnailUrl %>"/> <meta property="og:image" content="<%- publicBaseUrl %><%- items[0].thumbnailUrl %>"/>
<% } %> <% } %>
<link rel="icon" href="/share/static/favicon.ico" type="image/x-icon"> <link rel="icon" href="/share/static/favicon.ico" type="image/x-icon">
<link type="text/css" rel="stylesheet" href="/share/static/style.css"/> <link type="text/css" rel="stylesheet" href="/share/static/style.css"/>