Merge branch 'pr-264' into #264-show-expiry
# Conflicts: # docs/configuration.md
This commit is contained in:
@@ -42,6 +42,8 @@
|
||||
"singleItemAutoOpen": true,
|
||||
"showTitle": true,
|
||||
"showDescription": false,
|
||||
"showExpiryDate": false,
|
||||
"expiryDateFormat": "YYYY-MM-DD",
|
||||
"groupByDate": false,
|
||||
"cacheTime": 300
|
||||
},
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
import { Response } from 'express-serve-static-core'
|
||||
import { AssetType, ImageSize, SharedLink } from '../types'
|
||||
import { getConfigOption } from '../config/access'
|
||||
import { canDownload, title } from '../share'
|
||||
import { canDownload, expiryDate, title } from '../share'
|
||||
import { toString } from '../utils/text'
|
||||
import { h } from 'preact'
|
||||
import { renderPage } from '../view/render'
|
||||
@@ -142,6 +142,7 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
|
||||
path: '/share/' + share.key,
|
||||
showDownload: downloadAllowed,
|
||||
showTitle: !!getConfigOption('ipp.gallery.showTitle', true),
|
||||
expiryDate: expiryDate(share),
|
||||
openItem,
|
||||
ogImageItem,
|
||||
lightboxConfig: {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { DownloadAll, SharedLink } from './types'
|
||||
import { getConfigOption } from './config/access'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
/**
|
||||
* Display title for a shared link. Prefers the user-set link description,
|
||||
@@ -31,3 +32,21 @@ export function canDownload (share: SharedLink): boolean {
|
||||
return !!share.allowDownload
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formatted expiry date for the gallery subtitle, or undefined when the
|
||||
* feature is off, the share never expires, or the date can't be parsed.
|
||||
*
|
||||
* Gated by `ipp.gallery.showExpiryDate` (default `false`). The date is
|
||||
* formatted with `ipp.gallery.expiryDateFormat`, a dayjs format string that
|
||||
* defaults to the ISO 8601 date `YYYY-MM-DD` (e.g. `2026-07-10`).
|
||||
*/
|
||||
export function expiryDate (share: SharedLink): string | undefined {
|
||||
if (!getConfigOption('ipp.gallery.showExpiryDate', false)) return undefined
|
||||
if (!share.expiresAt) return undefined
|
||||
const parsed = dayjs(share.expiresAt)
|
||||
if (!parsed.isValid()) return undefined
|
||||
const configured = getConfigOption('ipp.gallery.expiryDateFormat', 'YYYY-MM-DD')
|
||||
const format = typeof configured === 'string' && configured ? configured : 'YYYY-MM-DD'
|
||||
return parsed.format(format)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ export interface GalleryProps {
|
||||
path: string
|
||||
showDownload: boolean
|
||||
showTitle: boolean
|
||||
// Formatted "available until" date shown in the subtitle, or undefined when
|
||||
// ipp.gallery.showExpiryDate is off or the share never expires.
|
||||
expiryDate?: string
|
||||
openItem?: number
|
||||
ogImageItem?: GalleryItem
|
||||
lightboxConfig: LightboxConfig
|
||||
@@ -71,6 +74,9 @@ export function Gallery (props: GalleryProps) {
|
||||
<p class="subtitle">
|
||||
{props.items.length}{' '}
|
||||
{props.items.length === 1 ? 'item' : 'items'}
|
||||
{props.expiryDate && (
|
||||
<>{' · available until '}{props.expiryDate}</>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import dayjs from 'dayjs'
|
||||
import { expiryDate } from '../src/share'
|
||||
import { loadConfig } from '../src/config/loader'
|
||||
import { KeyType, SharedLink } from '../src/types'
|
||||
|
||||
// expiryDate formats the share's Immich expiry for the gallery subtitle. It is
|
||||
// gated behind ipp.gallery.showExpiryDate (default off) and formatted with
|
||||
// ipp.gallery.expiryDateFormat (a dayjs format string, default ISO 8601 date).
|
||||
|
||||
function setConfig (config: unknown) {
|
||||
process.env.CONFIG = JSON.stringify(config)
|
||||
loadConfig()
|
||||
}
|
||||
|
||||
const share = (expiresAt: string | null): SharedLink => ({
|
||||
key: 'k',
|
||||
keyType: KeyType.key,
|
||||
type: 'ALBUM',
|
||||
assets: [],
|
||||
expiresAt
|
||||
})
|
||||
|
||||
const EXPIRES = '2026-07-10T12:00:00.000Z'
|
||||
|
||||
describe('expiryDate', () => {
|
||||
beforeEach(() => {
|
||||
delete process.env.CONFIG
|
||||
loadConfig()
|
||||
})
|
||||
|
||||
it('returns undefined when the feature is off (default)', () => {
|
||||
setConfig({})
|
||||
expect(expiryDate(share(EXPIRES))).toBeUndefined()
|
||||
})
|
||||
|
||||
it('returns undefined when the share never expires, even if enabled', () => {
|
||||
setConfig({ ipp: { gallery: { showExpiryDate: true } } })
|
||||
expect(expiryDate(share(null))).toBeUndefined()
|
||||
})
|
||||
|
||||
it('formats as an ISO 8601 date by default when enabled', () => {
|
||||
setConfig({ ipp: { gallery: { showExpiryDate: true } } })
|
||||
expect(expiryDate(share(EXPIRES))).toBe(dayjs(EXPIRES).format('YYYY-MM-DD'))
|
||||
})
|
||||
|
||||
it('honours a custom dayjs format string', () => {
|
||||
setConfig({ ipp: { gallery: { showExpiryDate: true, expiryDateFormat: 'D MMMM YYYY' } } })
|
||||
expect(expiryDate(share(EXPIRES))).toBe(dayjs(EXPIRES).format('D MMMM YYYY'))
|
||||
})
|
||||
|
||||
it('falls back to the default format when the config value is not a usable string', () => {
|
||||
setConfig({ ipp: { gallery: { showExpiryDate: true, expiryDateFormat: '' } } })
|
||||
expect(expiryDate(share(EXPIRES))).toBe(dayjs(EXPIRES).format('YYYY-MM-DD'))
|
||||
})
|
||||
|
||||
it('returns undefined for an unparseable expiry date', () => {
|
||||
setConfig({ ipp: { gallery: { showExpiryDate: true } } })
|
||||
expect(expiryDate(share('not-a-date'))).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -84,6 +84,8 @@ Options that control how the gallery page is rendered. Configured under `ipp.gal
|
||||
| `singleItemAutoOpen` | `bool` | When a share contains a single item and is opened on its gallery page, automatically open the lightbox on the asset. Default `true`. |
|
||||
| `showTitle` | `bool` | Show a title on the gallery page. This is taken from the album title if it is an album being shared, otherwise the "Description" from the shared link will be used. |
|
||||
| `showDescription` | `bool` | Show the album description below the title. This only applies if it is an album which is being shared. |
|
||||
| `showExpiryDate` | `bool` | Show the share's expiry date next to the item count in the subtitle, as `45 items · available until 2026-07-10`. Only appears when the share actually has an expiry set in Immich (shares set to "never" show nothing extra). Default `false`. |
|
||||
| `expiryDateFormat` | `string` | Format for the `showExpiryDate` date, as a [dayjs format string](https://day.js.org/docs/en/display/format). Default `"YYYY-MM-DD"` (ISO 8601 date, e.g. `2026-07-10`). Example: `"D MMMM YYYY"` renders `10 July 2026`. |
|
||||
| `groupByDate` | `bool` or `string` | Group the gallery's thumbnails by date, with a header above each group. Set to `false` (default, no grouping), `true` / `"month"` for month headers like "December 2024", or `"day"` for day headers like "25 December 2024". Grouping uses each photo's local "taken" date (matching Immich's own timeline), and sorts photos newest-first. Items missing a creation date end up under an "Undated" bucket at the end (or render without any header when the whole gallery is undated). **Requires "Show metadata" to be enabled on the share in Immich** - when that's off, Immich strips creation dates from the assets it returns to IPP, so grouping won't work. |
|
||||
| `cacheTime` | `int` | How long (in seconds) browsers and any CDN may cache the gallery **page** before revalidating. Set this longer to reduce load on your server, but be aware that if you add new photos to a gallery they won't show up until the cache times out or you manually clear any downstream caches. |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user