diff --git a/app/package.json b/app/package.json index aa00415..0bf86c5 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "immich-public-proxy", - "version": "1.12.1", + "version": "1.13.0", "scripts": { "dev": "ts-node src/index.ts", "build": "npx tsc", diff --git a/app/src/immich.ts b/app/src/immich.ts index 2c91084..cfb922a 100644 --- a/app/src/immich.ts +++ b/app/src/immich.ts @@ -5,6 +5,7 @@ import { AssetType, ImageSize, IncomingShareRequest, + KeyType, SharedLink, SharedLinkResult } from './types' @@ -58,13 +59,13 @@ class Immich { // Check that the key is a valid format if (!immich.isKey(request.key)) { - log('Invalid share key ' + request.key) + log('Wrong key format ' + request.key) respondToInvalidRequest(res, 404) return } // 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) { // This isn't a valid request - check the console for more information respondToInvalidRequest(res, 404) @@ -142,10 +143,10 @@ class Immich { * 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. */ - async getShareByKey (key: string, password?: string): Promise { + async getShareByKey (key: string, password?: string, keyType: KeyType = KeyType.key): Promise { let link const url = this.buildUrl(this.apiUrl() + '/shared-links/me', { - key, + [keyType]: key, password }) const res = await fetch(url) diff --git a/app/src/index.ts b/app/src/index.ts index 3453727..99ce354 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -6,9 +6,9 @@ import immich from './immich' import crypto from 'crypto' import render from './render' import dayjs from 'dayjs' -import { Request, Response, NextFunction } from 'express-serve-static-core' -import { AssetType, ImageSize } from './types' -import { log, toString, addResponseHeaders, getConfigOption } from './functions' +import { NextFunction, Request, Response } from 'express-serve-static-core' +import { AssetType, ImageSize, KeyType } from './types' +import { addResponseHeaders, getConfigOption, log, toString } from './functions' import { decrypt, encrypt } from './encrypt' 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 */ -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({ req, key: req.params.key, + keyType: req.params.shareType === 's' ? KeyType.slug : KeyType.key, mode: req.params.mode, password: req.password }, res) diff --git a/app/src/types.ts b/app/src/types.ts index 93547c2..ffaee6b 100644 --- a/app/src/types.ts +++ b/app/src/types.ts @@ -5,6 +5,11 @@ export enum AssetType { video = 'VIDEO' } +export enum KeyType { + key = 'key', + slug = 'slug' +} + export interface ExifInfo { description?: string; } @@ -62,6 +67,7 @@ export enum ImageSize { export interface IncomingShareRequest { req: Request; key: string; + keyType?: KeyType; password?: string; mode?: string; size?: ImageSize;