This commit is contained in:
+14
-1
@@ -169,11 +169,24 @@ html, body {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#gallery a:hover .tile-check,
|
|
||||||
#gallery.select-mode .tile-check {
|
#gallery.select-mode .tile-check {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Hover reveal only where hover is real: iOS spends a first tap on it #294 */
|
||||||
|
@media (hover: hover) {
|
||||||
|
#gallery a:hover .tile-check {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Touch outside select mode: no invisible tap target. Long-press selects */
|
||||||
|
@media (hover: none) {
|
||||||
|
#gallery:not(.select-mode) .tile-check {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.tile-check svg {
|
.tile-check svg {
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
|
|||||||
@@ -160,9 +160,12 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
|
|||||||
metaBase
|
metaBase
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTML gallery page cache time
|
// HTML gallery page cache time. A password-protected gallery keeps the
|
||||||
const cacheTime = Math.max(0, getNumericConfigOption('ipp.gallery.cacheTime', 300))
|
// no-store that handleShareRequest set.
|
||||||
res.header('Cache-Control', 'public, max-age=' + cacheTime)
|
if (!share.password) {
|
||||||
|
const cacheTime = Math.max(0, getNumericConfigOption('ipp.gallery.cacheTime', 300))
|
||||||
|
res.header('Cache-Control', 'public, max-age=' + cacheTime)
|
||||||
|
}
|
||||||
res.send(renderPage(h(Gallery, props)))
|
res.send(renderPage(h(Gallery, props)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,13 @@ export function addResponseHeaders (res: Response): void {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Stop browsers and shared caches storing a response from a password-protected share. */
|
||||||
|
export function addNoStoreHeaders (res: Response): void {
|
||||||
|
res.set('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
|
||||||
|
res.set('Pragma', 'no-cache')
|
||||||
|
res.set('Expires', '0')
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap an async route handler so a rejected promise is passed to Express's
|
* Wrap an async route handler so a rejected promise is passed to Express's
|
||||||
* error chain (and on to `errorHandler`).
|
* error chain (and on to `errorHandler`).
|
||||||
|
|||||||
+9
-9
@@ -13,7 +13,7 @@ import {
|
|||||||
} from './types'
|
} from './types'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { getConfigOption } from './config/access'
|
import { getConfigOption } from './config/access'
|
||||||
import { addResponseHeaders } from './http'
|
import { addNoStoreHeaders, addResponseHeaders } from './http'
|
||||||
import { canDownload } from './share'
|
import { canDownload } from './share'
|
||||||
import { log } from './utils/log'
|
import { log } from './utils/log'
|
||||||
import { assetBuffer } from './stream/asset'
|
import { assetBuffer } from './stream/asset'
|
||||||
@@ -162,11 +162,7 @@ export async function handleShareRequest (req: IncomingShareRequest, res: Respon
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't cache password-protected albums
|
// Don't cache password-protected albums
|
||||||
if (sharedLinkRes.passwordRequired || req.password) {
|
if (sharedLinkRes.passwordRequired || req.password) addNoStoreHeaders(res)
|
||||||
res.header('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
|
|
||||||
res.header('Pragma', 'no-cache')
|
|
||||||
res.header('Expires', '0')
|
|
||||||
}
|
|
||||||
|
|
||||||
// Password required - show the visitor the password page
|
// Password required - show the visitor the password page
|
||||||
if (sharedLinkRes.passwordRequired) {
|
if (sharedLinkRes.passwordRequired) {
|
||||||
@@ -495,14 +491,18 @@ export function fetchAssetDetail (asset: Asset): Promise<Asset | undefined> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the content-type of a video, for the lightbox <video> element
|
* Get the content-type of a video, for the lightbox <video> element. Undefined
|
||||||
|
* when Immich can't serve it, so one missing video doesn't break the share #119
|
||||||
*/
|
*/
|
||||||
export async function getVideoContentType (asset: Asset) {
|
export async function getVideoContentType (asset: Asset): Promise<string | undefined> {
|
||||||
const headers = await authHeadersForAsset(asset)
|
const headers = await authHeadersForAsset(asset)
|
||||||
const data = await request(buildUrl('/assets/' + encodeURIComponent(asset.id) + '/video/playback', {
|
const data = await request(buildUrl('/assets/' + encodeURIComponent(asset.id) + '/video/playback', {
|
||||||
[asset.keyType]: asset.key
|
[asset.keyType]: asset.key
|
||||||
}), { headers })
|
}), { headers })
|
||||||
return data.headers.get('Content-Type')
|
if (!(data instanceof globalThis.Response)) return undefined
|
||||||
|
// Only the header is needed; an unread body keeps the whole video download open
|
||||||
|
await data.body?.cancel()
|
||||||
|
return data.headers.get('Content-Type') || undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+13
-3
@@ -22,7 +22,7 @@ import { NextFunction, Request, Response } from 'express-serve-static-core'
|
|||||||
import { Asset, AssetType, ImageSize, KeyType, SharedLink } from './types'
|
import { Asset, AssetType, ImageSize, KeyType, SharedLink } from './types'
|
||||||
import { getConfigOption } from './config/access'
|
import { getConfigOption } from './config/access'
|
||||||
import { loadConfig } from './config/loader'
|
import { loadConfig } from './config/loader'
|
||||||
import { addResponseHeaders, asyncHandler, errorHandler } from './http'
|
import { addNoStoreHeaders, addResponseHeaders, asyncHandler, errorHandler } from './http'
|
||||||
import { canDownload, findMotionPhotoStill } from './share'
|
import { canDownload, findMotionPhotoStill } from './share'
|
||||||
import { toString } from './utils/text'
|
import { toString } from './utils/text'
|
||||||
import { decrypt, encrypt } from './encrypt'
|
import { decrypt, encrypt } from './encrypt'
|
||||||
@@ -104,7 +104,15 @@ type SharedAssetResolution =
|
|||||||
| { ok: true, link: SharedLink, asset: Asset }
|
| { ok: true, link: SharedLink, asset: Asset }
|
||||||
| { ok: false, status: number, reason: string, passwordRequired?: boolean }
|
| { 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> {
|
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' }
|
||||||
|
}
|
||||||
if (!isKey(req.params.key)) {
|
if (!isKey(req.params.key)) {
|
||||||
return { ok: false, status: 404, reason: 'Invalid key for ' + req.path }
|
return { ok: false, status: 404, reason: 'Invalid key for ' + req.path }
|
||||||
}
|
}
|
||||||
@@ -165,8 +173,7 @@ app.get(/^(|\/share)\/healthcheck$/, asyncHandler(async (_req, res) => {
|
|||||||
app.get('/:shareType(share|s)/:key/:mode(download)?', decodeCookie, asyncHandler(async (req, res) => {
|
app.get('/:shareType(share|s)/:key/:mode(download)?', decodeCookie, asyncHandler(async (req, res) => {
|
||||||
const keyType = getKeyTypeFromShare(req.params.shareType)
|
const keyType = getKeyTypeFromShare(req.params.shareType)
|
||||||
|
|
||||||
if (keyType === KeyType.slug && !getConfigOption('ipp.allowSlugLinks', true)) {
|
if (slugLinksDisabled(keyType)) {
|
||||||
// Slug type links are not allowed
|
|
||||||
respondToInvalidRequest(res, 404, 'Slug links are disabled in config.json')
|
respondToInvalidRequest(res, 404, 'Slug links are disabled in config.json')
|
||||||
} else {
|
} else {
|
||||||
await handleShareRequest({
|
await handleShareRequest({
|
||||||
@@ -275,6 +282,7 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, asyncHandler(
|
|||||||
respondToInvalidRequest(res, resolved.status, resolved.reason)
|
respondToInvalidRequest(res, resolved.status, resolved.reason)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (resolved.link.password) addNoStoreHeaders(res)
|
||||||
const asset: Asset = {
|
const asset: Asset = {
|
||||||
...resolved.asset,
|
...resolved.asset,
|
||||||
type: req.params.type === 'video' ? AssetType.video : resolved.asset.type
|
type: req.params.type === 'video' ? AssetType.video : resolved.asset.type
|
||||||
@@ -306,6 +314,8 @@ app.get('/:shareType(share|s)/meta/:key/:id', decodeCookie, asyncHandler(async (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (resolved.link.password) addNoStoreHeaders(res)
|
||||||
|
|
||||||
const detail = await fetchAssetDetail(resolved.asset)
|
const detail = await fetchAssetDetail(resolved.asset)
|
||||||
if (!detail) {
|
if (!detail) {
|
||||||
respondToInvalidRequest(res, 404, 'Asset detail unavailable for ' + req.params.id)
|
respondToInvalidRequest(res, 404, 'Asset detail unavailable for ' + req.params.id)
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||||
|
import { getVideoContentType } from '../src/immich'
|
||||||
|
import { Asset, AssetType, KeyType } from '../src/types'
|
||||||
|
|
||||||
|
const video: Asset = {
|
||||||
|
id: 'v1',
|
||||||
|
key: 'testkey',
|
||||||
|
keyType: KeyType.key,
|
||||||
|
type: AssetType.video,
|
||||||
|
isTrashed: false
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('getVideoContentType', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
process.env.IMMICH_URL = 'http://immich.test'
|
||||||
|
vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||||
|
})
|
||||||
|
afterEach(() => {
|
||||||
|
vi.unstubAllGlobals()
|
||||||
|
vi.restoreAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns the content-type and cancels the unread video body', async () => {
|
||||||
|
let cancelled = false
|
||||||
|
const body = new ReadableStream({
|
||||||
|
pull (controller) { controller.enqueue(new Uint8Array(1024)) },
|
||||||
|
cancel () { cancelled = true }
|
||||||
|
})
|
||||||
|
vi.stubGlobal('fetch', vi.fn(async () => new globalThis.Response(body, {
|
||||||
|
status: 200,
|
||||||
|
headers: { 'content-type': 'video/mp4' }
|
||||||
|
})))
|
||||||
|
expect(await getVideoContentType(video)).toBe('video/mp4')
|
||||||
|
expect(cancelled).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns undefined when Immich cannot serve the video #119', async () => {
|
||||||
|
vi.stubGlobal('fetch', vi.fn(async () => new globalThis.Response('{"message":"Not found"}', { status: 404 })))
|
||||||
|
expect(await getVideoContentType(video)).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns undefined when Immich is unreachable', async () => {
|
||||||
|
vi.stubGlobal('fetch', vi.fn(async () => { throw new TypeError('fetch failed') }))
|
||||||
|
expect(await getVideoContentType(video)).toBeUndefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -36,6 +36,29 @@ environment:
|
|||||||
If you serve IPP from several domains, leave it unset and make sure your reverse proxy forwards the original `Host`
|
If you serve IPP from several domains, leave it unset and make sure your reverse proxy forwards the original `Host`
|
||||||
header. See [Running on a single domain](/running-on-single-domain).
|
header. See [Running on a single domain](/running-on-single-domain).
|
||||||
|
|
||||||
|
## Container won't start after mounting `config.json`
|
||||||
|
|
||||||
|
Docker refuses to start the container, with an error that ends:
|
||||||
|
|
||||||
|
```
|
||||||
|
Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
|
||||||
|
```
|
||||||
|
|
||||||
|
The file on the left of the volume line doesn't exist. When the source of a bind mount is missing, Docker creates an
|
||||||
|
empty directory in its place, and a directory can't be mounted over the `config.json` file inside the image.
|
||||||
|
|
||||||
|
Check that your `config.json` is at that path. A relative path such as `./config.json` resolves from the folder that
|
||||||
|
holds `docker-compose.yml`. A Portainer stack resolves it inside Portainer's own data folder instead, so use an
|
||||||
|
absolute path there:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
volumes:
|
||||||
|
- /opt/immich-public-proxy/config.json:/app/config.json:ro
|
||||||
|
```
|
||||||
|
|
||||||
|
Delete the empty directory Docker created, then recreate the container. See
|
||||||
|
[#83](https://github.com/alangrainger/immich-public-proxy/issues/83).
|
||||||
|
|
||||||
## Can't reach Immich using `localhost:2283`
|
## Can't reach Immich using `localhost:2283`
|
||||||
|
|
||||||
This is a normal Docker thing, nothing to do with IPP.
|
This is a normal Docker thing, nothing to do with IPP.
|
||||||
|
|||||||
Reference in New Issue
Block a user