1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { blob } from "https://esm.town/v/std/blob";
import { set } from "https://esm.town/v/std/set?v=11";
export default async function(req: Request): Promise<Response> {
const searchParams = new URL(req.url).searchParams;
let value = searchParams.get("todo");
let items = await blob.getJSON("items");
if (value != null) {
console.log("Current contents :", items);
const index = items.indexOf(value);
if (index != -1) {
let updated = items.splice(index, 1);
console.log("Updated : ", updated);
await blob.setJSON("items", items);
return Response.json(items);
}
return Response.json(index);
}
return Response.json(items);
}