35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
39 headers: {
50
51async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53 method: "POST",
54 headers: {
11
12 useEffect(() => {
13 fetchProposals();
14 const signed = Cookies.get('signedProposals');
15 if (signed) {
18 }, []);
19
20 const fetchProposals = async () => {
21 const response = await fetch('/proposals');
22 const data = await response.json();
23 // Sort proposals by creation date (most recent first)
28 const handleSubmitProposal = async (e) => {
29 e.preventDefault();
30 await fetch('/proposals', {
31 method: 'POST',
32 headers: { 'Content-Type': 'application/json' },
34 });
35 setNewProposal({ title: '', proposer: '', targetCount: 10 });
36 fetchProposals();
37 };
38
46 return;
47 }
48 const response = await fetch(`/proposals/${id}/sign`, {
49 method: 'POST',
50 headers: { 'Content-Type': 'application/json' },
58 }
59 setSignature('');
60 fetchProposals();
61 };
62
63 const handleCancelSignature = async (id, name) => {
64 const response = await fetch(`/proposals/${id}/cancel`, {
65 method: 'POST',
66 headers: { 'Content-Type': 'application/json' },
72 setSignedProposals(newSignedProposals);
73 Cookies.set('signedProposals', JSON.stringify(Array.from(newSignedProposals)));
74 fetchProposals();
75 }
76 };
159 const query = searchInput.value.trim();
160 if (query.length > 0) {
161 fetchResults(query);
162 } else {
163 searchResults.style.display = 'none';
166 });
167
168 async function fetchResults(query) {
169 try {
170 const response = await fetch(\`/search?q=\${encodeURIComponent(query)}\`);
171 const results = await response.json();
172 displayResults(results);
173 } catch (error) {
174 console.error('Error fetching results:', error);
175 }
176 }
200`;
201
202export default app.fetch.bind(app);
55}
56
57// Link Fetching Helper
58export class LinkFetcher {
59 static async fetchLinksFromWebsite(websiteUrl) {
60 console.log(`\nFetching links from website: ${websiteUrl}`);
61 const query = `
62 SELECT
72
73 console.log("Making LSD API request...");
74 const response = await fetch(
75 `https://lsd.so/api?query=${encodeURIComponent(query)}`,
76 );
77
78 if (!response.ok) {
79 console.log("Failed to fetch links from LSD API");
80 throw new Error("Failed to fetch links from website");
81 }
82
149 try {
150 console.log(`Attempting HEAD request for: ${url}`);
151 const response = await fetch(url, { method: "HEAD" });
152
153 if (!response.ok) {
154 console.log(`HEAD request failed, attempting GET request for: ${url}`);
155 const getResponse = await fetch(url, { method: "GET" });
156 return { ok: getResponse.ok, status: getResponse.status };
157 }
253 console.log(`Starting findBrokenLinks for website: ${websiteUrl}`);
254
255 // Fetch all links
256 const links = await LinkFetcher.fetchLinksFromWebsite(websiteUrl);
257
258 // Check links
14
15 useEffect(() => {
16 fetchWallets();
17 }, []);
18
19 async function fetchWallets() {
20 try {
21 const response = await fetch(`${API_URL}/wallets`);
22 const data = await response.json();
23 setWallets(data);
24 } catch (err) {
25 console.error("Error fetching wallets:", err);
26 setWallets([]);
27 setError("Failed to fetch wallets. Please try again later.");
28 }
29 }
31 async function createWallet() {
32 try {
33 const response = await fetch(`${API_URL}/create-wallet`, { method: "POST" });
34 const { key, hash } = await response.json();
35 const newWalletData = { key, hash, value: 0 };
67
68 try {
69 const response = await fetch(`${API_URL}/transfer`, {
70 method: "POST",
71 headers: { "Content-Type": "application/json" },
79 message: "Transfer successful!",
80 });
81 fetchWallets();
82 setSourceKey("");
83 setDestinationHash("");
1/**
2 * This val creates a website to count lines of code in GitHub repositories.
3 * It uses a server-side API to fetch the data and a client-side UI for user interaction.
4 * It now includes sharing functionality and URL manipulation for better user experience.
5 */
185
186 try {
187 const response = await fetch(`/api/${user}/${repo}`);
188 const data = await response.json();
189
315});
316
317export default app.fetch;
74});
75
76export default app.fetch;
1/** @jsxImportSource https://esm.sh/hono@4.0.8/jsx **/
2
3import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
4import view_route from "https://esm.town/v/pomdtr/blob_admin_blob";
5import create_route from "https://esm.town/v/pomdtr/blob_admin_create";
137});
138
139export default modifyFetchHandler(passwordAuth(app.fetch));
9## What It Does
10
11This simple tool fetches the GitHub repository as a ZIP file,
12decompresses it on the fly (thanks to `fflate` 💨),
13and counts the lines of code — on val.town
5 const repo = `${username}/${repoName}`;
6 const url = `https://github.com/${repo}/archive/refs/heads/master.zip`;
7 fetch(url)
8 .then((res) => {
9 if (!res.ok || !res.body) return reject(new Error(`HTTP error! status: ${res.status}`));