From a620d0b3ae71dfc6e3ec0d823568b5caef443d61 Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Mon, 19 Oct 2026 15:43:29 +1300 Subject: [PATCH] #302 add name field for uploads --- app/package.json | 1 + docs/config/upload-service.md | 25 +++++++++++++-- docs/tag-and-review-uploads.md | 32 ++++++++++++++++++- docs/visitor-uploads.md | 7 ++++- package.json | 3 +- upload-app/config.json | 1 + upload-app/package.json | 1 + upload-app/public/style.css | 27 ++++++++++++++++ upload-app/src/client/upload.ts | 22 +++++++++++++ upload-app/src/config.ts | 5 +++ upload-app/src/filename.ts | 52 ++++++++++++++++++++++++++----- upload-app/src/index.ts | 5 +-- upload-app/src/notify.ts | 11 +++++-- upload-app/src/receive.ts | 12 ++++--- upload-app/src/shared/upload.ts | 2 ++ upload-app/src/view/upload.tsx | 6 ++++ upload-app/tests/config.test.ts | 10 +++++- upload-app/tests/filename.test.ts | 50 ++++++++++++++++++++++++++++- upload-app/tests/notify.test.ts | 9 ++++++ 19 files changed, 257 insertions(+), 24 deletions(-) diff --git a/app/package.json b/app/package.json index 7fb7b3f..b166fc4 100644 --- a/app/package.json +++ b/app/package.json @@ -4,6 +4,7 @@ "scripts": { "predev": "tsc -b ../shared", "dev": "concurrently -n core,server,client -c magenta,blue,green \"tsc -b -w --preserveWatchOutput ../shared\" \"tsx watch src/index.ts\" \"tsc -w -p tsconfig.client.json\"", + "dev:app": "concurrently -n server,client -c blue,green \"tsx watch src/index.ts\" \"tsc -w -p tsconfig.client.json\"", "build": "tsc -b && tsc -p tsconfig.client.json", "build:server": "tsc -b", "build:client": "tsc -p tsconfig.client.json", diff --git a/docs/config/upload-service.md b/docs/config/upload-service.md index ea4afee..8a68d66 100644 --- a/docs/config/upload-service.md +++ b/docs/config/upload-service.md @@ -98,6 +98,22 @@ Set it to `""` to hide it. The text is shown exactly as written, without HTML or links, so you can translate it into your gallery's language. The reason for the delay is explained in [When do uploads appear](/visitor-uploads#when-do-uploads-appear). +### `askName` + +**Type:** `bool` · **Default:** `true` + +Whether the upload page has an optional "Your name" field. The name goes into each stored filename between the prefix +and the original name, followed by a comma, so `IMG_0042.jpg` from Jane Smith is stored as +`ipp_upload_jane-smith,IMG_0042.jpg`. A file sent without a name is stored as `ipp_upload_IMG_0042.jpg`, with no +comma. The visitor's browser remembers the name for the next share on the same install. With `false`, the field is +not shown and a name sent anyway is ignored. + +The name is stored as a slug: lower case, letters and digits in any script, and a hyphen for anything else, at most 32 +characters. A comma in the visitor's own filename is removed, so the comma always marks the end of the name. A +filename that already carries the prefix gets neither the prefix nor the name again. The name is the visitor's own +claim; IPP cannot check it. For what to do with it, see +[Find each visitor's uploads](/tag-and-review-uploads#find-each-visitors-uploads). + ### `notifyUrl` **Type:** `string` · **Default:** `""` @@ -111,13 +127,14 @@ token in the URL never reaches the log. ```json { "title": "Photo sent to Holiday 2025", - "message": "ipp_upload_IMG_0042.jpg (3.0 MB) was uploaded to Holiday 2025.", + "message": "ipp_upload_jane-smith,IMG_0042.jpg (3.0 MB) was uploaded to Holiday 2025 by jane-smith.", "data": { "event": "upload", "time": "2026-10-05T07:18:00.000Z", "share": { "type": "album", "id": "9f1c…", "title": "Holiday 2025" }, - "file": { "name": "ipp_upload_IMG_0042.jpg", "size": 3145728, "type": "image/jpeg" }, - "asset": { "id": "4b2e…", "status": "created" } + "file": { "name": "ipp_upload_jane-smith,IMG_0042.jpg", "size": 3145728, "type": "image/jpeg" }, + "asset": { "id": "4b2e…", "status": "created" }, + "uploader": "jane-smith" } } ``` @@ -126,6 +143,8 @@ token in the URL never reaches the log. album ID or the shared link ID. - `asset.status` is `created`, or `duplicate` when the owner already had the same file. Immich adds a duplicate to the share too. +- `uploader` is the visitor's name as it appears in the filename, or `""` when the visitor gave none or + [`askName`](#askname) is off. - The body never contains the share key, the custom URL or a password. ntfy reads the two fields through its inline templates: diff --git a/docs/tag-and-review-uploads.md b/docs/tag-and-review-uploads.md index f365f20..7bf371b 100644 --- a/docs/tag-and-review-uploads.md +++ b/docs/tag-and-review-uploads.md @@ -22,7 +22,37 @@ IPP talks to Immich with the visitor's share key and nothing else. Immich lets a store a file into the share. Every tag endpoint needs an API key with tag permissions. The upload service holds no API key, and giving one to a service that faces the public would let that service change your library. -There are some other options under discussion in [GitHub discussion #302](https://github.com/alangrainger/immich-public-proxy/discussions/302). Feedback is welcome. +A sidecar file could carry a tag without an API key, but Immich reads a sidecar's keywords in place of the +photo's own, so a visitor's existing keywords would be lost. The filename keeps the photo's metadata untouched. + +## Find each visitor's uploads + +The upload page asks each visitor for their name (see [`upload.askName`](/config/upload-service#askname)). A name +given is stored in the filename between the prefix and the original name, with a comma after it, as +`ipp_upload_jane-smith,IMG_0042.jpg`. So in Immich: + +- Search for `ipp_upload_jane-smith,` to see everything Jane sent. +- Add a workflow per visitor to tag or sort their uploads: **Filter by filename**, match type `startsWith`, pattern + `ipp_upload_jane-smith,`, then **Add Tags** with a tag such as `Uploaded/Jane Smith`. + +The comma matters: without it, `ipp_upload_jane` would also match `jane-smith` and `janet`. The name is whatever the +visitor typed, made lower case with hyphens for spaces and punctuation. A visitor who leaves the field empty is stored +with the prefix alone and no comma. A visitor can type any name, so treat it as a label, not proof. + +### Why a comma + +The filename is ``, where each field is followed by a comma. The separator had to be one +that a visitor's own filename never keeps, so that a stem with no comma has no fields, and otherwise the last comma +ends them. An underscore cannot do that: `ipp_upload_photo_1.jpg` would read as a visitor called `photo`. A tilde +was ruled out because Android names an edited photo `IMG_1234~2.jpg`. A comma is typeable, legal on every file +system, never written by a camera or a phone, and only rarely by a person. When a visitor's filename does contain +one, it is removed. + +The fields are positional so that more can be added later, such as an event code the owner hands out. A new field +goes on the end, an empty one is written empty, and a file with no fields at all has no comma. So a future +`ipp_upload_jane-smith,34,IMG_0042.jpg` and `ipp_upload_,34,IMG_0042.jpg` would sit beside today's names, and a +script that splits on the comma reads all of them: the last piece is the original filename, the rest are the fields +in order. ## Review uploads before they appear diff --git a/docs/visitor-uploads.md b/docs/visitor-uploads.md index 3b7166a..57b0ce6 100644 --- a/docs/visitor-uploads.md +++ b/docs/visitor-uploads.md @@ -47,6 +47,10 @@ What the owner sees in Immich: - Each file name starts with `ipp_upload_`, so visitor uploads are easy to find in search or to [tag with a workflow](/tag-and-review-uploads#tag-uploaded-photos). The prefix can be changed or [turned off](/config/upload-service#filenameprefix). +- The upload page asks for the visitor's name, optionally. A name given is stored in the filename after the prefix, + as `ipp_upload_jane-smith,IMG_0042.jpg`, so you can see who sent what and + [find each visitor's uploads](/tag-and-review-uploads#find-each-visitors-uploads). The field can be + [turned off](/config/upload-service#askname). - The owner removes unwanted files in Immich, like any other photo. Other visitors see the new photos in the gallery within a few minutes. See @@ -344,7 +348,8 @@ they reach the gallery, use a [review workflow](/tag-and-review-uploads#review-u ### Can visitors see who uploaded what, or remove photos No. The upload page shows nothing from the share, only the visitor's own uploads in progress, and nothing can be -deleted or edited from it. The owner manages uploads in Immich. +deleted or edited from it. The owner manages uploads in Immich. The name a visitor types is stored in the filename +for the owner, and is not shown to other visitors. ### Why is uploading a separate container diff --git a/package.json b/package.json index a03cfad..cfb0a5b 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "build": "npm run build --workspaces", "test": "npm test --workspaces && vitest run --root docs", "lint": "eslint shared app upload-app --ext .ts,.tsx", - "dev": "npm run dev --workspace=app", + "predev": "tsc -b shared", + "dev": "concurrently -n core,ipp,upload -c magenta,blue,green \"tsc -b -w --preserveWatchOutput shared\" \"npm run dev:app --workspace=app\" \"npm run dev:app --workspace=upload-app\"", "bump": "npm version --no-git-tag-version --workspaces" } } diff --git a/upload-app/config.json b/upload-app/config.json index 9bde8a3..daf1e17 100644 --- a/upload-app/config.json +++ b/upload-app/config.json @@ -8,6 +8,7 @@ "byteBudget": 10240, "filenamePrefix": "ipp_upload_", "notice": "Uploaded photos may not appear in the gallery immediately.", + "askName": true, "notifyUrl": "", "notifyHeaders": {}, "notifyTimeout": 10000 diff --git a/upload-app/package.json b/upload-app/package.json index 9427de2..c408a85 100644 --- a/upload-app/package.json +++ b/upload-app/package.json @@ -5,6 +5,7 @@ "scripts": { "predev": "tsc -b ../shared", "dev": "concurrently -n core,server,client -c magenta,blue,green \"tsc -b -w --preserveWatchOutput ../shared\" \"tsx watch src/index.ts\" \"tsc -w -p tsconfig.client.json\"", + "dev:app": "concurrently -n server,client -c blue,green \"tsx watch src/index.ts\" \"tsc -w -p tsconfig.client.json\"", "build": "tsc -b && tsc -p tsconfig.client.json", "test": "vitest run", "test:watch": "vitest", diff --git a/upload-app/public/style.css b/upload-app/public/style.css index 17a2d25..caa83ce 100644 --- a/upload-app/public/style.css +++ b/upload-app/public/style.css @@ -71,6 +71,33 @@ html.dark .upload-placeholder:focus-visible { opacity: 0.7; } +/* The optional name field, when ipp.upload.askName is on */ +.upload-name { + display: flex; + flex-direction: column; + gap: 6px; + font-size: 14px; +} + +.upload-name-label { + font-weight: 500; +} + +.upload-name input { + font: inherit; + font-size: 16px; + padding: 10px 12px; + border: 1px solid color-mix(in srgb, var(--color-fg) 20%, transparent); + border-radius: 8px; + background: var(--color-subtle); + color: var(--color-fg); +} + +.upload-name input:focus-visible { + outline: 2px solid var(--color-primary); + outline-offset: 1px; +} + /* The owner's notice, from ipp.upload.notice */ .upload-notice { margin: -8px 0 0; diff --git a/upload-app/src/client/upload.ts b/upload-app/src/client/upload.ts index 3a118f0..d1a5aae 100644 --- a/upload-app/src/client/upload.ts +++ b/upload-app/src/client/upload.ts @@ -29,6 +29,7 @@ const MAX_RETRY_WAIT_MS = 60_000 const config = JSON.parse(document.getElementById('upload-init')?.textContent || '{}') as UploadPageConfig const run = createLimiter(CONCURRENT_UPLOADS) +const nameEl = document.getElementById('upload-name') as HTMLInputElement | null const panelEl = document.getElementById('upload-panel') as HTMLElement const progressEl = document.getElementById('upload-progress') as HTMLElement const countsEl = document.getElementById('upload-counts') as HTMLElement @@ -217,6 +218,9 @@ function attempt (row: UploadRow, attemptNumber: number): Promise { return new Promise(resolve => { const timestamp = new Date(row.file.lastModified || Date.now()).toISOString() const query = new URLSearchParams({ filename: row.file.name, fileCreatedAt: timestamp, fileModifiedAt: timestamp }) + // Read when the file is sent, so a name typed after choosing the files still counts + const uploader = nameEl?.value.trim() + if (uploader) query.set('uploader', uploader) const xhr = new XMLHttpRequest() row.xhr = xhr const started = Date.now() @@ -361,6 +365,24 @@ function setupDragAndDrop () { }) } +/* + Remember the visitor's name across shares. One origin serves every share on + an install, so the name typed for one gallery is offered for the next. The + storage may be unavailable, as in a private window, and the field then works + for this visit only. +*/ +const NAME_KEY = 'ipp-uploader-name' +if (nameEl) { + try { + nameEl.value = localStorage.getItem(NAME_KEY) || '' + } catch { } + nameEl.addEventListener('change', () => { + try { + localStorage.setItem(NAME_KEY, nameEl.value.trim()) + } catch { } + }) +} + const input = document.getElementById('upload-input') as HTMLInputElement document.getElementById('upload-choose')?.addEventListener('click', () => input.click()) input.addEventListener('change', () => { diff --git a/upload-app/src/config.ts b/upload-app/src/config.ts index ed5b6e7..2ad1774 100644 --- a/upload-app/src/config.ts +++ b/upload-app/src/config.ts @@ -32,6 +32,11 @@ export function filenamePrefix (): string { return typeof configured === 'string' ? configured : '' } +/** Whether the upload page asks the visitor's name, from `ipp.upload.askName`. */ +export function askName (): boolean { + return getConfigOption('ipp.upload.askName', true) !== false +} + /** Text shown under the placeholder on the upload page, from `ipp.upload.notice`. Empty hides it. */ export function uploadNotice (): string { const configured = getConfigOption('ipp.upload.notice', 'Uploaded photos may not appear in the gallery immediately.') diff --git a/upload-app/src/filename.ts b/upload-app/src/filename.ts index 22646d4..28a64b2 100644 --- a/upload-app/src/filename.ts +++ b/upload-app/src/filename.ts @@ -9,13 +9,49 @@ const MAX_FILENAME_LENGTH = 254 */ const formatCharsRe = /[\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]/g +const MAX_UPLOADER_LENGTH = 32 + +/* + A stored name is `
`. The header is the visitor + fields, each a slug, each followed by a comma: `ipp_upload_jane-smith,IMG_0042.jpg`. + Fields are positional, so a field added later goes on the end and an empty + one is written empty: `ipp_upload_,34,IMG_0042.jpg`. When every field is + empty there is no header at all, and the name is as it was before fields + existed. The visitor's own filename never keeps a comma, so a stem with no + comma has no fields and otherwise the last comma ends the header. +*/ +const FIELD_SEPARATOR = ',' + +/** + * The visitor's name as a filename slug: lower case, letters and digits in any + * script, runs of anything else become one hyphen. Empty when nothing usable + * is left. A slug never contains the field separator. + */ +export function uploaderSlug (raw: unknown): string { + if (typeof raw !== 'string') return '' + return raw.normalize('NFC') + .replace(formatCharsRe, '') + .toLowerCase() + .replace(/[^\p{L}\p{N}]+/gu, '-') + .replace(/^-+|-+$/g, '') + .slice(0, MAX_UPLOADER_LENGTH) + .replace(/-+$/, '') +} + +/** The header for these fields, in order, or empty when none has a value. */ +function fieldHeader (fields: string[]): string { + if (!fields.some(Boolean)) return '' + return fields.map(field => field + FIELD_SEPARATOR).join('') +} + /** * Turn the visitor-supplied filename into the name Immich will store, with - * `prefix` applied once. Returns undefined when nothing usable is left, or - * when there is no extension: Immich types an asset by its extension and - * would refuse it. + * `prefix` applied once and the uploader's slug after it, as + * `ipp_upload_jane-smith,IMG_0042.jpg`. Returns undefined when nothing usable + * is left, or when there is no extension: Immich types an asset by its + * extension and would refuse it. */ -export function uploadFilename (raw: unknown, prefix: string): string | undefined { +export function uploadFilename (raw: unknown, prefix: string, uploader = ''): string | undefined { if (typeof raw !== 'string') return undefined const base = (raw.normalize('NFC').replace(formatCharsRe, '').split(/[\\/]/).pop() || '') // Split the extension off first: `sanitize` truncates at 254 characters, @@ -23,13 +59,15 @@ export function uploadFilename (raw: unknown, prefix: string): string | undefine const parts = base.match(/^(.*)(\.[A-Za-z0-9]{1,16})$/) if (!parts) return undefined const extension = parts[2] - const stem = sanitize(parts[1]).trim() + // The separator is removed from the visitor's name so it only ever marks a field + const stem = sanitize(parts[1]).split(FIELD_SEPARATOR).join('').trim() // An empty stem is a dotfile; a leading dot is a traversal remnant. if (!stem || stem.startsWith('.')) return undefined const cleanPrefix = sanitize(prefix).trim() - // Don't stack the prefix on a file that already carries it - const wanted = stem.startsWith(cleanPrefix) ? '' : cleanPrefix + // Don't stack the prefix, or the name, on a file that already carries the prefix + const hasPrefix = cleanPrefix !== '' && stem.startsWith(cleanPrefix) + const wanted = hasPrefix ? '' : cleanPrefix + fieldHeader([uploader]) const room = MAX_FILENAME_LENGTH - wanted.length - extension.length return wanted + stem.slice(0, Math.max(1, room)) + extension } diff --git a/upload-app/src/index.ts b/upload-app/src/index.ts index 03b2cbb..a5a1dc8 100644 --- a/upload-app/src/index.ts +++ b/upload-app/src/index.ts @@ -28,7 +28,7 @@ import { title, unlockHandler } from '@ipp/core' -import { galleryUrl, maxFileSize, uploadNotice } from './config' +import { askName, galleryUrl, maxFileSize, uploadNotice } from './config' import { uploadAllowed } from './gate' import { createUploadReceiver } from './receive' import { getShare } from './share' @@ -141,7 +141,8 @@ router.get('/:shareType(share|s)/:key', decodeCookie, asyncHandler(async (req, r config: { uploadUrl: `${req.baseUrl}/${req.params.shareType}/${encodeURIComponent(key)}/upload`, maxFileSize: maxFileSize(), - title: title(resolved.link) + title: title(resolved.link), + askName: askName() }, basePath: req.baseUrl, galleryLink: gallery && `${gallery}/${req.params.shareType}/${encodeURIComponent(key)}`, diff --git a/upload-app/src/notify.ts b/upload-app/src/notify.ts index 9c311fb..44fcaed 100644 --- a/upload-app/src/notify.ts +++ b/upload-app/src/notify.ts @@ -17,6 +17,8 @@ export interface UploadNotification { share: { type: 'album' | 'individual', id: string, title: string } file: { name: string, size: number, type: string } asset: { id: string, status: 'created' | 'duplicate' } + /** The visitor's name as stored in the filename, or empty when none was given. */ + uploader: string } } @@ -28,13 +30,15 @@ export interface UploadNotification { export function buildNotification ( share: SharedLink, file: { name: string, size: number, type: string }, - asset: { id: string, status: 'created' | 'duplicate' } + asset: { id: string, status: 'created' | 'duplicate' }, + uploader = '' ): UploadNotification { const isAlbum = share.type === AlbumType.album const shareTitle = title(share) + const sender = uploader ? ` by ${uploader}` : '' return { title: 'Photo sent to ' + shareTitle, - message: `${file.name} (${formatSize(file.size)}) was uploaded to ${shareTitle}.`, + message: `${file.name} (${formatSize(file.size)}) was uploaded to ${shareTitle}${sender}.`, data: { event: 'upload', time: new Date().toISOString(), @@ -45,7 +49,8 @@ export function buildNotification ( title: shareTitle }, file, - asset + asset, + uploader } } } diff --git a/upload-app/src/receive.ts b/upload-app/src/receive.ts index 5548eda..c4cd579 100644 --- a/upload-app/src/receive.ts +++ b/upload-app/src/receive.ts @@ -2,8 +2,8 @@ import { pipeline } from 'stream' import { Request, Response } from 'express-serve-static-core' import dayjs from 'dayjs' import { abortOnClose, KeyType, log, respondToInvalidRequest, SharedLink } from '@ipp/core' -import { byteBudget, filenamePrefix, maxFileSize, rateLimit } from './config' -import { uploadFilename } from './filename' +import { askName, byteBudget, filenamePrefix, maxFileSize, rateLimit } from './config' +import { uploaderSlug, uploadFilename } from './filename' import { forwardUpload } from './forward' import { authoriseUpload } from './gate' import { createIdleTimeoutStream, IdleTimeoutError } from './idleTimeoutStream' @@ -66,6 +66,7 @@ export function createUploadReceiver () { const budget = createWindowBudget({ limit: byteBudget(), windowMs: 60 * 60_000 }) const maxBytes = maxFileSize() const prefix = filenamePrefix() + const withName = askName() return async function receiveUpload (req: Request, res: Response, link: SharedLink, keyType: KeyType): Promise { const key = req.params.key @@ -90,7 +91,9 @@ export function createUploadReceiver () { return } - const filename = uploadFilename(req.query.filename, prefix) + // The name is the visitor's claim, kept only as part of the filename + const uploader = withName ? uploaderSlug(req.query.uploader) : '' + const filename = uploadFilename(req.query.filename, prefix, uploader) if (!filename) { refuse(res, 400, 'Missing or unusable filename') return @@ -146,7 +149,8 @@ export function createUploadReceiver () { sendNotification(buildNotification( link, { name: filename, size: result.bytes, type: mimeType }, - { id: result.id, status: result.status } + { id: result.id, status: result.status }, + uploader )) } } diff --git a/upload-app/src/shared/upload.ts b/upload-app/src/shared/upload.ts index 26918e8..b342618 100644 --- a/upload-app/src/shared/upload.ts +++ b/upload-app/src/shared/upload.ts @@ -86,6 +86,8 @@ export interface UploadPageConfig { maxFileSize: number /** Share title, for the drop overlay and the completion message. */ title: string + /** Whether the page has a name field, sent with each file as `uploader`. */ + askName: boolean } /** Success body of `POST /upload`. */ diff --git a/upload-app/src/view/upload.tsx b/upload-app/src/view/upload.tsx index 1e95b6e..76dc967 100644 --- a/upload-app/src/view/upload.tsx +++ b/upload-app/src/view/upload.tsx @@ -52,6 +52,12 @@ export function UploadPage ({ config, basePath, galleryLink, notice }: UploadPag
+ {config.askName && ( + + )}