1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { fetch } from "https://esm.town/v/std/fetch";
import process from "node:process";
const devices = [
{ apiKey: Deno.env.get("tidbyt_apikey"), id: Deno.env.get("tidbyt_device_id") },
{ apiKey: Deno.env.get("tidbyt_2_api_key"), id: Deno.env.get("tidbyt_2_device_id") },
];
export async function setTidbytImage({ image }: {
image: string;
}) {
const apiKey = Deno.env.get("tidbyt_apikey");
for (let { apiKey, id } of devices) {
const res = await fetch(
`https://api.tidbyt.com/v0/devices/${id}/push`,
{
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
"deviceID": id,
"image": image,
"installationID": "custom",
"background": false,
}),
},
);
if (!res.ok) {
console.error("Error setting tidbyt image:", res.status, await res.text());
}
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
September 12, 2024