WIP
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
"motionPhotos": true,
|
||||
"downloadedFilename": 0,
|
||||
"allowDownload": 0,
|
||||
"uploadUrl": "",
|
||||
"allowSlugLinks": true,
|
||||
"showHomePage": true,
|
||||
"showMetadata": {
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from '../immich'
|
||||
import { Response } from 'express-serve-static-core'
|
||||
import { ImageSize } from '../types'
|
||||
import { canDownload, expiryDate } from '../share'
|
||||
import { canDownload, expiryDate, uploadLink } from '../share'
|
||||
import { h } from 'preact'
|
||||
import { Gallery, GalleryItem, GalleryProps } from '../view/gallery'
|
||||
import type { GroupByDateMode } from '../shared/types'
|
||||
@@ -155,7 +155,8 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
|
||||
locationWebLink: !!getConfigOption('ipp.showMetadata.location.webLink', true)
|
||||
},
|
||||
groupByDate,
|
||||
metaBase
|
||||
metaBase,
|
||||
uploadLink: uploadLink(share)
|
||||
}
|
||||
|
||||
// HTML gallery page cache time. A password-protected gallery keeps the
|
||||
|
||||
+16
-1
@@ -1,4 +1,4 @@
|
||||
import { Asset, getConfigOption, log, SharedLink, TtlLruCache } from '@ipp/core'
|
||||
import { Asset, getConfigOption, KeyType, log, SharedLink, TtlLruCache } from '@ipp/core'
|
||||
import { DownloadAll } from './types'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
@@ -22,6 +22,21 @@ export function canDownload (share: SharedLink): boolean {
|
||||
|
||||
let warnedInvalidDownloadPolicy = false
|
||||
|
||||
/**
|
||||
* The "Add photos" link to this share on the upload service, or undefined
|
||||
* when `ipp.uploadUrl` is unset or not an http(s) URL, or the owner has not
|
||||
* turned on "Allow public user to upload". A share opened by its slug links
|
||||
* by its slug, so the upload service resolves it the same way.
|
||||
*/
|
||||
export function uploadLink (share: SharedLink): string | undefined {
|
||||
const configured = getConfigOption('ipp.uploadUrl', '')
|
||||
if (!share.allowUpload || typeof configured !== 'string' || !/^https?:\/\//i.test(configured.trim())) return undefined
|
||||
const base = configured.trim().replace(/\/+$/, '')
|
||||
return share.keyType === KeyType.slug && share.slug
|
||||
? base + '/s/' + encodeURIComponent(share.slug)
|
||||
: base + '/share/' + encodeURIComponent(share.key)
|
||||
}
|
||||
|
||||
// Asset ids already warned about, so each warns at most once a day
|
||||
const warnedUnprocessed = new TtlLruCache<true>({ ttlMs: 24 * 60 * 60_000, max: 1000 })
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ export interface GalleryProps {
|
||||
metadataConfig: MetadataConfig
|
||||
groupByDate: GroupByDateMode | false
|
||||
metaBase?: string
|
||||
// The upload service's page for this share, when it accepts uploads
|
||||
uploadLink?: string
|
||||
}
|
||||
|
||||
export function Gallery (props: GalleryProps) {
|
||||
@@ -69,7 +71,7 @@ export function Gallery (props: GalleryProps) {
|
||||
<link type="text/css" rel="stylesheet" href={`/share/static/${ASSET_VERSION}/photoswipe-overrides.css`}/>
|
||||
</head>
|
||||
<body>
|
||||
{(showHeaderText || props.showDownloadZip) && (
|
||||
{(showHeaderText || props.showDownloadZip || props.uploadLink) && (
|
||||
<header id="header">
|
||||
{showHeaderText && (
|
||||
<div class="header-text">
|
||||
@@ -83,13 +85,22 @@ export function Gallery (props: GalleryProps) {
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
{props.showDownloadZip && (
|
||||
<a id="download-all" class="header-action" href={props.path + '/download'} title="Download all" aria-label="Download all">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path fill="currentColor" d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"/>
|
||||
</svg>
|
||||
</a>
|
||||
)}
|
||||
<div class="header-actions">
|
||||
{props.uploadLink && (
|
||||
<a id="upload-link" class="header-action" href={props.uploadLink} title="Add photos" aria-label="Add photos">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path fill="currentColor" d="M7 19L12 14L13.88 15.88C13.33 16.79 13 17.86 13 19H7M10 10.5C10 9.67 9.33 9 8.5 9S7 9.67 7 10.5 7.67 12 8.5 12 10 11.33 10 10.5M13.09 20H6V4H13V9H18V13.09C18.33 13.04 18.66 13 19 13C19.34 13 19.67 13.04 20 13.09V8L14 2H6C4.89 2 4 2.9 4 4V20C4 21.11 4.89 22 6 22H13.81C13.46 21.39 13.21 20.72 13.09 20M18 15V18H15V20H18V23H20V20H23V18H20V15H18Z"/>
|
||||
</svg>
|
||||
</a>
|
||||
)}
|
||||
{props.showDownloadZip && (
|
||||
<a id="download-all" class="header-action" href={props.path + '/download'} title="Download all" aria-label="Download all">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path fill="currentColor" d="M5,20H19V18H5M19,9H15V3H9V9H5L12,16L19,9Z"/>
|
||||
</svg>
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
)}
|
||||
{props.description && (
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { KeyType, loadConfig, SharedLink } from '@ipp/core'
|
||||
import { uploadLink } from '../src/share'
|
||||
|
||||
function setConfig (config: unknown) {
|
||||
process.env.CONFIG = JSON.stringify(config)
|
||||
loadConfig()
|
||||
}
|
||||
|
||||
const share = (overrides: Partial<SharedLink> = {}): SharedLink => ({
|
||||
key: 'the-key',
|
||||
keyType: KeyType.key,
|
||||
type: 'ALBUM',
|
||||
assets: [],
|
||||
expiresAt: null,
|
||||
allowUpload: true,
|
||||
...overrides
|
||||
})
|
||||
|
||||
describe('uploadLink', () => {
|
||||
beforeEach(() => {
|
||||
delete process.env.CONFIG
|
||||
loadConfig()
|
||||
})
|
||||
|
||||
it('is absent while ipp.uploadUrl is unset', () => {
|
||||
expect(uploadLink(share())).toBeUndefined()
|
||||
})
|
||||
|
||||
it('links a key share by its key, without a doubled slash', () => {
|
||||
setConfig({ ipp: { uploadUrl: 'https://upload.example.com/' } })
|
||||
expect(uploadLink(share())).toBe('https://upload.example.com/share/the-key')
|
||||
})
|
||||
|
||||
it('links a share opened by its slug by that slug', () => {
|
||||
setConfig({ ipp: { uploadUrl: 'https://photos.example.com/upload' } })
|
||||
expect(uploadLink(share({ keyType: KeyType.slug, slug: 'holiday 2025' }))).toBe('https://photos.example.com/upload/s/holiday%202025')
|
||||
})
|
||||
|
||||
it('is absent when the owner has not allowed uploads', () => {
|
||||
setConfig({ ipp: { uploadUrl: 'https://upload.example.com' } })
|
||||
expect(uploadLink(share({ allowUpload: false }))).toBeUndefined()
|
||||
expect(uploadLink(share({ allowUpload: undefined }))).toBeUndefined()
|
||||
})
|
||||
|
||||
it('ignores a value that is not an http(s) URL', () => {
|
||||
setConfig({ ipp: { uploadUrl: 'javascript:alert(1)' } })
|
||||
expect(uploadLink(share())).toBeUndefined()
|
||||
setConfig({ ipp: { uploadUrl: 42 } })
|
||||
expect(uploadLink(share())).toBeUndefined()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user