From 0bbe409cbbb94f5a123ad3681e3172ac1f1f8242 Mon Sep 17 00:00:00 2001 From: Alan Grainger Date: Wed, 12 Mar 2025 15:26:46 +0800 Subject: [PATCH] #76 add option to follow Immich per-link download settings --- README.md | 16 ++++++++-------- app/config.json | 2 +- app/package-lock.json | 4 ++-- app/package.json | 2 +- app/src/functions.ts | 15 +++++++++++++++ app/src/immich.ts | 4 ++-- app/src/render.ts | 4 ++-- app/src/types.ts | 7 +++++++ 8 files changed, 38 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a451100..7152b26 100644 --- a/README.md +++ b/README.md @@ -140,14 +140,14 @@ There are some additional configuration options you can change, for example the ### Immich Public Proxy options -| Option | Description | -|-------------------------|-----------------------------------------------------------------------------------------------------------------------------| -| `responseHeaders` | Change the headers sent with your web responses. By default there is `cache-control` and CORS added. | -| `downloadOriginalPhoto` | Set to `false` if you only want people to be able to download the 'preview' quality photo, rather than your original photo. | -| `showGalleryTitle` | Show a title on the gallery page. | -| `allowDownloadAll` | Allow visitors to download all files as a zip. | -| `showHomePage` | Set to `false` to remove the IPP shield page at `/` and at `/share` | -| `customInvalidResponse` | 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. | +| `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
`2` always allowed | +| `showHomePage` | `bool` | Set to `false` to remove the IPP shield page at `/` and at `/share` | +| `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 62db069..a77788b 100644 --- a/app/config.json +++ b/app/config.json @@ -8,7 +8,7 @@ "singleItemAutoOpen": true, "downloadOriginalPhoto": true, "showGalleryTitle": false, - "allowDownloadAll": false, + "allowDownloadAll": 0, "showHomePage": true, "customInvalidResponse": false }, diff --git a/app/package-lock.json b/app/package-lock.json index 056e5d2..28dab35 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,12 +1,12 @@ { "name": "immich-public-proxy", - "version": "1.8.0", + "version": "1.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "immich-public-proxy", - "version": "1.8.0", + "version": "1.9.0", "license": "AGPL-3.0", "dependencies": { "archiver": "^7.0.1", diff --git a/app/package.json b/app/package.json index a2541eb..fecaa49 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "immich-public-proxy", - "version": "1.8.0", + "version": "1.9.0", "scripts": { "dev": "ts-node src/index.ts", "build": "npx tsc", diff --git a/app/src/functions.ts b/app/src/functions.ts index 3ffeb1a..437364f 100644 --- a/app/src/functions.ts +++ b/app/src/functions.ts @@ -1,5 +1,6 @@ import dayjs from 'dayjs' import { Response } from 'express-serve-static-core' +import { DownloadAll, SharedLink } from './types' let config = {} try { @@ -46,3 +47,17 @@ export function addResponseHeaders (res: Response) { res.set(header, value) }) } + +export function canDownload (share: SharedLink) { + const allowDownloadConfig = getConfigOption('ipp.allowDownloadAll', 0) as DownloadAll + if (!allowDownloadConfig) { + // Downloading is disabled in config.json + return false + } else if (allowDownloadConfig === DownloadAll.always) { + // Always allowed to download in config.json + return true + } else { + // Return Immich's setting for this shared link + return !!share.allowDownload + } +} diff --git a/app/src/immich.ts b/app/src/immich.ts index 2fce1e2..ec0107a 100644 --- a/app/src/immich.ts +++ b/app/src/immich.ts @@ -1,6 +1,6 @@ import { Asset, AssetType, ImageSize, IncomingShareRequest, SharedLink, SharedLinkResult } from './types' import dayjs from 'dayjs' -import { addResponseHeaders, getConfigOption, log } from './functions' +import { addResponseHeaders, canDownload, getConfigOption, log } from './functions' import render from './render' import { Response } from 'express-serve-static-core' import { respondToInvalidRequest } from './invalidRequestHandler' @@ -105,7 +105,7 @@ class Immich { // Everything is ok - output the shared link data - if (request.mode === 'download' && getConfigOption('ipp.allowDownloadAll', false)) { + if (request.mode === 'download' && canDownload(link)) { // Download all assets as a zip file await render.downloadAll(res, link) } else if (link.assets.length === 1) { diff --git a/app/src/render.ts b/app/src/render.ts index cea1fb4..88a861c 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -1,7 +1,7 @@ import immich from './immich' import { Response } from 'express-serve-static-core' import { Asset, AssetType, ImageSize, IncomingShareRequest, SharedLink } from './types' -import { getConfigOption } from './functions' +import { canDownload, getConfigOption } from './functions' import archiver from 'archiver' import { respondToInvalidRequest } from './invalidRequestHandler' @@ -121,7 +121,7 @@ class Render { openItem, title: this.title(share), path: '/share/' + share.key, - showDownload: getConfigOption('ipp.allowDownloadAll', false), + showDownload: canDownload(share), showTitle: getConfigOption('ipp.showGalleryTitle', false), lgConfig: getConfigOption('lightGallery', {}) }) diff --git a/app/src/types.ts b/app/src/types.ts index 407bbdb..8ac6d84 100644 --- a/app/src/types.ts +++ b/app/src/types.ts @@ -20,6 +20,7 @@ export interface SharedLink { type: string; description?: string; assets: Asset[]; + allowDownload?: boolean; password?: string; album?: { id: string; @@ -50,3 +51,9 @@ export interface IncomingShareRequest { size?: ImageSize; range?: string; } + +export enum DownloadAll { + disabled, + perImmich, + always +}