#116 Partial solution for custom album links
This commit is contained in:
+5
-4
@@ -5,6 +5,7 @@ import {
|
||||
AssetType,
|
||||
ImageSize,
|
||||
IncomingShareRequest,
|
||||
KeyType,
|
||||
SharedLink,
|
||||
SharedLinkResult
|
||||
} from './types'
|
||||
@@ -58,13 +59,13 @@ class Immich {
|
||||
|
||||
// Check that the key is a valid format
|
||||
if (!immich.isKey(request.key)) {
|
||||
log('Invalid share key ' + request.key)
|
||||
log('Wrong key format ' + request.key)
|
||||
respondToInvalidRequest(res, 404)
|
||||
return
|
||||
}
|
||||
|
||||
// Get information about the shared link via Immich API
|
||||
const sharedLinkRes = await immich.getShareByKey(request.key, request.password)
|
||||
const sharedLinkRes = await immich.getShareByKey(request.key, request.password, request.keyType || KeyType.key)
|
||||
if (!sharedLinkRes.valid) {
|
||||
// This isn't a valid request - check the console for more information
|
||||
respondToInvalidRequest(res, 404)
|
||||
@@ -142,10 +143,10 @@ class Immich {
|
||||
* Query Immich for the SharedLink metadata for a given key.
|
||||
* The key is what is returned in the URL when you create a share in Immich.
|
||||
*/
|
||||
async getShareByKey (key: string, password?: string): Promise<SharedLinkResult> {
|
||||
async getShareByKey (key: string, password?: string, keyType: KeyType = KeyType.key): Promise<SharedLinkResult> {
|
||||
let link
|
||||
const url = this.buildUrl(this.apiUrl() + '/shared-links/me', {
|
||||
key,
|
||||
[keyType]: key,
|
||||
password
|
||||
})
|
||||
const res = await fetch(url)
|
||||
|
||||
+5
-4
@@ -6,9 +6,9 @@ import immich from './immich'
|
||||
import crypto from 'crypto'
|
||||
import render from './render'
|
||||
import dayjs from 'dayjs'
|
||||
import { Request, Response, NextFunction } from 'express-serve-static-core'
|
||||
import { AssetType, ImageSize } from './types'
|
||||
import { log, toString, addResponseHeaders, getConfigOption } from './functions'
|
||||
import { NextFunction, Request, Response } from 'express-serve-static-core'
|
||||
import { AssetType, ImageSize, KeyType } from './types'
|
||||
import { addResponseHeaders, getConfigOption, log, toString } from './functions'
|
||||
import { decrypt, encrypt } from './encrypt'
|
||||
import { respondToInvalidRequest } from './invalidRequestHandler'
|
||||
|
||||
@@ -74,10 +74,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
|
||||
*/
|
||||
app.get('/share/:key/:mode(download)?', decodeCookie, async (req, res) => {
|
||||
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)
|
||||
|
||||
@@ -5,6 +5,11 @@ export enum AssetType {
|
||||
video = 'VIDEO'
|
||||
}
|
||||
|
||||
export enum KeyType {
|
||||
key = 'key',
|
||||
slug = 'slug'
|
||||
}
|
||||
|
||||
export interface ExifInfo {
|
||||
description?: string;
|
||||
}
|
||||
@@ -62,6 +67,7 @@ export enum ImageSize {
|
||||
export interface IncomingShareRequest {
|
||||
req: Request;
|
||||
key: string;
|
||||
keyType?: KeyType;
|
||||
password?: string;
|
||||
mode?: string;
|
||||
size?: ImageSize;
|
||||
|
||||
Reference in New Issue
Block a user