Add the optional Immich integration and manual gallery push
Immich connections stay server-side with an encrypted API key, albums can be imported, and photos are only sent back when an event's push button is pressed: originals upload once, edited photos re-render, and edits hashes plus checksums skip anything already in Immich. This also lands the accompanying editor, cloud and administration work that was still uncommitted. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
+21
-4
@@ -1,23 +1,40 @@
|
||||
import crypto from 'node:crypto';
|
||||
import { promisify } from 'node:util';
|
||||
import { SESSION_DAYS } from './config.mjs';
|
||||
import { sessions, users } from './db.mjs';
|
||||
|
||||
const KEYLEN = 64;
|
||||
const scrypt = promisify(crypto.scrypt);
|
||||
|
||||
export function hashPassword(password) {
|
||||
export async function hashPassword(password) {
|
||||
const salt = crypto.randomBytes(16);
|
||||
const hash = crypto.scryptSync(password, salt, KEYLEN);
|
||||
const hash = await scrypt(password, salt, KEYLEN);
|
||||
return `scrypt$${salt.toString('hex')}$${hash.toString('hex')}`;
|
||||
}
|
||||
|
||||
export function verifyPassword(password, stored) {
|
||||
export async function verifyPassword(password, stored) {
|
||||
const [scheme, saltHex, hashHex] = String(stored).split('$');
|
||||
if (scheme !== 'scrypt' || !saltHex || !hashHex) return false;
|
||||
const expected = Buffer.from(hashHex, 'hex');
|
||||
const actual = crypto.scryptSync(password, Buffer.from(saltHex, 'hex'), expected.length);
|
||||
const actual = await scrypt(password, Buffer.from(saltHex, 'hex'), expected.length);
|
||||
return expected.length === actual.length && crypto.timingSafeEqual(expected, actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* A fixed hash for addresses that do not exist, so a failed login costs the
|
||||
* same scrypt work as a real one and does not reveal registration by timing.
|
||||
* Built synchronously once at boot; this is not on a request path.
|
||||
*/
|
||||
const DUMMY_HASH = (() => {
|
||||
const salt = crypto.randomBytes(16);
|
||||
const hash = crypto.scryptSync('luminary-timing-equalizer', salt, KEYLEN);
|
||||
return `scrypt$${salt.toString('hex')}$${hash.toString('hex')}`;
|
||||
})();
|
||||
|
||||
export async function spendPasswordCheck(password) {
|
||||
await verifyPassword(password, DUMMY_HASH);
|
||||
}
|
||||
|
||||
export function createSession(userId) {
|
||||
const token = crypto.randomBytes(32).toString('hex');
|
||||
const expiresAt = Date.now() + SESSION_DAYS * 24 * 60 * 60 * 1000;
|
||||
|
||||
Reference in New Issue
Block a user