Ability to remove a bonob registration from sonos (#16)

This commit is contained in:
Simon J
2021-08-07 20:11:02 +10:00
committed by GitHub
parent 55a362e01b
commit 20bcf5524f
7 changed files with 319 additions and 72 deletions

View File

@@ -12,7 +12,8 @@ import {
PRESENTATION_MAP_ROUTE,
SONOS_RECOMMENDED_IMAGE_SIZES,
LOGIN_ROUTE,
REGISTER_ROUTE,
CREATE_REGISTRATION_ROUTE,
REMOVE_REGISTRATION_ROUTE
} from "./smapi";
import { LinkCodes, InMemoryLinkCodes } from "./link_codes";
import { MusicService, isSuccess } from "./music_service";
@@ -95,7 +96,8 @@ function server(
services,
bonobService: service,
registeredBonobService,
registerRoute: bonobUrl.append({ pathname: REGISTER_ROUTE }).pathname(),
createRegistrationRoute: bonobUrl.append({ pathname: CREATE_REGISTRATION_ROUTE }).pathname(),
removeRegistrationRoute: bonobUrl.append({ pathname: REMOVE_REGISTRATION_ROUTE }).pathname(),
});
}
);
@@ -110,7 +112,7 @@ function server(
});
});
app.post(REGISTER_ROUTE, (_, res) => {
app.post(CREATE_REGISTRATION_ROUTE, (_, res) => {
sonos.register(service).then((success) => {
if (success) {
res.render("success", {
@@ -124,6 +126,20 @@ function server(
});
});
app.post(REMOVE_REGISTRATION_ROUTE, (_, res) => {
sonos.remove(service.sid).then((success) => {
if (success) {
res.render("success", {
message: `Successfully removed registration`,
});
} else {
res.status(500).render("failure", {
message: `Failed to remove registration!`,
});
}
});
});
app.get(LOGIN_ROUTE, (req, res) => {
res.render("login", {
bonobService: service,