Add additional log messages for 4xx responses

This commit is contained in:
Alan Grainger
2025-10-11 13:37:05 +08:00
parent 18bf03239f
commit c23de6331d
6 changed files with 19 additions and 20 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "immich-public-proxy", "name": "immich-public-proxy",
"version": "1.13.3", "version": "1.13.5",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "immich-public-proxy", "name": "immich-public-proxy",
"version": "1.13.3", "version": "1.13.5",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"dependencies": { "dependencies": {
"archiver": "^7.0.1", "archiver": "^7.0.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "immich-public-proxy", "name": "immich-public-proxy",
"version": "1.13.4", "version": "1.13.5",
"scripts": { "scripts": {
"dev": "ts-node src/index.ts", "dev": "ts-node src/index.ts",
"build": "npx tsc", "build": "npx tsc",
+3 -5
View File
@@ -59,8 +59,7 @@ class Immich {
// Check that the key is a valid format // Check that the key is a valid format
if (!immich.isKey(request.key)) { if (!immich.isKey(request.key)) {
log('Wrong key format ' + request.key) respondToInvalidRequest(res, 404, 'Wrong key format ' + request.key)
respondToInvalidRequest(res, 404)
return return
} }
@@ -68,7 +67,7 @@ class Immich {
const sharedLinkRes = await immich.getShareByKey(request.key, request.password, request.keyType || KeyType.key) const sharedLinkRes = await immich.getShareByKey(request.key, request.password, request.keyType || KeyType.key)
if (!sharedLinkRes.valid) { if (!sharedLinkRes.valid) {
// This isn't a valid request - check the console for more information // This isn't a valid request - check the console for more information
respondToInvalidRequest(res, 404) respondToInvalidRequest(res, 404, 'Invalid request')
return return
} }
@@ -100,8 +99,7 @@ class Immich {
} }
if (!sharedLinkRes.link) { if (!sharedLinkRes.link) {
log('Unknown error with key ' + request.key) respondToInvalidRequest(res, 404, 'Unknown error with key ' + request.key)
respondToInvalidRequest(res, 404)
return return
} }
const link = sharedLinkRes.link const link = sharedLinkRes.link
+5 -8
View File
@@ -8,7 +8,7 @@ import render from './render'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { NextFunction, Request, Response } from 'express-serve-static-core' import { NextFunction, Request, Response } from 'express-serve-static-core'
import { Asset, AssetType, ImageSize, KeyType } from './types' 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 { decrypt, encrypt } from './encrypt'
import { respondToInvalidRequest } from './invalidRequestHandler' 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)) { if (keyType === KeyType.slug && !getConfigOption('ipp.allowSlugLinks', true)) {
// Slug type links are not allowed // Slug type links are not allowed
respondToInvalidRequest(res, 404) respondToInvalidRequest(res, 404, 'Slug links are disabled in config.json')
} else { } else {
await immich.handleShareRequest({ await immich.handleShareRequest({
req, req,
@@ -115,15 +115,13 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r
// Check for valid key and ID // Check for valid key and ID
if (!immich.isKey(req.params.key) || !immich.isId(req.params.id)) { if (!immich.isKey(req.params.key) || !immich.isId(req.params.id)) {
log('Invalid key or ID for ' + req.path) respondToInvalidRequest(res, 404, 'Invalid key or ID for ' + req.path)
respondToInvalidRequest(res, 404)
return return
} }
// Validate the size parameter // Validate the size parameter
if (req.params.size && !Object.values(ImageSize).includes(req.params.size as ImageSize)) { if (req.params.size && !Object.values(ImageSize).includes(req.params.size as ImageSize)) {
log('Invalid size parameter ' + req.path) respondToInvalidRequest(res, 404, 'Invalid size parameter ' + req.path)
respondToInvalidRequest(res, 404)
return return
} }
@@ -160,8 +158,7 @@ if (getConfigOption('ipp.showHomePage', true)) {
* Send a 404 for all other routes * Send a 404 for all other routes
*/ */
app.get('*', (req, res) => { app.get('*', (req, res) => {
log('Invalid route ' + req.path) respondToInvalidRequest(res, 404, 'Invalid route ' + req.path)
respondToInvalidRequest(res, 404)
}) })
// Send the correct process error code for any uncaught exceptions // Send the correct process error code for any uncaught exceptions
+6 -2
View File
@@ -5,26 +5,30 @@ through a Docker volume mount.
*/ */
import { Response } from 'express-serve-static-core' 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) let method = getConfigOption('ipp.customInvalidResponse', false)
if (method === false) { if (method === false) {
// No custom method specified, use the default // No custom method specified, use the default
method = defaultResponse method = defaultResponse
} }
logMessage = logMessage ? ' - ' + logMessage : ''
if (typeof method === 'number') { if (typeof method === 'number') {
// Respond with an HTTP status code // Respond with an HTTP status code
log('Return status ' + method + logMessage)
res.status(method).send() res.status(method).send()
} else if (method === null) { } else if (method === null) {
// Drop the connection without responding // Drop the connection without responding
log('Dropping connection' + logMessage)
res.destroy() res.destroy()
} else if (typeof method === 'string' && method.startsWith('http')) { } else if (typeof method === 'string' && method.startsWith('http')) {
// Redirect to another URL // Redirect to another URL
res.redirect(method) res.redirect(method)
} else { } else {
// Fallback to 404 // Fallback to 404
log('Return status 404' + logMessage)
res.status(404).send() res.status(404).send()
} }
} }
+2 -2
View File
@@ -25,7 +25,7 @@ class Render {
// Make sure we should display this asset // Make sure we should display this asset
if (meta.isTrashed || meta.visibility === 'locked') { if (meta.isTrashed || meta.visibility === 'locked') {
respondToInvalidRequest(res, 404) respondToInvalidRequest(res, 404, `Asset ${asset.id} is trashed or locked`)
return return
} }
@@ -88,7 +88,7 @@ class Render {
) )
res.end() res.end()
} else { } else {
respondToInvalidRequest(res, 404) respondToInvalidRequest(res, 404, 'Non-200 response from Immich for asset ' + asset.id)
} }
} }