Add additional log messages for 4xx responses
This commit is contained in:
Generated
+2
-2
@@ -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",
|
||||
|
||||
+1
-1
@@ -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",
|
||||
|
||||
+3
-5
@@ -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
|
||||
|
||||
+5
-8
@@ -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
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user