feat(sessions): material downloads unlock when the session ends
Private materials bucket + RLS read gate (admins/own speakers anytime, all attendees after the scheduled slot end, event-local Amsterdam time); always visible uploaded-state, locked download panel, authenticated client downloads, admin signed URLs. 12 new assertions in material_time_lock_tests.sql.
This commit is contained in:
1 parent
a2b87602b4
commit
d4e4637e7c
13 files changed
+334
-30
No files matched your search
@@ -236,10 +236,28 @@ export async function getMyPointsLog(email: string): Promise<PointsLogRow[]> {
|
||||
return data as PointsLogRow[];
|
||||
}
|
||||
|
||||
/** Public URL for a session material stored in the `materials` bucket. */
|
||||
export function sessionMaterialUrl(path: string): string {
|
||||
const { data } = supabase.storage.from('materials').getPublicUrl(path);
|
||||
return data.publicUrl;
|
||||
/** Filename of a material object path (`sessions/<id>/<ts>-<name>`). */
|
||||
export function materialFilename(path: string): string {
|
||||
const base = path.slice(path.lastIndexOf('/') + 1);
|
||||
return base.replace(/^\d+-/, '');
|
||||
}
|
||||
|
||||
/** Download a session material through authenticated storage. The materials
|
||||
* bucket is private and server-side RLS only releases the file to the
|
||||
* session's own speakers/admins at any time, and to everyone else once the
|
||||
* session's scheduled end has passed — so this legitimately fails before the
|
||||
* end for plain attendees even if the UI clock disagrees. */
|
||||
export async function downloadSessionMaterial(path: string): Promise<void> {
|
||||
const { data, error } = await supabase.storage.from('materials').download(path);
|
||||
if (error) throw new ApiError('Download failed — material unlocks when the session ends.');
|
||||
const url = URL.createObjectURL(data);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = materialFilename(path);
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
/** Session ids the signed-in contact is a speaker of (for material upload). */
|
||||
|
||||
Reference in new issue
Block a user