geschenkgutscheine implementiert ("Paket verschenken"). Neuer Upload-Provider: Sparkbooth.

This commit is contained in:
Codex Agent
2025-12-07 16:54:58 +01:00
parent 3f3c0f1d35
commit 046e2fe3ec
50 changed files with 2422 additions and 130 deletions

View File

@@ -149,13 +149,26 @@ export type PhotoboothStatusMetrics = {
last_upload_at?: string | null;
};
export type SparkboothStatus = {
enabled: boolean;
status: string | null;
username: string | null;
password: string | null;
expires_at: string | null;
upload_url: string | null;
response_format: 'json' | 'xml';
metrics?: PhotoboothStatusMetrics | null;
};
export type PhotoboothStatus = {
mode: 'ftp' | 'sparkbooth';
enabled: boolean;
status: string | null;
username: string | null;
password: string | null;
path: string | null;
ftp_url: string | null;
upload_url: string | null;
expires_at: string | null;
rate_limit_per_minute: number;
ftp: {
@@ -163,6 +176,7 @@ export type PhotoboothStatus = {
port: number;
require_ftps: boolean;
};
sparkbooth?: SparkboothStatus | null;
metrics?: PhotoboothStatusMetrics | null;
};
@@ -1215,13 +1229,34 @@ function normalizePhotoboothStatus(payload: JsonValue): PhotoboothStatus {
};
}
const sparkRaw = (payload.sparkbooth ?? null) as JsonValue | null;
let sparkbooth: SparkboothStatus | null = null;
if (sparkRaw && typeof sparkRaw === 'object') {
sparkbooth = {
enabled: Boolean((sparkRaw as JsonValue).enabled),
status: typeof (sparkRaw as JsonValue).status === 'string' ? (sparkRaw as JsonValue).status : null,
username: typeof (sparkRaw as JsonValue).username === 'string' ? (sparkRaw as JsonValue).username : null,
password: typeof (sparkRaw as JsonValue).password === 'string' ? (sparkRaw as JsonValue).password : null,
expires_at: typeof (sparkRaw as JsonValue).expires_at === 'string' ? (sparkRaw as JsonValue).expires_at : null,
upload_url: typeof (sparkRaw as JsonValue).upload_url === 'string' ? (sparkRaw as JsonValue).upload_url : null,
response_format:
(sparkRaw as JsonValue).response_format === 'xml' ? 'xml' : 'json',
metrics: normalizePhotoboothMetrics((sparkRaw as JsonValue).metrics),
};
}
const modeValue = typeof payload.mode === 'string' && payload.mode === 'sparkbooth' ? 'sparkbooth' : 'ftp';
return {
mode: modeValue,
enabled: Boolean(payload.enabled),
status: typeof payload.status === 'string' ? payload.status : null,
username: typeof payload.username === 'string' ? payload.username : null,
password: typeof payload.password === 'string' ? payload.password : null,
path: typeof payload.path === 'string' ? payload.path : null,
ftp_url: typeof payload.ftp_url === 'string' ? payload.ftp_url : null,
upload_url: typeof payload.upload_url === 'string' ? payload.upload_url : null,
expires_at: typeof payload.expires_at === 'string' ? payload.expires_at : null,
rate_limit_per_minute: Number(payload.rate_limit_per_minute ?? ftp.rate_limit_per_minute ?? 0),
ftp: {
@@ -1229,10 +1264,34 @@ function normalizePhotoboothStatus(payload: JsonValue): PhotoboothStatus {
port: Number(ftp.port ?? payload.ftp_port ?? 0) || 0,
require_ftps: Boolean(ftp.require_ftps ?? payload.require_ftps),
},
sparkbooth,
metrics,
};
}
function normalizePhotoboothMetrics(raw: JsonValue | null | undefined): PhotoboothStatusMetrics | null {
if (!raw || typeof raw !== 'object') {
return null;
}
const record = raw as Record<string, JsonValue>;
const readNumber = (key: string): number | null => {
const value = record[key];
if (value === null || value === undefined) {
return null;
}
const parsed = Number(value);
return Number.isFinite(parsed) ? parsed : null;
};
return {
uploads_last_hour: readNumber('uploads_last_hour') ?? readNumber('last_hour') ?? readNumber('hour'),
uploads_today: readNumber('uploads_today') ?? readNumber('today'),
uploads_total: readNumber('uploads_total') ?? readNumber('total'),
last_upload_at: typeof record.last_upload_at === 'string' ? record.last_upload_at : null,
};
}
async function requestPhotoboothStatus(slug: string, path = '', init: RequestInit = {}, errorMessage = 'Failed to fetch photobooth status'): Promise<PhotoboothStatus> {
const response = await authorizedFetch(`${photoboothEndpoint(slug)}${path}`, init);
const payload = await jsonOrThrow<JsonValue | { data: JsonValue }>(response, errorMessage);
@@ -1648,16 +1707,40 @@ export async function getEventPhotoboothStatus(slug: string): Promise<Photobooth
return requestPhotoboothStatus(slug, '', {}, 'Failed to load photobooth status');
}
export async function enableEventPhotobooth(slug: string): Promise<PhotoboothStatus> {
return requestPhotoboothStatus(slug, '/enable', { method: 'POST' }, 'Failed to enable photobooth access');
export async function enableEventPhotobooth(slug: string, options?: { mode?: 'ftp' | 'sparkbooth' }): Promise<PhotoboothStatus> {
const body = options?.mode ? JSON.stringify({ mode: options.mode }) : undefined;
const headers = body ? { 'Content-Type': 'application/json' } : undefined;
return requestPhotoboothStatus(
slug,
'/enable',
{ method: 'POST', body, headers },
'Failed to enable photobooth access'
);
}
export async function rotateEventPhotobooth(slug: string): Promise<PhotoboothStatus> {
return requestPhotoboothStatus(slug, '/rotate', { method: 'POST' }, 'Failed to rotate credentials');
export async function rotateEventPhotobooth(slug: string, options?: { mode?: 'ftp' | 'sparkbooth' }): Promise<PhotoboothStatus> {
const body = options?.mode ? JSON.stringify({ mode: options.mode }) : undefined;
const headers = body ? { 'Content-Type': 'application/json' } : undefined;
return requestPhotoboothStatus(
slug,
'/rotate',
{ method: 'POST', body, headers },
'Failed to rotate credentials'
);
}
export async function disableEventPhotobooth(slug: string): Promise<PhotoboothStatus> {
return requestPhotoboothStatus(slug, '/disable', { method: 'POST' }, 'Failed to disable photobooth access');
export async function disableEventPhotobooth(slug: string, options?: { mode?: 'ftp' | 'sparkbooth' }): Promise<PhotoboothStatus> {
const body = options?.mode ? JSON.stringify({ mode: options.mode }) : undefined;
const headers = body ? { 'Content-Type': 'application/json' } : undefined;
return requestPhotoboothStatus(
slug,
'/disable',
{ method: 'POST', body, headers },
'Failed to disable photobooth access'
);
}
export async function submitTenantFeedback(payload: {