fix set volume route and formatting
This commit is contained in:
@@ -3,137 +3,139 @@ import { z } from "zod";
|
|||||||
import type { TidalService } from "../tidal/service.js";
|
import type { TidalService } from "../tidal/service.js";
|
||||||
|
|
||||||
export async function tidalRoutes(
|
export async function tidalRoutes(
|
||||||
fastify: FastifyInstance,
|
fastify: FastifyInstance,
|
||||||
{
|
{
|
||||||
tidalService,
|
tidalService,
|
||||||
verifyAPIKey,
|
verifyAPIKey,
|
||||||
}: {
|
}: {
|
||||||
tidalService: TidalService;
|
tidalService: TidalService;
|
||||||
verifyAPIKey: (
|
verifyAPIKey: (
|
||||||
request: FastifyRequest,
|
request: FastifyRequest,
|
||||||
reply: FastifyReply,
|
reply: FastifyReply,
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/tidal/song",
|
"/tidal/song",
|
||||||
{
|
{
|
||||||
schema: {
|
schema: {
|
||||||
description: "Get currently playing song",
|
description: "Get currently playing song",
|
||||||
tags: ["tidal"],
|
tags: ["tidal"],
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
artists: z.string(),
|
artists: z.string(),
|
||||||
status: z.string(),
|
status: z.string(),
|
||||||
current: z.string(),
|
current: z.string(),
|
||||||
duration: z.string(),
|
duration: z.string(),
|
||||||
url: z.string(),
|
url: z.string(),
|
||||||
}),
|
}),
|
||||||
418: z.object({
|
418: z.object({
|
||||||
error: z.string(),
|
error: z.string(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
async (_request, reply) => {
|
async (_request, reply) => {
|
||||||
const service_result = await tidalService.getSong();
|
const service_result = await tidalService.getSong();
|
||||||
|
|
||||||
if (!service_result.successful) {
|
if (!service_result.successful) {
|
||||||
reply.code(418);
|
reply.code(418);
|
||||||
return { error: service_result.result };
|
return { error: service_result.result };
|
||||||
}
|
}
|
||||||
|
|
||||||
return service_result.result;
|
return service_result.result;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/tidal/songFormatted",
|
"/tidal/songFormatted",
|
||||||
{
|
{
|
||||||
schema: {
|
schema: {
|
||||||
description: "Get currently playing song (formatted)",
|
description: "Get currently playing song (formatted)",
|
||||||
tags: ["tidal"],
|
tags: ["tidal"],
|
||||||
response: {
|
response: {
|
||||||
200: z.string(),
|
200: z.string(),
|
||||||
418: z.object({
|
418: z.object({
|
||||||
error: z.string(),
|
error: z.string(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
async (_request, reply) => {
|
async (_request, reply) => {
|
||||||
const service_result = await tidalService.getSongFormatted();
|
const service_result = await tidalService.getSongFormatted();
|
||||||
|
|
||||||
if (!service_result.successful) {
|
if (!service_result.successful) {
|
||||||
reply.code(418);
|
reply.code(418);
|
||||||
return { error: service_result.result };
|
return { error: service_result.result };
|
||||||
}
|
}
|
||||||
|
|
||||||
return service_result.result;
|
return service_result.result;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/tidal/volume",
|
"/tidal/volume",
|
||||||
{
|
{
|
||||||
schema: {
|
schema: {
|
||||||
description: "Get current volume level",
|
description: "Get current volume level",
|
||||||
tags: ["tidal"],
|
tags: ["tidal"],
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
volume: z.number(),
|
volume: z.number(),
|
||||||
}),
|
}),
|
||||||
418: z.object({
|
418: z.object({
|
||||||
error: z.string(),
|
error: z.string(),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
async (_request, reply) => {
|
async (_request, reply) => {
|
||||||
const service_result = await tidalService.getVolume();
|
const service_result = await tidalService.getVolume();
|
||||||
|
|
||||||
if (!service_result.successful) {
|
if (!service_result.successful) {
|
||||||
reply.code(418);
|
reply.code(418);
|
||||||
return { error: service_result.result };
|
return { error: service_result.result };
|
||||||
}
|
}
|
||||||
|
|
||||||
return service_result.result;
|
return service_result.result;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
fastify.post(
|
fastify.post(
|
||||||
"/tidal/volume",
|
"/tidal/volume",
|
||||||
{
|
{
|
||||||
preHandler: verifyAPIKey,
|
preHandler: verifyAPIKey,
|
||||||
schema: {
|
schema: {
|
||||||
description:
|
description:
|
||||||
"Set volume level (accepts absolute number or relative +/- value)",
|
"Set volume level (accepts absolute number or relative +/- value)",
|
||||||
tags: ["tidal"],
|
tags: ["tidal"],
|
||||||
body: z.string(),
|
body: z.object({
|
||||||
response: {
|
volume: z.string(),
|
||||||
200: z.object({
|
}),
|
||||||
volume: z.number(),
|
response: {
|
||||||
}),
|
200: z.object({
|
||||||
401: z.object({
|
volume: z.number(),
|
||||||
error: z.literal("Invalid API key"),
|
}),
|
||||||
}),
|
401: z.object({
|
||||||
418: z.object({
|
error: z.literal("Invalid API key"),
|
||||||
error: z.string(),
|
}),
|
||||||
}),
|
418: z.object({
|
||||||
},
|
error: z.string(),
|
||||||
},
|
}),
|
||||||
},
|
},
|
||||||
async (request, reply) => {
|
},
|
||||||
const volume = request.body as string;
|
},
|
||||||
const service_result = await tidalService.setVolume(volume);
|
async (request, reply) => {
|
||||||
|
const volume = request.body as string;
|
||||||
|
const service_result = await tidalService.setVolume(volume);
|
||||||
|
|
||||||
if (!service_result.successful) {
|
if (!service_result.successful) {
|
||||||
reply.code(418);
|
reply.code(418);
|
||||||
return { error: service_result.result };
|
return { error: service_result.result };
|
||||||
}
|
}
|
||||||
|
|
||||||
return service_result.result;
|
return service_result.result;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user