From c23de6331d72e5c55fff5b389108204c67a39adc Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Sat, 11 Oct 2025 13:37:05 +0800 Subject: [PATCH] Add additional log messages for 4xx responses --- app/package-lock.json | 4 ++-- app/package.json | 2 +- app/src/immich.ts | 8 +++----- app/src/index.ts | 13 +++++-------- app/src/invalidRequestHandler.ts | 8 ++++++-- app/src/render.ts | 4 ++-- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/package-lock.json b/app/package-lock.json index 4f9b06d..19b4a2b 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -1,12 +1,12 @@ { "name": "immich-public-proxy", - "version": "1.13.3", + "version": "1.13.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "immich-public-proxy", - "version": "1.13.3", + "version": "1.13.5", "license": "AGPL-3.0", "dependencies": { "archiver": "^7.0.1", diff --git a/app/package.json b/app/package.json index 86cfbb5..4b473c2 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "immich-public-proxy", - "version": "1.13.4", + "version": "1.13.5", "scripts": { "dev": "ts-node src/index.ts", "build": "npx tsc", diff --git a/app/src/immich.ts b/app/src/immich.ts index 907f5ff..5668167 100644 --- a/app/src/immich.ts +++ b/app/src/immich.ts @@ -59,8 +59,7 @@ class Immich { // Check that the key is a valid format if (!immich.isKey(request.key)) { - log('Wrong key format ' + request.key) - respondToInvalidRequest(res, 404) + respondToInvalidRequest(res, 404, 'Wrong key format ' + request.key) return } @@ -68,7 +67,7 @@ class Immich { const sharedLinkRes = await immich.getShareByKey(request.key, request.password, request.keyType || KeyType.key) if (!sharedLinkRes.valid) { // This isn't a valid request - check the console for more information - respondToInvalidRequest(res, 404) + respondToInvalidRequest(res, 404, 'Invalid request') return } @@ -100,8 +99,7 @@ class Immich { } if (!sharedLinkRes.link) { - log('Unknown error with key ' + request.key) - respondToInvalidRequest(res, 404) + respondToInvalidRequest(res, 404, 'Unknown error with key ' + request.key) return } const link = sharedLinkRes.link diff --git a/app/src/index.ts b/app/src/index.ts index 7863a18..0305a7a 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -8,7 +8,7 @@ import render from './render' import dayjs from 'dayjs' import { NextFunction, Request, Response } from 'express-serve-static-core' import { Asset, AssetType, ImageSize, KeyType } from './types' -import { addResponseHeaders, getConfigOption, log, toString } from './functions' +import { addResponseHeaders, getConfigOption, toString } from './functions' import { decrypt, encrypt } from './encrypt' import { respondToInvalidRequest } from './invalidRequestHandler' @@ -79,7 +79,7 @@ app.get('/:shareType(share|s)/:key/:mode(download)?', decodeCookie, async (req, if (keyType === KeyType.slug && !getConfigOption('ipp.allowSlugLinks', true)) { // Slug type links are not allowed - respondToInvalidRequest(res, 404) + respondToInvalidRequest(res, 404, 'Slug links are disabled in config.json') } else { await immich.handleShareRequest({ req, @@ -115,15 +115,13 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r // Check for valid key and ID if (!immich.isKey(req.params.key) || !immich.isId(req.params.id)) { - log('Invalid key or ID for ' + req.path) - respondToInvalidRequest(res, 404) + respondToInvalidRequest(res, 404, 'Invalid key or ID for ' + req.path) return } // Validate the size parameter if (req.params.size && !Object.values(ImageSize).includes(req.params.size as ImageSize)) { - log('Invalid size parameter ' + req.path) - respondToInvalidRequest(res, 404) + respondToInvalidRequest(res, 404, 'Invalid size parameter ' + req.path) return } @@ -160,8 +158,7 @@ if (getConfigOption('ipp.showHomePage', true)) { * Send a 404 for all other routes */ app.get('*', (req, res) => { - log('Invalid route ' + req.path) - respondToInvalidRequest(res, 404) + respondToInvalidRequest(res, 404, 'Invalid route ' + req.path) }) // Send the correct process error code for any uncaught exceptions diff --git a/app/src/invalidRequestHandler.ts b/app/src/invalidRequestHandler.ts index 9c54b27..b76d209 100644 --- a/app/src/invalidRequestHandler.ts +++ b/app/src/invalidRequestHandler.ts @@ -5,26 +5,30 @@ through a Docker volume mount. */ import { Response } from 'express-serve-static-core' -import { getConfigOption } from './functions' +import { getConfigOption, log } from './functions' -export function respondToInvalidRequest (res: Response, defaultResponse: number | string | null) { +export function respondToInvalidRequest (res: Response, defaultResponse: number | string | null, logMessage = '') { let method = getConfigOption('ipp.customInvalidResponse', false) if (method === false) { // No custom method specified, use the default method = defaultResponse } + logMessage = logMessage ? ' - ' + logMessage : '' if (typeof method === 'number') { // Respond with an HTTP status code + log('Return status ' + method + logMessage) res.status(method).send() } else if (method === null) { // Drop the connection without responding + log('Dropping connection' + logMessage) res.destroy() } else if (typeof method === 'string' && method.startsWith('http')) { // Redirect to another URL res.redirect(method) } else { // Fallback to 404 + log('Return status 404' + logMessage) res.status(404).send() } } diff --git a/app/src/render.ts b/app/src/render.ts index e6b1546..d16d945 100644 --- a/app/src/render.ts +++ b/app/src/render.ts @@ -25,7 +25,7 @@ class Render { // Make sure we should display this asset if (meta.isTrashed || meta.visibility === 'locked') { - respondToInvalidRequest(res, 404) + respondToInvalidRequest(res, 404, `Asset ${asset.id} is trashed or locked`) return } @@ -88,7 +88,7 @@ class Render { ) res.end() } else { - respondToInvalidRequest(res, 404) + respondToInvalidRequest(res, 404, 'Non-200 response from Immich for asset ' + asset.id) } }