From e7dc11a66c09dff3386171ec26bd787be52b169b Mon Sep 17 00:00:00 2001
From: Alan Grainger <16197738+alangrainger@users.noreply.github.com>
Date: Sat, 20 Sep 2025 20:10:46 +0200
Subject: [PATCH] #116 Support custom URL links (slug-type links)
---
README.md | 21 +++++++++++----------
app/config.json | 1 +
app/package-lock.json | 4 ++--
app/package.json | 2 +-
app/src/immich.ts | 7 ++++++-
app/src/index.ts | 43 +++++++++++++++++++++----------------------
app/src/render.ts | 12 ++++++++++++
app/src/types.ts | 1 +
8 files changed, 55 insertions(+), 36 deletions(-)
diff --git a/README.md b/README.md
index b6f4214..aa7ee75 100644
--- a/README.md
+++ b/README.md
@@ -146,16 +146,17 @@ Alternatively, you can [pass the configuration inline](docs/inline-configuration
### 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 |
+|-------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `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 |
+| `allowSlugLinks` | `bool` | Enable/disable the custom URL links. |
+| `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..6e8e92d 100644
--- a/app/config.json
+++ b/app/config.json
@@ -8,6 +8,7 @@
"singleItemAutoOpen": true,
"downloadOriginalPhoto": true,
"allowDownloadAll": 0,
+ "allowSlugLinks": true,
"showHomePage": true,
"showGalleryTitle": false,
"showMetadata": {
diff --git a/app/package-lock.json b/app/package-lock.json
index a620df0..2186a7a 100644
--- a/app/package-lock.json
+++ b/app/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "immich-public-proxy",
- "version": "1.12.1",
+ "version": "1.13.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "immich-public-proxy",
- "version": "1.12.1",
+ "version": "1.13.1",
"license": "AGPL-3.0",
"dependencies": {
"archiver": "^7.0.1",
diff --git a/app/package.json b/app/package.json
index 0bf86c5..87262b1 100644
--- a/app/package.json
+++ b/app/package.json
@@ -1,6 +1,6 @@
{
"name": "immich-public-proxy",
- "version": "1.13.0",
+ "version": "1.13.1",
"scripts": {
"dev": "ts-node src/index.ts",
"build": "npx tsc",
diff --git a/app/src/immich.ts b/app/src/immich.ts
index cfb922a..1d3466a 100644
--- a/app/src/immich.ts
+++ b/app/src/immich.ts
@@ -156,12 +156,13 @@ class Immich {
if (res.status === 200) {
// Normal response - get the shared assets
link = jsonBody as SharedLink
+ link.keyType = keyType
// For an album, we need to make a second request to Immich to populate
// the array of assets
if (link.type === AlbumType.album) {
const albumRes = await fetch(this.buildUrl(this.apiUrl() + '/albums/' + link?.album?.id, {
- key,
+ [keyType]: key,
password
}))
const album = await albumRes.json() as Album
@@ -310,6 +311,10 @@ class Immich {
return size as ImageSize
}
}
+
+ getKeyTypeFromShare (shareType: string) {
+ return shareType === 's' ? KeyType.slug : KeyType.key
+ }
}
const immich = new Immich()
diff --git a/app/src/index.ts b/app/src/index.ts
index 99ce354..7863a18 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -7,7 +7,7 @@ import crypto from 'crypto'
import render from './render'
import dayjs from 'dayjs'
import { NextFunction, Request, Response } from 'express-serve-static-core'
-import { AssetType, ImageSize, KeyType } from './types'
+import { Asset, AssetType, ImageSize, KeyType } from './types'
import { addResponseHeaders, getConfigOption, log, toString } from './functions'
import { decrypt, encrypt } from './encrypt'
import { respondToInvalidRequest } from './invalidRequestHandler'
@@ -75,13 +75,20 @@ app.get(/^(|\/share)\/healthcheck$/, async (_req, res) => {
* [ROUTE] This is the main URL that someone would visit if they are opening a shared link
*/
app.get('/:shareType(share|s)/:key/:mode(download)?', decodeCookie, async (req, res) => {
- await immich.handleShareRequest({
- req,
- key: req.params.key,
- keyType: req.params.shareType === 's' ? KeyType.slug : KeyType.key,
- mode: req.params.mode,
- password: req.password
- }, res)
+ const keyType = immich.getKeyTypeFromShare(req.params.shareType)
+
+ if (keyType === KeyType.slug && !getConfigOption('ipp.allowSlugLinks', true)) {
+ // Slug type links are not allowed
+ respondToInvalidRequest(res, 404)
+ } else {
+ await immich.handleShareRequest({
+ req,
+ key: req.params.key,
+ keyType,
+ mode: req.params.mode,
+ password: req.password
+ }, res)
+ }
})
/*
@@ -120,25 +127,17 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r
return
}
- // Fetch the shared link information from Immich, so we can check to make sure that the requested asset
- // is allowed by this shared link.
- const sharedLink = (await immich.getShareByKey(req.params.key, req.password))?.link
const request = {
req,
key: req.params.key,
range: req.headers.range || ''
}
- if (sharedLink?.assets.length) {
- // Check that the requested asset exists in this share
- const asset = sharedLink.assets.find(x => x.id === req.params.id)
- if (asset) {
- asset.type = req.params.type === 'video' ? AssetType.video : AssetType.image
- render.assetBuffer(request, res, asset, req.params.size).then()
- }
- } else {
- log('No asset found for ' + req.path)
- respondToInvalidRequest(res, 404)
- }
+ const asset = {
+ id: req.params.id,
+ key: req.params.key,
+ type: req.params.type === 'video' ? AssetType.video : AssetType.image
+ } as Asset
+ render.assetBuffer(request, res, asset, req.params.size).then()
})
/*
diff --git a/app/src/render.ts b/app/src/render.ts
index 073715c..a2f25d0 100644
--- a/app/src/render.ts
+++ b/app/src/render.ts
@@ -16,6 +16,18 @@ class Render {
* Stream data from Immich back to the client
*/
async assetBuffer (req: IncomingShareRequest, res: Response, asset: Asset, size?: ImageSize | string) {
+ // Get meta info regarding the asset
+ const metaRes = await fetch(immich.buildUrl(immich.apiUrl() + '/assets/' + encodeURIComponent(asset.id), {
+ key: asset.key
+ }))
+ const meta = await metaRes.json()
+
+ // Make sure we should display this asset
+ if (meta.isTrashed || meta.visibility === 'locked') {
+ respondToInvalidRequest(res, 404)
+ return
+ }
+
// Prepare the request
const headerList = ['content-type', 'content-length', 'last-modified', 'etag']
size = immich.validateImageSize(size)
diff --git a/app/src/types.ts b/app/src/types.ts
index ffaee6b..44425e9 100644
--- a/app/src/types.ts
+++ b/app/src/types.ts
@@ -38,6 +38,7 @@ export interface Album {
export interface SharedLink {
key: string;
+ keyType: KeyType;
type: string;
description?: string;
assets: Asset[];