where('export_token', $token)->where('is_active', true)->firstOrFail(); return response($feed->build($channel), 200, [ 'Content-Type' => 'text/calendar; charset=utf-8', 'Content-Disposition' => 'inline; filename="belegung.ics"', 'Cache-Control' => 'no-cache, max-age=0', ]); } public function health(Request $request): JsonResponse { $token = config('fewo.channels.health_token'); abort_if(blank($token) || ! hash_equals($token, (string) $request->query('token')), 404); $channels = Channel::query()->active()->get()->map(fn (Channel $channel): array => [ 'name' => $channel->name, 'imports' => $channel->importsOccupations(), 'ok' => ! $channel->isStale(), 'last_success_at' => $channel->last_success_at?->toIso8601String(), 'last_error' => $channel->last_error, ]); $openTasks = ChannelTask::query()->open()->count(); $ok = $channels->every(fn (array $channel): bool => $channel['ok']); return response()->json([ 'status' => $ok ? 'ok' : 'degraded', 'open_tasks' => $openTasks, 'channels' => $channels->values(), ], $ok ? 200 : 503); } /** * The automation reports a task as done. The raw body must be signed like the outgoing webhook. */ public function completeTask(Request $request, ChannelTask $task): JsonResponse { $secret = config('fewo.automation.secret'); $signature = (string) $request->header('X-Signature'); abort_if(blank($secret) || ! hash_equals(hash_hmac('sha256', $request->getContent(), $secret), $signature), 403); if ($task->status === ChannelTaskStatus::Open) { $task->complete('Automatisierung'); } return response()->json(['status' => $task->status->value]); } }