23 <head>
24 <title>SQLite Explorer</title>
25 <link rel="preconnect" href="https://fonts.googleapis.com" />
26 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
27 <link
28 href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
29 rel="stylesheet"
30 />
13## Authentication
14
15Login to your SQLite Explorer with [password authentication](https://www.val.town/v/pomdtr/password_auth) with your [Val Town API Token](https://www.val.town/settings/api) as the password.
16
17## Todos / Plans
1null
2
3Migrated from folder: Web_API/jsonBodyParsing
2// it's not working in ValTown or from Airtable's scripting environment.
3// My best guess is that it has something to do with the headers not looking
4// quite right to Substack when we hit their API.
5
6const email = "hello.at.smallworld@gmail.com";
18};
19
20const result = await fetch("https://blog.edgeesmeralda.com/api/v1/free", {
21 "headers": {
22 "content-type": "application/json",
11## Usage
12
13If you want to use an [api token](https://www.val.town/settings/api) to authenticate:
14
15```ts
41```
42
43Note that authenticating using your api token remain an option even after setting a password.
44
45## TODO
61
62async function fetchUser(token: string): Promise<{ id: string }> {
63 const resp = await fetch("https://api.val.town/v1/me", {
64 headers: {
65 Authorization: `Bearer ${token}`,
74}
75
76async function verifyApiToken(token: string) {
77 try {
78 const [currentUser, requestUser] = await Promise.all([fetchUser(Deno.env.get("valtown")), fetchUser(token)]);
92 <article>
93 <p>This val website is <a href="https://www.val.town/v/pomdtr/password_auth">protected by a password</a>.</p>
94 <p>If you are <a href="https://val.town/u/${handle}">@${handle}</a>, you can access it using an <a href="https://www.val.town/settings/api">API token</a>.</p>
95 <p>If not, you'll need to contact the author for access.</p>
96 <footer>
147 const formData = await req.formData();
148 const password = formData.get("password") as string;
149 if (!passwords.includes(password) && !(await verifyApiToken(password))) {
150 return new Response("Unauthorized", {
151 status: 403,
10
11 // fetch data from the server
12 fetch("/api/item")
13 .then((res) => res.json())
14 .then((item) => setItems([...items, item]));
29export default async function (req: Request) {
30 const url = new URL(req.url);
31 if (url.pathname == "/api/item") {
32 return Response.json("This item is fetched from the server by the client");
33 }
1export function myApi(name) {
2 return "hi " + name;
3}
10 if (hash.startsWith("0x0")) {
11 const hash = new URL(url).pathname.split("/").pop();
12 const urlStream = await fetch(`https://api.blobscan.com/blobs/${hash}`);
13 const arrayBuffer = await urlStream.arrayBuffer();
14 const blob = new Blob([arrayBuffer], { type: "application/json" });
16 data.append("file", file);
17 } else {
18 const tx = await fetch(`https://api.blobscan.com/transactions/${hash}`);
19 const txData = await tx.json();
20
22 let folder = "blobs"
23 await Promise.all(txData.blobs.map(async (blob, index) => {
24 const blobStream = await fetch(`https://api.blobscan.com/blobs/${blob}`);
25 const arrayBuffer = await blobStream.arrayBuffer();
26 const blobFile = new Blob([arrayBuffer], { type: "application/json" });
35 console.log(data);
36
37 const response = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", {
38 method: "POST",
39 headers: {
8
91. Click `Fork`
102. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via [nominatim's geocoder API](https://www.val.town/v/stevekrouse/nominatimSearch).
113. Click `Run`
12