#116 Support custom URL links (slug-type links)
This commit is contained in:
@@ -146,16 +146,17 @@ Alternatively, you can [pass the configuration inline](docs/inline-configuration
|
|||||||
|
|
||||||
### Immich Public Proxy options
|
### Immich Public Proxy options
|
||||||
|
|
||||||
| Option | Type | Description |
|
| Option | Type | Description |
|
||||||
|-------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `responseHeaders` | `object` | Change the headers sent with your web responses. By default there is `cache-control` and CORS added. |
|
| `responseHeaders` | `object` | Change the headers sent with your web responses. By default there is `cache-control` and CORS added. |
|
||||||
| `singleImageGallery` | `bool` | By default a link to a single image will directly open the image file. Set to `true` if you want to show a gallery page instead for a single item. |
|
| `singleImageGallery` | `bool` | By default a link to a single image will directly open the image file. Set to `true` if you want to show a gallery page instead for a single item. |
|
||||||
| `downloadOriginalPhoto` | `bool` | Set to `false` if you only want people to be able to download the 'preview' quality photo, rather than your original photo. |
|
| `downloadOriginalPhoto` | `bool` | Set to `false` if you only want people to be able to download the 'preview' quality photo, rather than your original photo. |
|
||||||
| `showGalleryTitle` | `bool` | Show a title on the gallery page. |
|
| `showGalleryTitle` | `bool` | Show a title on the gallery page. |
|
||||||
| `allowDownloadAll` | `int` | Allow visitors to download all files as a zip.<br>`0` disable downloads<br>`1` follow Immich setting per share ([example](https://github.com/user-attachments/assets/79ea8c08-71ce-42ab-b025-10aec384938a))<br>`2` always allowed |
|
| `allowDownloadAll` | `int` | Allow visitors to download all files as a zip.<br>`0` disable downloads<br>`1` follow Immich setting per share ([example](https://github.com/user-attachments/assets/79ea8c08-71ce-42ab-b025-10aec384938a))<br>`2` always allowed |
|
||||||
| `showHomePage` | `bool` | Set to `false` to remove the IPP shield page at `/` and at `/share` |
|
| `allowSlugLinks` | `bool` | Enable/disable the custom URL links. |
|
||||||
| `showMetadata` | `object` | See the [Metadata](#metadata) section below. |
|
| `showHomePage` | `bool` | Set to `false` to remove the IPP shield page at `/` and at `/share` |
|
||||||
| `customInvalidResponse` | various | Send a custom response instead of the default 404 - see [Custom responses](docs/custom-responses.md) for more details. |
|
| `showMetadata` | `object` | See the [Metadata](#metadata) section below. |
|
||||||
|
| `customInvalidResponse` | various | Send a custom response instead of the default 404 - see [Custom responses](docs/custom-responses.md) for more details. |
|
||||||
|
|
||||||
For example, to disable the home page at `/` and at `/share` you need to change `showHomePage` to `false`:
|
For example, to disable the home page at `/` and at `/share` you need to change `showHomePage` to `false`:
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"singleItemAutoOpen": true,
|
"singleItemAutoOpen": true,
|
||||||
"downloadOriginalPhoto": true,
|
"downloadOriginalPhoto": true,
|
||||||
"allowDownloadAll": 0,
|
"allowDownloadAll": 0,
|
||||||
|
"allowSlugLinks": true,
|
||||||
"showHomePage": true,
|
"showHomePage": true,
|
||||||
"showGalleryTitle": false,
|
"showGalleryTitle": false,
|
||||||
"showMetadata": {
|
"showMetadata": {
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "immich-public-proxy",
|
"name": "immich-public-proxy",
|
||||||
"version": "1.12.1",
|
"version": "1.13.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "immich-public-proxy",
|
"name": "immich-public-proxy",
|
||||||
"version": "1.12.1",
|
"version": "1.13.1",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"archiver": "^7.0.1",
|
"archiver": "^7.0.1",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "immich-public-proxy",
|
"name": "immich-public-proxy",
|
||||||
"version": "1.13.0",
|
"version": "1.13.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "ts-node src/index.ts",
|
"dev": "ts-node src/index.ts",
|
||||||
"build": "npx tsc",
|
"build": "npx tsc",
|
||||||
|
|||||||
+6
-1
@@ -156,12 +156,13 @@ class Immich {
|
|||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
// Normal response - get the shared assets
|
// Normal response - get the shared assets
|
||||||
link = jsonBody as SharedLink
|
link = jsonBody as SharedLink
|
||||||
|
link.keyType = keyType
|
||||||
|
|
||||||
// For an album, we need to make a second request to Immich to populate
|
// For an album, we need to make a second request to Immich to populate
|
||||||
// the array of assets
|
// the array of assets
|
||||||
if (link.type === AlbumType.album) {
|
if (link.type === AlbumType.album) {
|
||||||
const albumRes = await fetch(this.buildUrl(this.apiUrl() + '/albums/' + link?.album?.id, {
|
const albumRes = await fetch(this.buildUrl(this.apiUrl() + '/albums/' + link?.album?.id, {
|
||||||
key,
|
[keyType]: key,
|
||||||
password
|
password
|
||||||
}))
|
}))
|
||||||
const album = await albumRes.json() as Album
|
const album = await albumRes.json() as Album
|
||||||
@@ -310,6 +311,10 @@ class Immich {
|
|||||||
return size as ImageSize
|
return size as ImageSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getKeyTypeFromShare (shareType: string) {
|
||||||
|
return shareType === 's' ? KeyType.slug : KeyType.key
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const immich = new Immich()
|
const immich = new Immich()
|
||||||
|
|||||||
+21
-22
@@ -7,7 +7,7 @@ import crypto from 'crypto'
|
|||||||
import render from './render'
|
import render from './render'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { NextFunction, Request, Response } from 'express-serve-static-core'
|
import { NextFunction, Request, Response } from 'express-serve-static-core'
|
||||||
import { AssetType, ImageSize, KeyType } from './types'
|
import { Asset, AssetType, ImageSize, KeyType } from './types'
|
||||||
import { addResponseHeaders, getConfigOption, log, toString } 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'
|
||||||
@@ -75,13 +75,20 @@ 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('/:shareType(share|s)/:key/:mode(download)?', decodeCookie, async (req, res) => {
|
app.get('/:shareType(share|s)/:key/:mode(download)?', decodeCookie, async (req, res) => {
|
||||||
await immich.handleShareRequest({
|
const keyType = immich.getKeyTypeFromShare(req.params.shareType)
|
||||||
req,
|
|
||||||
key: req.params.key,
|
if (keyType === KeyType.slug && !getConfigOption('ipp.allowSlugLinks', true)) {
|
||||||
keyType: req.params.shareType === 's' ? KeyType.slug : KeyType.key,
|
// Slug type links are not allowed
|
||||||
mode: req.params.mode,
|
respondToInvalidRequest(res, 404)
|
||||||
password: req.password
|
} else {
|
||||||
}, res)
|
await immich.handleShareRequest({
|
||||||
|
req,
|
||||||
|
key: req.params.key,
|
||||||
|
keyType,
|
||||||
|
mode: req.params.mode,
|
||||||
|
password: req.password
|
||||||
|
}, res)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -120,25 +127,17 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', decodeCookie, async (req, r
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the shared link information from Immich, so we can check to make sure that the requested asset
|
|
||||||
// is allowed by this shared link.
|
|
||||||
const sharedLink = (await immich.getShareByKey(req.params.key, req.password))?.link
|
|
||||||
const request = {
|
const request = {
|
||||||
req,
|
req,
|
||||||
key: req.params.key,
|
key: req.params.key,
|
||||||
range: req.headers.range || ''
|
range: req.headers.range || ''
|
||||||
}
|
}
|
||||||
if (sharedLink?.assets.length) {
|
const asset = {
|
||||||
// Check that the requested asset exists in this share
|
id: req.params.id,
|
||||||
const asset = sharedLink.assets.find(x => x.id === req.params.id)
|
key: req.params.key,
|
||||||
if (asset) {
|
type: req.params.type === 'video' ? AssetType.video : AssetType.image
|
||||||
asset.type = req.params.type === 'video' ? AssetType.video : AssetType.image
|
} as Asset
|
||||||
render.assetBuffer(request, res, asset, req.params.size).then()
|
render.assetBuffer(request, res, asset, req.params.size).then()
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log('No asset found for ' + req.path)
|
|
||||||
respondToInvalidRequest(res, 404)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -16,6 +16,18 @@ class Render {
|
|||||||
* Stream data from Immich back to the client
|
* Stream data from Immich back to the client
|
||||||
*/
|
*/
|
||||||
async assetBuffer (req: IncomingShareRequest, res: Response, asset: Asset, size?: ImageSize | string) {
|
async assetBuffer (req: IncomingShareRequest, res: Response, asset: Asset, size?: ImageSize | string) {
|
||||||
|
// Get meta info regarding the asset
|
||||||
|
const metaRes = await fetch(immich.buildUrl(immich.apiUrl() + '/assets/' + encodeURIComponent(asset.id), {
|
||||||
|
key: asset.key
|
||||||
|
}))
|
||||||
|
const meta = await metaRes.json()
|
||||||
|
|
||||||
|
// Make sure we should display this asset
|
||||||
|
if (meta.isTrashed || meta.visibility === 'locked') {
|
||||||
|
respondToInvalidRequest(res, 404)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare the request
|
// Prepare the request
|
||||||
const headerList = ['content-type', 'content-length', 'last-modified', 'etag']
|
const headerList = ['content-type', 'content-length', 'last-modified', 'etag']
|
||||||
size = immich.validateImageSize(size)
|
size = immich.validateImageSize(size)
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ export interface Album {
|
|||||||
|
|
||||||
export interface SharedLink {
|
export interface SharedLink {
|
||||||
key: string;
|
key: string;
|
||||||
|
keyType: KeyType;
|
||||||
type: string;
|
type: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
assets: Asset[];
|
assets: Asset[];
|
||||||
|
|||||||
Reference in New Issue
Block a user