feat: add get remotes in web interface

This commit is contained in:
Fritz Heiden 2025-04-14 23:37:07 +02:00
parent 83ab71f845
commit f83ffac0ce
3 changed files with 21 additions and 3 deletions

View File

@ -1,4 +1,4 @@
function Remote({ id, title, commands } = {}) { function Remote({ id, title, commands = [] } = {}) {
let _id = id; let _id = id;
let _title = title; let _title = title;
let _commands = commands; let _commands = commands;

View File

@ -68,7 +68,11 @@ const Serializer = (function () {
} }
function deserializeRemote(object) { function deserializeRemote(object) {
return new Remote(object); return new Remote({
id: object.id,
title: object.title,
commands: deserializeCommands(object.commands),
});
} }
function deserializeRemotes(objects) { function deserializeRemotes(objects) {

View File

@ -3,7 +3,20 @@ import Serializer from "../data/serializer";
import Net from "../tools/net"; import Net from "../tools/net";
function RemoteService() { function RemoteService() {
let remotes = []; async function getRemote(remoteId) {
let response = await Net.sendRequest({
method: "GET",
url: "/api/remotes/" + remoteId,
});
if (response.status !== 200) {
let responseData = JSON.parse(response.data);
throw new Error(responseData.error);
}
let remoteObject = JSON.parse(response.data);
return Serializer.deserializeRemote(remoteObject);
}
async function getRemotes() { async function getRemotes() {
let response = await Net.sendRequest({ let response = await Net.sendRequest({
@ -92,6 +105,7 @@ function RemoteService() {
} }
return { return {
getRemote,
getRemotes, getRemotes,
createRemote, createRemote,
deleteRemote, deleteRemote,