Add #10 - Single item as a gallery
This commit is contained in:
+5
-22
@@ -2,19 +2,19 @@ import express from 'express'
|
||||
import immich from './immich'
|
||||
import render from './render'
|
||||
import dayjs from 'dayjs'
|
||||
import { AssetType, ImageSize } from './types'
|
||||
import { Request } from 'express-serve-static-core'
|
||||
import { AssetType } from './types'
|
||||
import { decrypt } from './encrypt'
|
||||
import { log, getSize, toString, addResponseHeaders } from './functions'
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
const app = express()
|
||||
// Add the EJS view engine, to render the gallery page
|
||||
app.set('view engine', 'ejs')
|
||||
// Serve static assets from the /public folder
|
||||
app.use(express.static('public'))
|
||||
// For parsing the password unlock form
|
||||
app.use(express.json())
|
||||
// Serve static assets from the /public folder
|
||||
app.use(express.static('public', { setHeaders: addResponseHeaders }))
|
||||
|
||||
// An incoming request for a shared link
|
||||
app.get('/share/:key', async (req, res) => {
|
||||
@@ -34,7 +34,7 @@ app.post('/unlock', async (req, res) => {
|
||||
|
||||
// Output the buffer data for a photo or video
|
||||
app.get('/:type(photo|video)/:key/:id', async (req, res) => {
|
||||
res.set('Cache-Control', 'public, max-age=' + process.env.CACHE_AGE)
|
||||
addResponseHeaders(res)
|
||||
// Check for valid key and ID
|
||||
if (immich.isKey(req.params.key) && immich.isId(req.params.id)) {
|
||||
let password
|
||||
@@ -83,23 +83,6 @@ app.get('*', (req, res) => {
|
||||
res.status(404).send()
|
||||
})
|
||||
|
||||
/**
|
||||
* Output a console.log message with timestamp
|
||||
*/
|
||||
export const log = (message: string) => console.log(dayjs().format() + ' ' + message)
|
||||
|
||||
/**
|
||||
* Sanitise the data for an incoming query string `size` parameter
|
||||
* e.g. https://example.com/share/abc...xyz?size=thumbnail
|
||||
*/
|
||||
const getSize = (req: Request) => {
|
||||
return req.query?.size === 'thumbnail' ? ImageSize.thumbnail : ImageSize.original
|
||||
}
|
||||
|
||||
const toString = (value: unknown) => {
|
||||
return typeof value === 'string' ? value : ''
|
||||
}
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log(dayjs().format() + ' Server started')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user