Fix #29 Download all password albums
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "immich-public-proxy",
|
"name": "immich-public-proxy",
|
||||||
"version": "1.5.2",
|
"version": "1.5.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "ts-node src/index.ts",
|
"dev": "ts-node src/index.ts",
|
||||||
"build": "npx tsc",
|
"build": "npx tsc",
|
||||||
|
|||||||
@@ -136,6 +136,7 @@ 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.password = password
|
||||||
if (link.expiresAt && dayjs(link.expiresAt) < dayjs()) {
|
if (link.expiresAt && dayjs(link.expiresAt) < dayjs()) {
|
||||||
// This link has expired
|
// This link has expired
|
||||||
log('Expired link ' + key)
|
log('Expired link ' + key)
|
||||||
|
|||||||
+32
-23
@@ -2,10 +2,17 @@ import express from 'express'
|
|||||||
import immich from './immich'
|
import immich from './immich'
|
||||||
import render from './render'
|
import render from './render'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
|
import { Request, Response, NextFunction } from 'express-serve-static-core'
|
||||||
import { AssetType, ImageSize } from './types'
|
import { AssetType, ImageSize } from './types'
|
||||||
import { decrypt } from './encrypt'
|
import { decrypt } from './encrypt'
|
||||||
import { log, toString, addResponseHeaders } from './functions'
|
import { log, toString, addResponseHeaders } from './functions'
|
||||||
|
|
||||||
|
declare module 'express-serve-static-core' {
|
||||||
|
interface Request {
|
||||||
|
password?: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
@@ -18,6 +25,26 @@ app.use('/share/static', express.static('public', { setHeaders: addResponseHeade
|
|||||||
// Serve the same assets on /, to allow for /robots.txt and /favicon.ico
|
// Serve the same assets on /, to allow for /robots.txt and /favicon.ico
|
||||||
app.use(express.static('public', { setHeaders: addResponseHeaders }))
|
app.use(express.static('public', { setHeaders: addResponseHeaders }))
|
||||||
|
|
||||||
|
const checkPassword = (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
if (req.query?.cr && req.query?.iv) {
|
||||||
|
try {
|
||||||
|
const payload = JSON.parse(decrypt({
|
||||||
|
iv: toString(req.query.iv),
|
||||||
|
cr: toString(req.query.cr)
|
||||||
|
}))
|
||||||
|
if (payload?.expires && dayjs(payload.expires) > dayjs()) {
|
||||||
|
req.password = payload.password
|
||||||
|
} else {
|
||||||
|
log(`Attempted to load assets from ${req.params.key} with an expired decryption token`)
|
||||||
|
// Send 404 rather than 401 so as not to provide information to an attacker that there is "something" at this path
|
||||||
|
res.status(404).send()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
|
next()
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* [ROUTE] Healthcheck
|
* [ROUTE] Healthcheck
|
||||||
* The path matches for /share/healthcheck, and also the legacy /healthcheck
|
* The path matches for /share/healthcheck, and also the legacy /healthcheck
|
||||||
@@ -33,10 +60,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
|
* [ROUTE] This is the main URL that someone would visit if they are opening a shared link
|
||||||
*/
|
*/
|
||||||
app.get('/share/:key/:mode(download)?', async (req, res) => {
|
app.get('/share/:key/:mode(download)?', checkPassword, async (req, res) => {
|
||||||
await immich.handleShareRequest({
|
await immich.handleShareRequest({
|
||||||
key: req.params.key,
|
key: req.params.key,
|
||||||
mode: req.params.mode
|
mode: req.params.mode,
|
||||||
|
password: req.password
|
||||||
}, res)
|
}, res)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -53,7 +81,7 @@ app.post('/share/unlock', async (req, res) => {
|
|||||||
/*
|
/*
|
||||||
* [ROUTE] This is the direct link to a photo or video asset
|
* [ROUTE] This is the direct link to a photo or video asset
|
||||||
*/
|
*/
|
||||||
app.get('/share/:type(photo|video)/:key/:id/:size?', async (req, res) => {
|
app.get('/share/:type(photo|video)/:key/:id/:size?', checkPassword, async (req, res) => {
|
||||||
// Add the headers configured in config.json (most likely `cache-control`)
|
// Add the headers configured in config.json (most likely `cache-control`)
|
||||||
addResponseHeaders(res)
|
addResponseHeaders(res)
|
||||||
|
|
||||||
@@ -71,28 +99,9 @@ app.get('/share/:type(photo|video)/:key/:id/:size?', async (req, res) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the password payload, if one was provided
|
|
||||||
let password
|
|
||||||
if (req.query?.cr && req.query?.iv) {
|
|
||||||
try {
|
|
||||||
const payload = JSON.parse(decrypt({
|
|
||||||
iv: toString(req.query.iv),
|
|
||||||
cr: toString(req.query.cr)
|
|
||||||
}))
|
|
||||||
if (payload?.expires && dayjs(payload.expires) > dayjs()) {
|
|
||||||
password = payload.password
|
|
||||||
} else {
|
|
||||||
log(`Attempted to load assets from ${req.params.key} with an expired decryption token`)
|
|
||||||
// Send 404 rather than 401 so as not to provide information to an attacker that there is "something" at this path
|
|
||||||
res.status(404).send()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} catch (e) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch the shared link information from Immich, so we can check to make sure that the requested asset
|
// Fetch the shared link information from Immich, so we can check to make sure that the requested asset
|
||||||
// is allowed by this shared link.
|
// is allowed by this shared link.
|
||||||
const sharedLink = (await immich.getShareByKey(req.params.key, password))?.link
|
const sharedLink = (await immich.getShareByKey(req.params.key, req.password))?.link
|
||||||
const request = {
|
const request = {
|
||||||
key: req.params.key,
|
key: req.params.key,
|
||||||
range: req.headers.range || ''
|
range: req.headers.range || ''
|
||||||
|
|||||||
+3
-1
@@ -3,6 +3,7 @@ import { Response } from 'express-serve-static-core'
|
|||||||
import { Asset, AssetType, ImageSize, IncomingShareRequest, SharedLink } from './types'
|
import { Asset, AssetType, ImageSize, IncomingShareRequest, SharedLink } from './types'
|
||||||
import { getConfigOption } from './functions'
|
import { getConfigOption } from './functions'
|
||||||
import archiver from 'archiver'
|
import archiver from 'archiver'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
class Render {
|
class Render {
|
||||||
lgConfig
|
lgConfig
|
||||||
@@ -121,6 +122,7 @@ class Render {
|
|||||||
title: this.title(share),
|
title: this.title(share),
|
||||||
path: '/share/' + share.key,
|
path: '/share/' + share.key,
|
||||||
showDownload: getConfigOption('ipp.allowDownloadAll', false),
|
showDownload: getConfigOption('ipp.allowDownloadAll', false),
|
||||||
|
password: share.password ? immich.encryptPassword(share.password) : {},
|
||||||
showTitle: getConfigOption('ipp.showGalleryTitle', false),
|
showTitle: getConfigOption('ipp.showGalleryTitle', false),
|
||||||
lgConfig: getConfigOption('lightGallery', {})
|
lgConfig: getConfigOption('lightGallery', {})
|
||||||
})
|
})
|
||||||
@@ -130,7 +132,7 @@ class Render {
|
|||||||
* Attempt to get a title from the link description or the album title
|
* Attempt to get a title from the link description or the album title
|
||||||
*/
|
*/
|
||||||
title (share: SharedLink) {
|
title (share: SharedLink) {
|
||||||
return share.description || share?.album?.albumName || ''
|
return share.description || share?.album?.albumName || 'Gallery'
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export interface SharedLink {
|
|||||||
type: string;
|
type: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
assets: Asset[];
|
assets: Asset[];
|
||||||
|
password?: string;
|
||||||
album?: {
|
album?: {
|
||||||
id: string;
|
id: string;
|
||||||
albumName?: string;
|
albumName?: string;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
||||||
<title><%- title || 'Gallery' %></title>
|
<title><%- title %></title>
|
||||||
<link rel="icon" href="/share/static/favicon.ico" type="image/x-icon">
|
<link rel="icon" href="/share/static/favicon.ico" type="image/x-icon">
|
||||||
<link type="text/css" rel="stylesheet" href="/share/static/style.css"/>
|
<link type="text/css" rel="stylesheet" href="/share/static/style.css"/>
|
||||||
<link type="text/css" rel="stylesheet" href="/share/static/lg/lightgallery-bundle.min.css"/>
|
<link type="text/css" rel="stylesheet" href="/share/static/lg/lightgallery-bundle.min.css"/>
|
||||||
@@ -12,9 +12,15 @@
|
|||||||
<% if (showTitle) { %>
|
<% if (showTitle) { %>
|
||||||
<h1><%- title || 'Gallery' %></h1>
|
<h1><%- title || 'Gallery' %></h1>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if (showDownload) { %>
|
<%
|
||||||
|
if (showDownload) {
|
||||||
|
// If there is a password required for the download, format it as a query string
|
||||||
|
const passwordQuery = Object.entries(password).length ? '?' + (new URLSearchParams(password)).toString() : ''
|
||||||
|
%>
|
||||||
<div id="download-all">
|
<div id="download-all">
|
||||||
<a href="<%- path %>/download" title="Download all"><img src="/images/download-all.svg" height="24" width="24" alt="Download all"></a>
|
<a href="<%- path %>/download<%- passwordQuery %>" title="Download all"><img src="/images/download-all.svg"
|
||||||
|
height="24"
|
||||||
|
width="24" alt="Download all"></a>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user