1
0
Fork 0
mirror of https://github.com/alangrainger/immich-public-proxy.git synced 2024-12-29 12:21:57 +00:00

Update unlock page

This commit is contained in:
Alan Grainger 2024-11-01 12:18:13 +01:00
parent 356d9280d4
commit 77f8225c2f
3 changed files with 22 additions and 15 deletions

View file

@ -24,7 +24,7 @@ html {
} }
#lightgallery img { #lightgallery img {
width: 100%; width: 100%;
height: auto; height: 100%;
object-fit: cover; object-fit: cover;
object-position: center; object-position: center;
} }

View file

@ -37,6 +37,10 @@ class Immich {
if (!sharedLinkRes.valid) { if (!sharedLinkRes.valid) {
// This isn't a valid request - check the console for more information // This isn't a valid request - check the console for more information
res.status(404).send() res.status(404).send()
} else if (sharedLinkRes.passwordRequired && request.password) {
// Invalid password
log('Invalid password for key ' + request.key)
res.status(401).send()
} else if (sharedLinkRes.passwordRequired) { } else if (sharedLinkRes.passwordRequired) {
// Password required - show the visitor the password page // Password required - show the visitor the password page
// `req.params.key` should already be sanitised at this point, but it never hurts to be explicit // `req.params.key` should already be sanitised at this point, but it never hurts to be explicit
@ -159,7 +163,11 @@ class Immich {
params = Object.fromEntries(Object.entries(params).filter(([_, value]) => !!value)) params = Object.fromEntries(Object.entries(params).filter(([_, value]) => !!value))
let query = '' let query = ''
// Safely encode query parameters // Safely encode query parameters
if (Object.entries(params).length) query = '?' + (new URLSearchParams(params as { [key: string]: string })).toString() if (Object.entries(params).length) {
query = '?' + (new URLSearchParams(params as {
[key: string]: string
})).toString()
}
return baseUrl + query return baseUrl + query
} }
@ -167,7 +175,7 @@ class Immich {
* Return the image data URL for a photo * Return the image data URL for a photo
*/ */
photoUrl (key: string, id: string, size?: ImageSize, password?: string) { photoUrl (key: string, id: string, size?: ImageSize, password?: string) {
const params = { key } const params = { key, size }
if (password) { if (password) {
Object.assign(params, encrypt(password)) Object.assign(params, encrypt(password))
} }

View file

@ -41,20 +41,19 @@
</main> </main>
<script src="/web.js"></script> <script src="/web.js"></script>
<script> <script>
function submitForm (formElement) { async function submitForm (formElement) {
const formData = new FormData(formElement) const formData = new FormData(formElement)
try {
fetch('/unlock', { const res = await fetch('/unlock', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(Object.fromEntries(formData.entries())) body: JSON.stringify(Object.fromEntries(formData.entries()))
}) })
.then(response => response.text()) if (res.status === 200) {
.then(html => { document.documentElement.innerHTML = await res.text()
document.documentElement.innerHTML = html
initLightGallery() // from web.js initLightGallery() // from web.js
}) }
.catch(error => console.error('Error:', error)) } catch (e) { }
} }
document.getElementById('unlock') document.getElementById('unlock')