#116 Support custom URL links (slug-type links)
This commit is contained in:
+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()
|
||||
})
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user