#116 Partial solution for custom album links

This commit is contained in:
Alan Grainger
2025-08-07 21:16:13 +02:00
parent 35c78fdbe6
commit 033d49dd75
4 changed files with 17 additions and 9 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "immich-public-proxy", "name": "immich-public-proxy",
"version": "1.12.1", "version": "1.13.0",
"scripts": { "scripts": {
"dev": "ts-node src/index.ts", "dev": "ts-node src/index.ts",
"build": "npx tsc", "build": "npx tsc",
+5 -4
View File
@@ -5,6 +5,7 @@ import {
AssetType, AssetType,
ImageSize, ImageSize,
IncomingShareRequest, IncomingShareRequest,
KeyType,
SharedLink, SharedLink,
SharedLinkResult SharedLinkResult
} from './types' } from './types'
@@ -58,13 +59,13 @@ class Immich {
// Check that the key is a valid format // Check that the key is a valid format
if (!immich.isKey(request.key)) { if (!immich.isKey(request.key)) {
log('Invalid share key ' + request.key) log('Wrong key format ' + request.key)
respondToInvalidRequest(res, 404) respondToInvalidRequest(res, 404)
return return
} }
// Get information about the shared link via Immich API // Get information about the shared link via Immich API
const sharedLinkRes = await immich.getShareByKey(request.key, request.password) const sharedLinkRes = await immich.getShareByKey(request.key, request.password, request.keyType || KeyType.key)
if (!sharedLinkRes.valid) { if (!sharedLinkRes.valid) {
// This isn't a valid request - check the console for more information // This isn't a valid request - check the console for more information
respondToInvalidRequest(res, 404) respondToInvalidRequest(res, 404)
@@ -142,10 +143,10 @@ class Immich {
* Query Immich for the SharedLink metadata for a given key. * Query Immich for the SharedLink metadata for a given key.
* The key is what is returned in the URL when you create a share in Immich. * The key is what is returned in the URL when you create a share in Immich.
*/ */
async getShareByKey (key: string, password?: string): Promise<SharedLinkResult> { async getShareByKey (key: string, password?: string, keyType: KeyType = KeyType.key): Promise<SharedLinkResult> {
let link let link
const url = this.buildUrl(this.apiUrl() + '/shared-links/me', { const url = this.buildUrl(this.apiUrl() + '/shared-links/me', {
key, [keyType]: key,
password password
}) })
const res = await fetch(url) const res = await fetch(url)
+5 -4
View File
@@ -6,9 +6,9 @@ import immich from './immich'
import crypto from 'crypto' import crypto from 'crypto'
import render from './render' import render from './render'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { Request, Response, NextFunction } from 'express-serve-static-core' import { NextFunction, Request, Response } from 'express-serve-static-core'
import { AssetType, ImageSize } from './types' import { AssetType, ImageSize, KeyType } from './types'
import { log, toString, addResponseHeaders, getConfigOption } from './functions' import { addResponseHeaders, getConfigOption, log, toString } from './functions'
import { decrypt, encrypt } from './encrypt' import { decrypt, encrypt } from './encrypt'
import { respondToInvalidRequest } from './invalidRequestHandler' import { respondToInvalidRequest } from './invalidRequestHandler'
@@ -74,10 +74,11 @@ app.get(/^(|\/share)\/healthcheck$/, async (_req, res) => {
/* /*
* [ROUTE] This is the main URL that someone would visit if they are opening a shared link * [ROUTE] This is the main URL that someone would visit if they are opening a shared link
*/ */
app.get('/share/:key/:mode(download)?', decodeCookie, async (req, res) => { app.get('/:shareType(share|s)/:key/:mode(download)?', decodeCookie, async (req, res) => {
await immich.handleShareRequest({ await immich.handleShareRequest({
req, req,
key: req.params.key, key: req.params.key,
keyType: req.params.shareType === 's' ? KeyType.slug : KeyType.key,
mode: req.params.mode, mode: req.params.mode,
password: req.password password: req.password
}, res) }, res)
+6
View File
@@ -5,6 +5,11 @@ export enum AssetType {
video = 'VIDEO' video = 'VIDEO'
} }
export enum KeyType {
key = 'key',
slug = 'slug'
}
export interface ExifInfo { export interface ExifInfo {
description?: string; description?: string;
} }
@@ -62,6 +67,7 @@ export enum ImageSize {
export interface IncomingShareRequest { export interface IncomingShareRequest {
req: Request; req: Request;
key: string; key: string;
keyType?: KeyType;
password?: string; password?: string;
mode?: string; mode?: string;
size?: ImageSize; size?: ImageSize;