feat: add option to display expiry date

This commit is contained in:
lukasganster
2026-07-07 17:16:44 +02:00
parent 02791c9817
commit 056615f9da
4 changed files with 29 additions and 1 deletions
+2
View File
@@ -42,6 +42,8 @@
"singleItemAutoOpen": true, "singleItemAutoOpen": true,
"showTitle": true, "showTitle": true,
"showDescription": false, "showDescription": false,
"showExpiryDate": false,
"expiryDateFormat": "YYYY-MM-DD",
"groupByDate": false, "groupByDate": false,
"cacheTime": 300 "cacheTime": 300
}, },
+2 -1
View File
@@ -6,7 +6,7 @@ import {
import { Response } from 'express-serve-static-core' import { Response } from 'express-serve-static-core'
import { AssetType, ImageSize, SharedLink } from '../types' import { AssetType, ImageSize, SharedLink } from '../types'
import { getConfigOption } from '../config/access' import { getConfigOption } from '../config/access'
import { canDownload, title } from '../share' import { canDownload, expiryDate, title } from '../share'
import { toString } from '../utils/text' import { toString } from '../utils/text'
import { h } from 'preact' import { h } from 'preact'
import { renderPage } from '../view/render' import { renderPage } from '../view/render'
@@ -138,6 +138,7 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
path: '/share/' + share.key, path: '/share/' + share.key,
showDownload: downloadAllowed, showDownload: downloadAllowed,
showTitle: !!getConfigOption('ipp.gallery.showTitle', true), showTitle: !!getConfigOption('ipp.gallery.showTitle', true),
expiryDate: expiryDate(share),
openItem, openItem,
ogImageItem, ogImageItem,
lightboxConfig: { lightboxConfig: {
+19
View File
@@ -1,5 +1,6 @@
import { DownloadAll, SharedLink } from './types' import { DownloadAll, SharedLink } from './types'
import { getConfigOption } from './config/access' import { getConfigOption } from './config/access'
import dayjs from 'dayjs'
/** /**
* Display title for a shared link. Prefers the user-set link description, * 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 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)
}
+6
View File
@@ -13,6 +13,9 @@ export interface GalleryProps {
path: string path: string
showDownload: boolean showDownload: boolean
showTitle: 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 openItem?: number
ogImageItem?: GalleryItem ogImageItem?: GalleryItem
lightboxConfig: LightboxConfig lightboxConfig: LightboxConfig
@@ -71,6 +74,9 @@ export function Gallery (props: GalleryProps) {
<p class="subtitle"> <p class="subtitle">
{props.items.length}{' '} {props.items.length}{' '}
{props.items.length === 1 ? 'item' : 'items'} {props.items.length === 1 ? 'item' : 'items'}
{props.expiryDate && (
<>{' · available until '}{props.expiryDate}</>
)}
</p> </p>
</div> </div>
)} )}