documentation

This commit is contained in:
Darius
2025-11-22 03:16:54 +01:00
parent e1ca9d8963
commit ce1412f63d
5 changed files with 1084 additions and 114 deletions

139
src/tidal/routes.ts Normal file
View File

@@ -0,0 +1,139 @@
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { z } from "zod";
import type { TidalService } from "../tidal/service.js";
export async function tidalRoutes(
fastify: FastifyInstance,
{
tidalService,
verifyAPIKey,
}: {
tidalService: TidalService;
verifyAPIKey: (
request: FastifyRequest,
reply: FastifyReply,
) => Promise<void>;
},
) {
fastify.get(
"/tidal/song",
{
schema: {
description: "Get currently playing song",
tags: ["tidal"],
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 tidalService.getSong();
if (!service_result.successful) {
reply.code(418);
return { error: service_result.result };
}
return service_result.result;
},
);
fastify.get(
"/tidal/songFormatted",
{
schema: {
description: "Get currently playing song (formatted)",
tags: ["tidal"],
response: {
200: z.string(),
418: z.object({
error: z.string(),
}),
},
},
},
async (_request, reply) => {
const service_result = await tidalService.getSongFormatted();
if (!service_result.successful) {
reply.code(418);
return { error: service_result.result };
}
return service_result.result;
},
);
fastify.get(
"/tidal/volume",
{
schema: {
description: "Get current volume level",
tags: ["tidal"],
response: {
200: z.object({
volume: z.number(),
}),
418: z.object({
error: z.string(),
}),
},
},
},
async (_request, reply) => {
const service_result = await tidalService.getVolume();
if (!service_result.successful) {
reply.code(418);
return { error: service_result.result };
}
return service_result.result;
},
);
fastify.post(
"/tidal/volume",
{
preHandler: verifyAPIKey,
schema: {
description:
"Set volume level (accepts absolute number or relative +/- value)",
tags: ["tidal"],
body: z.string(),
response: {
200: z.object({
volume: z.number(),
}),
401: z.object({
error: z.literal("Invalid API key"),
}),
418: z.object({
error: z.string(),
}),
},
},
},
async (request, reply) => {
const volume = request.body as string;
const service_result = await tidalService.setVolume(volume);
if (!service_result.successful) {
reply.code(418);
return { error: service_result.result };
}
return service_result.result;
},
);
}