Initial work on upload app server
This commit is contained in:
+3
-13
@@ -4,7 +4,6 @@ import 'dotenv/config'
|
||||
import express from 'express'
|
||||
import { resolve } from 'path'
|
||||
import {
|
||||
accessible,
|
||||
addNoStoreHeaders,
|
||||
addResponseHeaders,
|
||||
Asset,
|
||||
@@ -16,6 +15,7 @@ import {
|
||||
errorHandler,
|
||||
getConfigOption,
|
||||
getKeyTypeFromShare,
|
||||
healthcheck,
|
||||
isId,
|
||||
isKey,
|
||||
KeyType,
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
sessionMiddleware,
|
||||
setInvalidRequestHandler,
|
||||
SharedLink,
|
||||
slugLinksDisabled,
|
||||
unlockHandler
|
||||
} from '@ipp/core'
|
||||
import { fetchAssetDetail, getShareByKey, handleShareRequest } from './immich'
|
||||
@@ -97,11 +98,6 @@ type SharedAssetResolution =
|
||||
| { ok: true, link: SharedLink, asset: Asset }
|
||||
| { ok: false, status: number, reason: string, passwordRequired?: boolean }
|
||||
|
||||
/** Whether this is a slug link and the operator has turned slug links off. */
|
||||
function slugLinksDisabled (keyType: KeyType): boolean {
|
||||
return keyType === KeyType.slug && !getConfigOption('ipp.allowSlugLinks', true)
|
||||
}
|
||||
|
||||
async function resolveShare (req: Request, keyType: KeyType): Promise<ShareResolution> {
|
||||
if (slugLinksDisabled(keyType)) {
|
||||
return { ok: false, status: 404, reason: 'Slug links are disabled in config.json' }
|
||||
@@ -152,13 +148,7 @@ async function resolveSharedAsset (req: Request, keyType: KeyType, allowMotion =
|
||||
* [ROUTE] Healthcheck
|
||||
* The path matches for /share/healthcheck, and also the legacy /healthcheck
|
||||
*/
|
||||
app.get(/^(|\/share)\/healthcheck$/, asyncHandler(async (_req, res) => {
|
||||
if (await accessible()) {
|
||||
res.send('ok')
|
||||
} else {
|
||||
res.status(503).send()
|
||||
}
|
||||
}))
|
||||
app.get(/^(|\/share)\/healthcheck$/, asyncHandler(healthcheck))
|
||||
|
||||
/*
|
||||
* [ROUTE] This is the main URL that someone would visit if they are opening a shared link
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { Transform } from 'stream'
|
||||
|
||||
/**
|
||||
* A pass-through Transform that destroys itself if no data flows through for
|
||||
* `idleMs`. The timer is set when the transform is created and reset on every
|
||||
* chunk, so a slow-but-steady download (large video over a slow link) keeps
|
||||
* going, while a genuinely stalled connection still fails fast.
|
||||
*/
|
||||
export function createIdleTimeoutStream (idleMs: number): Transform {
|
||||
let timer: NodeJS.Timeout | undefined
|
||||
const transform: Transform = new Transform({
|
||||
transform (chunk, _, cb) {
|
||||
if (timer) clearTimeout(timer)
|
||||
timer = setTimeout(() => transform.destroy(new Error(`No data received for ${idleMs}ms`)), idleMs)
|
||||
cb(null, chunk)
|
||||
},
|
||||
flush (cb) {
|
||||
if (timer) clearTimeout(timer)
|
||||
cb()
|
||||
}
|
||||
})
|
||||
// Arm the timer immediately so a response that returns headers but never
|
||||
// sends a body also times out.
|
||||
timer = setTimeout(() => transform.destroy(new Error(`No data received for ${idleMs}ms`)), idleMs)
|
||||
return transform
|
||||
}
|
||||
+2
-17
@@ -1,22 +1,7 @@
|
||||
import { readFileSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
import { resolveAppVersion } from '@ipp/core'
|
||||
|
||||
/**
|
||||
* Resolve the running application version. Prefers the APP_VERSION env var
|
||||
* baked in at Docker build time (see Dockerfile); falls back to package.json
|
||||
* for local dev (`npm run dev`), and finally to 'dev' if neither is readable.
|
||||
*/
|
||||
function resolveVersion (): string {
|
||||
if (process.env.APP_VERSION) return process.env.APP_VERSION
|
||||
try {
|
||||
const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'))
|
||||
return pkg.version || 'dev'
|
||||
} catch {
|
||||
return 'dev'
|
||||
}
|
||||
}
|
||||
|
||||
export const APP_VERSION = resolveVersion()
|
||||
export const APP_VERSION = resolveAppVersion(join(__dirname, '..', 'package.json'))
|
||||
|
||||
/** URL-safe cache-busting segment for static asset paths. */
|
||||
export const ASSET_VERSION = encodeURIComponent(APP_VERSION)
|
||||
|
||||
Reference in New Issue
Block a user