Skip to content

Commit 8b01006

Browse files
committed
rm legacy code
1 parent 6cd1287 commit 8b01006

1 file changed

Lines changed: 0 additions & 71 deletions

File tree

http-server/server.js

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -112,75 +112,4 @@ app.post("/", async (req, res) => {
112112
}
113113
});
114114

115-
// XXX LEGACY endpoint, will be removed soon
116-
// POST /devices/:id/leds – set led's of a specific device (pc component, such as mainboard, ram, etc)
117-
// Body example: { color: {red: 100, green: 100, blue: 100 }, mode: "Breathing", ledIndex: X }
118-
app.post("/devices/:id/leds", async (req, res) => {
119-
try {
120-
const requestedDeviceId = parseInt(req.params.id);
121-
if (requestedDeviceId < 0 || Number.isNaN(requestedDeviceId) || requestedDeviceId === undefined) {
122-
return res.status(400).json({ error: "Device index (id) must be greater than 0." });
123-
}
124-
125-
const ledIndex = String(req.body?.ledIndex).toLowerCase() == "x" ? String(req.body?.ledIndex).toLowerCase() : parseInt(req.body?.ledIndex);
126-
if (ledIndex < 0 || Number.isNaN(ledIndex) || ledIndex === undefined) {
127-
return res.status(400).json({ error: "Led index (id) must be greater than 0." });
128-
}
129-
130-
const red = parseInt(req.body?.color?.red);
131-
const green = parseInt(req.body?.color?.green);
132-
const blue = parseInt(req.body?.color?.blue);
133-
if (!(red >= 0 && red <= 255 && green >= 0 && green <= 255 && blue >= 0 && blue <= 255)) {
134-
return res.status(400).json({ error: "Each color must be in the range of 0 to 255." });
135-
}
136-
137-
const deviceData = req.devices.find((device) => device.deviceId == requestedDeviceId);
138-
139-
const mode = req.body?.mode;
140-
const modes = req.devices.find((device) => device.deviceId == requestedDeviceId).modes.map((mode) => mode.name);
141-
if (!modes.map((m) => m.toLowerCase()).includes(mode.toLowerCase())) {
142-
return res.status(400).json({ error: `Wrong mode attribute. Supported modes for device ${requestedDeviceId} are ${modes}` });
143-
}
144-
145-
const ledCount = deviceData.leds?.length;
146-
147-
// Update single led only if index is a number
148-
if (ledIndex !== "x") {
149-
client.updateSingleLed(requestedDeviceId, ledIndex, utils.color(red, green, blue));
150-
await client.updateMode(requestedDeviceId, mode);
151-
return res.status(200).json({ deviceId: requestedDeviceId, deviceName: deviceData.name, leds: ledCount, color: { red: red, green: green, blue: blue }, mode: mode });
152-
}
153-
154-
// Update all led's of the given device if index == "x"
155-
for (let ledIndex = 0; ledIndex < ledCount; ledIndex++) {
156-
client.updateSingleLed(requestedDeviceId, ledIndex, utils.color(red, green, blue));
157-
await client.updateMode(requestedDeviceId, mode);
158-
}
159-
return res.status(200).json({ deviceId: requestedDeviceId, deviceName: deviceData.name, leds: ledCount, color: { red: red, green: green, blue: blue }, mode: mode });
160-
} catch (err) {
161-
console.error(err);
162-
return res.status(500).json({ error: err.message });
163-
}
164-
});
165-
166-
// TODO
167-
// POST /devices/:id/profile – load or save profile
168-
// Body: { profile: name_or_index, save?: boolean }
169-
app.post("/devices/:id/profile", async (req, res) => {
170-
try {
171-
const id = parseInt(req.params.id);
172-
const { profile, save = false } = req.body;
173-
if (save) {
174-
await client.saveProfile(profile, false);
175-
return res.status(200).json({ saved: profile });
176-
} else {
177-
await client.loadProfile(profile, false);
178-
return res.status(200).json({ loaded: profile });
179-
}
180-
} catch (err) {
181-
console.error(err);
182-
return res.status(500).send(err.message);
183-
}
184-
});
185-
186115
app.listen(3000, () => console.log("OpenRGB REST API running at http://localhost:3000"));

0 commit comments

Comments
 (0)