Build and Push Docker Image / build-and-push (push) Successful in 6m47s
- Admin: sign-up Open / Invite only / Closed with single-use invite links - Present mode for scripts (auto-scroll) and outlines (step through, pace vs planned minutes) - Series: group studies on the dashboard, filter by series, calendar file for a study's sessions - Lesson handout: printable page per session (passage, outline, questions, writing lines) - Save a chunk's notes as your own study template (synced) - Voice dictation for notes and scripts (browser speech recognition) - Reading progress: map of the 66 books and a calendar of days read, synced and merged across devices - Export highlights and bookmarks as Markdown or Word, grouped by named colour - Verse of the day push to the ntfy topic (needs IQBIBLE_API_KEY) - Sharing: co-teacher editing via single-use invite links; read-only links can expire and take a passcode Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
28 lines
1.4 KiB
JavaScript
28 lines
1.4 KiB
JavaScript
// The rules for a read-only link: it can expire, and it can need a passcode. Kept separate from the routes
|
|
// so they can be tested on their own.
|
|
import bcrypt from 'bcryptjs';
|
|
|
|
export const MAX_PASSCODE = 100;
|
|
|
|
// "never" (null/0) or a number of days, up to a year -> an expiry time in ms (or null)
|
|
export function expiryFromDays(days, now = Date.now()) {
|
|
const n = Number(days);
|
|
if (!days || !Number.isFinite(n) || n <= 0) return null;
|
|
return now + Math.min(365, Math.round(n)) * 86_400_000;
|
|
}
|
|
|
|
export async function hashPasscode(passcode) {
|
|
const p = String(passcode ?? '').slice(0, MAX_PASSCODE);
|
|
return p.trim() ? bcrypt.hash(p.trim(), 10) : null;
|
|
}
|
|
|
|
// -> { ok: true } | { ok: false, status: 410, error } (expired) | { ok: false, status: 401, needsPasscode: true, error }
|
|
export async function checkShareAccess({ expiresAt, passHash, supplied }, now = Date.now()) {
|
|
if (expiresAt && expiresAt <= now) return { ok: false, status: 410, error: 'This link has expired. Ask the person who shared it for a new one.' };
|
|
if (!passHash) return { ok: true };
|
|
const given = String(supplied ?? '').slice(0, MAX_PASSCODE).trim();
|
|
if (!given) return { ok: false, status: 401, needsPasscode: true, error: 'This link needs a passcode.' };
|
|
if (!(await bcrypt.compare(given, passHash))) return { ok: false, status: 401, needsPasscode: true, error: 'That passcode is not right.' };
|
|
return { ok: true };
|
|
}
|