add all needed routes and stuff
This commit is contained in:
52
src/homepage/routes.ts
Normal file
52
src/homepage/routes.ts
Normal 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;
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user