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
22 <head>
23 <title>SQLite Explorer</title>
24 <link rel="preconnect" href="https://fonts.googleapis.com" />
25 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
26 <link
27 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"
28 rel="stylesheet"
29 />
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
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)]);
146 const formData = await req.formData();
147 const password = formData.get("password") as string;
148 if (!passwords.includes(password) && !(await verifyApiToken(password))) {
149 return new Response("Unauthorized", {
150 status: 403,
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 is always an option.
44
45## TODO
15```
16
17If you want to use an [api token](https://www.val.town/settings/api) to authenticate:
18
19```ts
1import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
2export function getMainExport(
3 mod: any,
35export async function set(path: string, value: any) {
36 let resolveResp = await fetch(
37 `${API_URL}/v1/alias/${path}`,
38 {
39 headers: {
48 const { id } = await resolveResp.json();
49 let resp = await fetch(
50 `${API_URL}/v1/vals/${id}/versions`,
51 {
52 method: "POST",
19
20export async function createScreenshot(code: string, theme: string = "dark-plus"): Promise<URL> {
21 const apiUrl = "https://sourcecodeshots.com/api/image/permalink";
22 const { url } = await ky.post(apiUrl, {
23 json: {
24 code,
30
31export async function fetchPackageData(scope: string, name: string) {
32 const prefixUrl = "https://api.jsr.io/";
33 const data = await ky.get(`scopes/${scope}/packages/${name}`, { prefixUrl }).json();
34 return v.parse(PackageDataSchema, data);