1
0
Fork 0
mirror of https://github.com/alangrainger/immich-public-proxy.git synced 2025-01-15 12:36:44 +01:00

Fix #15 Support live photos and HEIC images

This commit is contained in:
Alan Grainger 2024-11-12 10:27:26 +01:00
parent 5f502a215a
commit 1daf6c1c4b
2 changed files with 9 additions and 3 deletions

View file

@ -2,7 +2,7 @@ import express from 'express'
import immich from './immich'
import render from './render'
import dayjs from 'dayjs'
import { AssetType } from './types'
import { AssetType, ImageSize } from './types'
import { decrypt } from './encrypt'
import { log, toString, addResponseHeaders } from './functions'
@ -36,6 +36,12 @@ app.get('/:type(photo|video)/:key/:id/:size?', async (req, res) => {
addResponseHeaders(res)
// Check for valid key and ID
if (immich.isKey(req.params.key) && immich.isId(req.params.id)) {
// Validate the size parameter
if (req.params.size && !Object.values(ImageSize).includes(req.params.size as ImageSize)) {
log('Invalid size parameter ' + req.path)
res.status(404).send()
return
}
let password
// Validate the password payload, if one was provided
if (req.query?.cr && req.query?.iv) {
@ -59,7 +65,7 @@ app.get('/:type(photo|video)/:key/:id/:size?', async (req, res) => {
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, immich.validateImageSize(req.params.size)).then()
render.assetBuffer(request, res, asset, req.params.size).then()
return
}
}

View file

@ -13,7 +13,7 @@ class Render {
/**
* Stream data from Immich back to the client
*/
async assetBuffer (req: IncomingShareRequest, res: Response, asset: Asset, size?: ImageSize) {
async assetBuffer (req: IncomingShareRequest, res: Response, asset: Asset, size?: ImageSize | string) {
// Prepare the request
const headerList = ['content-type', 'content-length', 'last-modified', 'etag']
size = immich.validateImageSize(size)