#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
|
||||
|
||||
| Option | Type | Description |
|
||||
|-------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `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. |
|
||||
| `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. |
|
||||
| `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` |
|
||||
| `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. |
|
||||
| Option | Type | Description |
|
||||
|-------------------------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| `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. |
|
||||
| `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. |
|
||||
| `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 |
|
||||
| `allowSlugLinks` | `bool` | Enable/disable the custom URL links. |
|
||||
| `showHomePage` | `bool` | Set to `false` to remove the IPP shield page at `/` and at `/share` |
|
||||
| `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`:
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"singleItemAutoOpen": true,
|
||||
"downloadOriginalPhoto": true,
|
||||
"allowDownloadAll": 0,
|
||||
"allowSlugLinks": true,
|
||||
"showHomePage": true,
|
||||
"showGalleryTitle": false,
|
||||
"showMetadata": {
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "immich-public-proxy",
|
||||
"version": "1.12.1",
|
||||
"version": "1.13.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "immich-public-proxy",
|
||||
"version": "1.12.1",
|
||||
"version": "1.13.1",
|
||||
"license": "AGPL-3.0",
|
||||
"dependencies": {
|
||||
"archiver": "^7.0.1",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "immich-public-proxy",
|
||||
"version": "1.13.0",
|
||||
"version": "1.13.1",
|
||||
"scripts": {
|
||||
"dev": "ts-node src/index.ts",
|
||||
"build": "npx tsc",
|
||||
|
||||
+6
-1
@@ -156,12 +156,13 @@ class Immich {
|
||||
if (res.status === 200) {
|
||||
// Normal response - get the shared assets
|
||||
link = jsonBody as SharedLink
|
||||
link.keyType = keyType
|
||||
|
||||
// For an album, we need to make a second request to Immich to populate
|
||||
// the array of assets
|
||||
if (link.type === AlbumType.album) {
|
||||
const albumRes = await fetch(this.buildUrl(this.apiUrl() + '/albums/' + link?.album?.id, {
|
||||
key,
|
||||
[keyType]: key,
|
||||
password
|
||||
}))
|
||||
const album = await albumRes.json() as Album
|
||||
@@ -310,6 +311,10 @@ class Immich {
|
||||
return size as ImageSize
|
||||
}
|
||||
}
|
||||
|
||||
getKeyTypeFromShare (shareType: string) {
|
||||
return shareType === 's' ? KeyType.slug : KeyType.key
|
||||
}
|
||||
}
|
||||
|
||||
const immich = new Immich()
|
||||
|
||||
+21
-22
@@ -7,7 +7,7 @@ import crypto from 'crypto'
|
||||
import render from './render'
|
||||
import dayjs from 'dayjs'
|
||||
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 { decrypt, encrypt } from './encrypt'
|
||||
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
|
||||
*/
|
||||
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)
|
||||
const keyType = immich.getKeyTypeFromShare(req.params.shareType)
|
||||
|
||||
if (keyType === KeyType.slug && !getConfigOption('ipp.allowSlugLinks', true)) {
|
||||
// Slug type links are not allowed
|
||||
respondToInvalidRequest(res, 404)
|
||||
} else {
|
||||
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
|
||||
}
|
||||
|
||||
// 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 = {
|
||||
req,
|
||||
key: req.params.key,
|
||||
range: req.headers.range || ''
|
||||
}
|
||||
if (sharedLink?.assets.length) {
|
||||
// Check that the requested asset exists in this share
|
||||
const asset = sharedLink.assets.find(x => x.id === req.params.id)
|
||||
if (asset) {
|
||||
asset.type = req.params.type === 'video' ? AssetType.video : AssetType.image
|
||||
render.assetBuffer(request, res, asset, req.params.size).then()
|
||||
}
|
||||
} else {
|
||||
log('No asset found for ' + req.path)
|
||||
respondToInvalidRequest(res, 404)
|
||||
}
|
||||
const asset = {
|
||||
id: req.params.id,
|
||||
key: req.params.key,
|
||||
type: req.params.type === 'video' ? AssetType.video : AssetType.image
|
||||
} as Asset
|
||||
render.assetBuffer(request, res, asset, req.params.size).then()
|
||||
})
|
||||
|
||||
/*
|
||||
|
||||
@@ -16,6 +16,18 @@ class Render {
|
||||
* Stream data from Immich back to the client
|
||||
*/
|
||||
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
|
||||
const headerList = ['content-type', 'content-length', 'last-modified', 'etag']
|
||||
size = immich.validateImageSize(size)
|
||||
|
||||
@@ -38,6 +38,7 @@ export interface Album {
|
||||
|
||||
export interface SharedLink {
|
||||
key: string;
|
||||
keyType: KeyType;
|
||||
type: string;
|
||||
description?: string;
|
||||
assets: Asset[];
|
||||
|
||||
Reference in New Issue
Block a user