From e06d1c6e4447d3c541bd24a3daefb6fe5096e4bd Mon Sep 17 00:00:00 2001 From: Darius Date: Tue, 3 Feb 2026 22:12:26 +0100 Subject: [PATCH] fix set volume route and formatting --- src/tidal/routes.ts | 244 ++++++++++++++++++++++---------------------- 1 file changed, 123 insertions(+), 121 deletions(-) diff --git a/src/tidal/routes.ts b/src/tidal/routes.ts index 20fe496..26ca67e 100644 --- a/src/tidal/routes.ts +++ b/src/tidal/routes.ts @@ -3,137 +3,139 @@ 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; - }, + fastify: FastifyInstance, + { + tidalService, + verifyAPIKey, + }: { + tidalService: TidalService; + verifyAPIKey: ( + request: FastifyRequest, + reply: FastifyReply, + ) => Promise; + }, ) { - 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(); + 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 }; - } + if (!service_result.successful) { + reply.code(418); + return { error: service_result.result }; + } - return 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(); + 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 }; - } + if (!service_result.successful) { + reply.code(418); + return { error: service_result.result }; + } - return 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(); + 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 }; - } + if (!service_result.successful) { + reply.code(418); + return { error: service_result.result }; + } - return 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); + fastify.post( + "/tidal/volume", + { + preHandler: verifyAPIKey, + schema: { + description: + "Set volume level (accepts absolute number or relative +/- value)", + tags: ["tidal"], + body: z.object({ + volume: 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 }; - } + if (!service_result.successful) { + reply.code(418); + return { error: service_result.result }; + } - return service_result.result; - }, - ); + return service_result.result; + }, + ); }