change for api route
This commit is contained in:
43
src/index.ts
43
src/index.ts
@@ -37,8 +37,10 @@ const haService = new HomeAssistantService(haClient);
|
||||
const tidalClient = new TidalClient(server.axios.tidal);
|
||||
const tidalService = new TidalService(tidalClient);
|
||||
|
||||
// HOME ASSISTANT
|
||||
server.get("/homeassistant/desk/position", async (_request, reply) => {
|
||||
server.register(
|
||||
async (fastify) => {
|
||||
// HOME ASSISTANT
|
||||
fastify.get("/homeassistant/desk/position", async (_request, reply) => {
|
||||
const result = await haService.getDeskPosition();
|
||||
|
||||
if (!result) {
|
||||
@@ -51,9 +53,9 @@ server.get("/homeassistant/desk/position", async (_request, reply) => {
|
||||
is_standing: result.as_boolean,
|
||||
last_changed: result.last_changed.toReadable(true),
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
server.post(
|
||||
fastify.post(
|
||||
"/homeassistant/desk/stand",
|
||||
{ preHandler: verifyAPIKey },
|
||||
async (_request, reply) => {
|
||||
@@ -66,9 +68,9 @@ server.post(
|
||||
|
||||
return { result };
|
||||
},
|
||||
);
|
||||
);
|
||||
|
||||
server.get("/homeassistant/temperature", async (_request, reply) => {
|
||||
fastify.get("/homeassistant/temperature", async (_request, reply) => {
|
||||
const result = await haService.getTemperatureText();
|
||||
|
||||
if (!result) {
|
||||
@@ -79,10 +81,10 @@ server.get("/homeassistant/temperature", async (_request, reply) => {
|
||||
return {
|
||||
temperature: result,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
// TIDAL
|
||||
server.get("/tidal/song", async (_request, reply) => {
|
||||
// TIDAL
|
||||
fastify.get("/tidal/song", async (_request, reply) => {
|
||||
const result = await tidalService.getSong();
|
||||
|
||||
if (!result) {
|
||||
@@ -91,9 +93,9 @@ server.get("/tidal/song", async (_request, reply) => {
|
||||
}
|
||||
|
||||
return { result };
|
||||
});
|
||||
});
|
||||
|
||||
server.get("/tidal/songFormatted", async (_request, reply) => {
|
||||
fastify.get("/tidal/songFormatted", async (_request, reply) => {
|
||||
const result = await tidalService.getSongFormatted();
|
||||
|
||||
if (!result) {
|
||||
@@ -102,9 +104,9 @@ server.get("/tidal/songFormatted", async (_request, reply) => {
|
||||
}
|
||||
|
||||
return { result };
|
||||
});
|
||||
});
|
||||
|
||||
server.get("/tidal/volume", async (_request, reply) => {
|
||||
fastify.get("/tidal/volume", async (_request, reply) => {
|
||||
const result = await tidalService.getVolume();
|
||||
|
||||
if (!result) {
|
||||
@@ -113,9 +115,9 @@ server.get("/tidal/volume", async (_request, reply) => {
|
||||
}
|
||||
|
||||
return { result };
|
||||
});
|
||||
});
|
||||
|
||||
server.post(
|
||||
fastify.post(
|
||||
"/tidal/volume",
|
||||
{ preHandler: verifyAPIKey },
|
||||
async (request, reply) => {
|
||||
@@ -129,12 +131,15 @@ server.post(
|
||||
|
||||
return { result };
|
||||
},
|
||||
);
|
||||
);
|
||||
|
||||
// Default
|
||||
server.get("/ping", async (_request, _reply) => {
|
||||
// Default
|
||||
fastify.get("/ping", async (_request, _reply) => {
|
||||
return "pong\n";
|
||||
});
|
||||
});
|
||||
},
|
||||
{ prefix: "/api" },
|
||||
);
|
||||
|
||||
server.listen({ port: 8080 }, (err, address) => {
|
||||
if (err) {
|
||||
|
||||
@@ -1,48 +1,48 @@
|
||||
### Simple GET Request
|
||||
GET http://localhost:8080/ping
|
||||
GET http://localhost:8080/api/ping
|
||||
|
||||
###
|
||||
|
||||
#################### HA #######################
|
||||
|
||||
### Simple GET Desk Position
|
||||
GET http://localhost:8080/homeassistant/desk/position
|
||||
GET http://localhost:8080/api/homeassistant/desk/position
|
||||
|
||||
###
|
||||
|
||||
### Simple GET Stand Automation
|
||||
GET http://localhost:8080/homeassistant/desk/stand
|
||||
GET http://localhost:8080/api/homeassistant/desk/stand
|
||||
|
||||
###
|
||||
|
||||
### Simple POST Stand Automation
|
||||
POST http://localhost:8080/homeassistant/desk/stand
|
||||
POST http://localhost:8080/api/homeassistant/desk/stand
|
||||
|
||||
###
|
||||
|
||||
### Simple GET Temps
|
||||
GET http://localhost:8080/homeassistant/temperature
|
||||
GET http://localhost:8080/api/homeassistant/temperature
|
||||
|
||||
###
|
||||
|
||||
#################### TIDAL #######################
|
||||
|
||||
### Simple GET Song
|
||||
GET http://localhost:8080/tidal/song
|
||||
GET http://localhost:8080/api/tidal/song
|
||||
|
||||
###
|
||||
|
||||
### Simple GET Song Formatted
|
||||
GET http://localhost:8080/tidal/songFormatted
|
||||
GET http://localhost:8080/api/tidal/songFormatted
|
||||
|
||||
###
|
||||
|
||||
### Simple GET Volume
|
||||
GET http://localhost:8080/tidal/volume
|
||||
GET http://localhost:8080/api/tidal/volume
|
||||
|
||||
###
|
||||
|
||||
### Simple SET Volume
|
||||
POST http://localhost:8080/tidal/volume
|
||||
POST http://localhost:8080/api/tidal/volume
|
||||
|
||||
###
|
||||
|
||||
Reference in New Issue
Block a user