Release 0.6.1
This commit is contained in:
1 parent
b80dded55d
commit
d586fbd8ce
29 files changed
+398
-66
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { error, fail } from '@sveltejs/kit';
|
||||
import type { Actions, PageServerLoad } from './$types';
|
||||
import { requireUser } from '#lib/server/auth.js';
|
||||
import { requireBarkeeper, requireUser } from '#lib/server/auth.js';
|
||||
import { finalizeShow, getCompletionSummary } from '#lib/server/completion.js';
|
||||
import {
|
||||
completeCurrent,
|
||||
@@ -25,6 +25,8 @@ import {
|
||||
startOrResumeLive
|
||||
} from '#lib/server/live.js';
|
||||
import { listShows } from '#lib/server/shows.js';
|
||||
import { createShare, deleteShare, listShares, updateShare } from '#lib/server/shares.js';
|
||||
import { berlinLocalToUtc } from '#lib/server/time.js';
|
||||
|
||||
function text(data: FormData, name: string) {
|
||||
return String(data.get(name) || '');
|
||||
@@ -71,13 +73,15 @@ function attempt(intent: string, operation: () => unknown) {
|
||||
}
|
||||
|
||||
export const load: PageServerLoad = ({ locals, url }) => {
|
||||
requireUser(locals.user);
|
||||
const actor = requireUser(locals.user);
|
||||
const showId = url.searchParams.get('show') || listShows()[0]?.id;
|
||||
if (!showId) error(404, 'Keine Sendung vorhanden');
|
||||
try {
|
||||
const live = getLiveView(showId);
|
||||
return {
|
||||
live,
|
||||
canManageShares: actor.role === 'barkeeper',
|
||||
shares: actor.role === 'barkeeper' ? listShares(actor, showId) : [],
|
||||
commandId: randomUUID(),
|
||||
completion:
|
||||
live.endedAtUtc && live.show.status !== 'completed' ? getCompletionSummary(showId) : null
|
||||
@@ -90,6 +94,45 @@ export const load: PageServerLoad = ({ locals, url }) => {
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
createShare: async ({ locals, request }) => {
|
||||
const actor = requireBarkeeper(locals.user);
|
||||
const data = await request.formData();
|
||||
try {
|
||||
const share = await createShare(actor, {
|
||||
showId: text(data, 'showId'), scope: text(data, 'scope'), password: text(data, 'password'),
|
||||
expiresAtUtc: berlinLocalToUtc(text(data, 'expiresAt'), 'INVALID_EXPIRY')
|
||||
});
|
||||
return { intent: 'createShare', success: 'Leselink angelegt.', shareUrl: `/freigabe/${share.token}` };
|
||||
} catch (cause) {
|
||||
const problem = actionError(cause);
|
||||
return fail(problem.status, { intent: 'createShare', ...problem });
|
||||
}
|
||||
},
|
||||
updateShare: async ({ locals, request }) => {
|
||||
const actor = requireBarkeeper(locals.user);
|
||||
const data = await request.formData();
|
||||
try {
|
||||
await updateShare(actor, text(data, 'shareId'), {
|
||||
scope: text(data, 'scope'), passwordMode: text(data, 'passwordMode'), password: text(data, 'password'),
|
||||
expiresAtUtc: berlinLocalToUtc(text(data, 'expiresAt'), 'INVALID_EXPIRY')
|
||||
}, text(data, 'showId'));
|
||||
return { intent: 'updateShare', success: 'Freigabe aktualisiert.' };
|
||||
} catch (cause) {
|
||||
const problem = actionError(cause);
|
||||
return fail(problem.status, { intent: 'updateShare', ...problem });
|
||||
}
|
||||
},
|
||||
deleteShare: async ({ locals, request }) => {
|
||||
const actor = requireBarkeeper(locals.user);
|
||||
const data = await request.formData();
|
||||
try {
|
||||
deleteShare(actor, text(data, 'shareId'), text(data, 'showId'));
|
||||
return { intent: 'deleteShare', success: 'Freigabe gelöscht.' };
|
||||
} catch (cause) {
|
||||
const problem = actionError(cause);
|
||||
return fail(problem.status, { intent: 'deleteShare', ...problem });
|
||||
}
|
||||
},
|
||||
start: async ({ locals, request }) => {
|
||||
requireUser(locals.user);
|
||||
const data = await request.formData();
|
||||
|
||||
Reference in new issue
Block a user