Update healthcheck

This commit is contained in:
Alan Grainger
2024-11-04 11:15:00 +01:00
parent be66b16a08
commit 4b0253f211
5 changed files with 34 additions and 21 deletions
+17 -9
View File
@@ -11,17 +11,21 @@ class Immich {
* the possible attack surface of this app.
*/
async request (endpoint: string) {
const res = await fetch(process.env.IMMICH_URL + '/api' + endpoint)
if (res.status === 200) {
const contentType = res.headers.get('Content-Type') || ''
if (contentType.includes('application/json')) {
return res.json()
try {
const res = await fetch(process.env.IMMICH_URL + '/api' + endpoint)
if (res.status === 200) {
const contentType = res.headers.get('Content-Type') || ''
if (contentType.includes('application/json')) {
return res.json()
} else {
return res
}
} else {
return res
log('Immich API status ' + res.status)
console.log(await res.text())
}
} else {
log('Immich API status ' + res.status)
console.log(await res.text())
} catch (e) {
log('Unable to reach Immich on ' + process.env.IMMICH_URL)
}
}
@@ -229,6 +233,10 @@ class Immich {
expires: dayjs().add(1, 'hour').format()
}))
}
async accessible () {
return !!(await immich.request('/server/ping'))
}
}
const immich = new Immich()