Avatar

u

20 public vals
Joined April 10, 2023
1
2
3
export async function handlePlexWebhook(req: Request) {
console.log(await req.text());
}
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const regex = {
"'": /\\'/g,
"\"": /\\"/g,
};
function parse(str: string) {
var i = 0;
var parts = [];
var dot, bracket, quote, closing;
while (i < str.length) {
dot = str.indexOf(".", i);
bracket = str.indexOf("[", i);
// we've reached the end
if (dot === -1 && bracket === -1) {
parts.push(str.slice(i, str.length));
i = str.length;
}
// dots
else if (bracket === -1 || (dot !== -1 && dot < bracket)) {
parts.push(str.slice(i, dot));
i = dot + 1;
}
// brackets
else {
if (bracket > i) {
parts.push(str.slice(i, bracket));
i = bracket;
}
quote = str.slice(bracket + 1, bracket + 2);
if (quote !== "\"" && quote !== "'") {
closing = str.indexOf("]", bracket);
if (closing === -1) {
closing = str.length;
}
parts.push(str.slice(i + 1, closing));
i = str.slice(closing + 1, closing + 2) === "."
? closing + 2
: closing + 1;
} else {
closing = str.indexOf(quote + "]", bracket);
if (closing === -1) {
closing = str.length;
}
while (
str.slice(closing - 1, closing) === "\\"
&& bracket < str.length
) {
bracket++;
closing = str.indexOf(quote + "]", bracket);
}
parts.push(
str
.slice(i + 2, closing)
.replace(regex[quote], quote)
.replace(/\\+/g, function(backslash) {
return new Array(Math.ceil(backslash.length / 2) + 1).join("\\");
}),
);
i = str.slice(closing + 2, closing + 3) === "."
? closing + 3
: closing + 2;
}
}
}
return parts;
}
function degron(txt: string) {
const lines = txt.trim().split("\n");
const initializer = lines.shift()?.split(" = ")[1]; // initializer line
const state = initializer === "[]"
? []
: initializer === "{}"
? {}
: (() => {
throw new Error("Unexpected json initializer: " + initializer);
})();
for (const line of txt.trim().split("\n")) {
const [lhs, rhs] = line.split(" = ");
if (!lhs.startsWith("json")) throw new Error("doesn't start with json");
let curr: any = state;
const parsedPath = parse(lhs);
parsedPath.shift(); // drop json.
for (let i = 0; i < parsedPath.length - 1; i++) {
curr = curr[parsedPath[i]];
}
curr[parsedPath.at(-1)!] = JSON.parse(rhs);
}
return state;
}
type NameStack = (
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { gron } from "https://esm.town/v/u/gron";
export default async function untitled_roseClownfish(req: Request): Promise<Response> {
let url: URL;
try {
url = new URL(new URL(req.url).searchParams.get("url"));
}
catch {
return new Response(
"<html><body>Not a valid URL - " + new URL(req.url).search
+ "</body></html>",
{
headers: {
"Content-Type": "text/html",
},
},
);
}
return new Response(gron(await (await fetch(url)).json()));
}
1
2
export function schema(req, res) {
}
1
2
3
4
5
import { fetch } from "https://esm.town/v/std/fetch";
export async function json(url: string): Promise<any> {
return await (await fetch(url)).json();
}
1
2
3
4
import { msPerHour } from "https://esm.town/v/u/msPerHour";
import { hourPerDay } from "https://esm.town/v/u/hourPerDay";
export let msPerDay = hourPerDay * msPerHour;
1
2
3
4
import { secPerHour } from "https://esm.town/v/u/secPerHour";
import { hourPerDay } from "https://esm.town/v/u/hourPerDay";
export let secPerDay = hourPerDay * secPerHour;
1
2
3
4
import { minPerHour } from "https://esm.town/v/u/minPerHour";
import { hourPerDay } from "https://esm.town/v/u/hourPerDay";
export let minPerDay = hourPerDay * minPerHour;
1
export let hourPerDay = 24;
1
2
3
4
import { minPerHour } from "https://esm.town/v/u/minPerHour";
import { msPerMin } from "https://esm.town/v/u/msPerMin";
export let msPerHour = msPerMin * minPerHour;