add all needed routes and stuff

This commit is contained in:
Darius
2026-02-05 00:53:23 +01:00
parent bd87929593
commit fd7a80f525
8 changed files with 236 additions and 78 deletions

52
src/homepage/routes.ts Normal file
View File

@@ -0,0 +1,52 @@
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { z } from "zod";
import type { TidalService } from "../tidal/service.js";
import { HomeAssistantService } from "../homeassistant/service.js";
import { HomepageService } from "./service.js";
export async function homepageRoutes(
fastify: FastifyInstance,
{
hpService,
verifyAPIKey,
}: {
hpService: HomepageService
verifyAPIKey: (
request: FastifyRequest,
reply: FastifyReply,
) => Promise<void>;
},
) {
fastify.get(
"/homepage/status",
{
schema: {
description: "Get all current information for dpu status page",
tags: ["homepage"],
response: {
200: z.object({
title: z.string(),
artists: z.string(),
status: z.string(),
current: z.string(),
duration: z.string(),
url: z.string(),
}),
418: z.object({
error: z.string(),
}),
},
},
},
async (_request, reply) => {
const service_result = await hpService.getFullInformation();
if (!service_result.successful) {
reply.code(418);
return { error: service_result.result };
}
return service_result.result;
},
);
}