1import { fetchPelotonWorkouts } from "https://esm.town/v/andreterron/fetchPelotonWorkouts";
2import { email } from "https://esm.town/v/std/email?v=9";
3import process from "node:process";
5
6export default async function checkTodayWorkout() {
7 const data = await fetchPelotonWorkouts(
8 "3f5bf759bb65494d8b35d26ec72b7340",
9 process.env.pelotonSessionId,
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";
88});
89
90export default modifyFetchHandler(passwordAuth(app.fetch));
2import process from "node:process";
3import { pelotonUserId } from "https://esm.town/v/andreterron/pelotonUserId";
4import { fetchPelotonWorkouts } from "https://esm.town/v/andreterron/fetchPelotonWorkouts";
5
6console.log(await fetchPelotonWorkouts(
7 pelotonUserId,
8 process.env.pelotonSessionId
7
8const getComments = async () => {
9 const response = await fetch(MY_FORKED_VAL_URL);
10 const json = await response.json();
11 return json;
14const addComment = async (str) => {
15 try {
16 const response = await fetch(MY_FORKED_VAL_URL, {
17 method: "POST",
18 body: JSON.stringify(str),
22 return c.text("Added comment!", 200);
23});
24export default app.fetch;
1// SPDX-License-Identifier: 0BSD
2import { fetchVal } from "https://esm.town/v/vladimyr/fetchVal";
3import { formatLicenseInfo, parseLicenseInfo } from "https://esm.town/v/vladimyr/parseLicense";
4import { serveReadme } from "https://esm.town/v/vladimyr/serveReadme";
13 let badgeOptions: BadgenOptions = { label: "license", status: undefined };
14 try {
15 const { code } = await fetchVal(author, name);
16 try {
17 const info = parseLicenseInfo(code);
31});
32
33export default router.fetch;
1import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
2import { modifyFetchHandler } from "https://esm.town/v/vladimyr/codeOnValTown";
3
4const { author, name } = extractValInfo(import.meta.url);
12 </head>
13 <body>
14 <p><code>@vladimyr/codeOnValTown modifyFetchHandler</code> test</p>
15 </body>
16 </html>
20}
21
22// export default modifyFetchHandler(serveHtml, { val: { handle: author, name } });
23export default modifyFetchHandler(serveHtml);
37
38/**
39 * @param handler Fetch handler
40 * @param val Define which val should open
41 */
42export function modifyFetchHandler(
43 handler: RequestHandler,
44 { val, style }: { val?: ValRef; style?: string } = {},
59}
60
61export default modifyFetchHandler;
11Here are 2 different ways to add the "Code on Val Town" ribbon:
12
13### 1. Wrap your fetch handler (recommended)
14
15```ts
16import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=45";
17import { html } from "https://esm.town/v/stevekrouse/html?v=5";
18
19export default modifyFetchHandler(async (req: Request): Promise<Response> => {
20 return html(`<h2>Hello world!</h2>`);
21});
51These functions infer the val using the call stack or the request URL. If the inference isn't working, or if you want to ensure it links to a specific val, pass the `val` argument:
52
53- `modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }})`
54- `modifyHtmlString("<html>...", {val: { handle: "andre", name: "foo" }})`
55
58You can set the style parameter to a css string to customize the ribbon. Check out [github-fork-ribbon-css](https://github.com/simonwhitaker/github-fork-ribbon-css?tab=readme-ov-file#styling) to learn more about how to style the element.
59
60- `modifyFetchHandler(handler, {style: ".github-fork-ribbon:before { background-color: #333; }"})`
61- `modifyHtmlString("<html>...", {style: ".github-fork-ribbon:before { background-color: #333; }"})`
62
64
65```ts
66modifyFetchHandler(handler, {style: `@media (max-width: 768px) {
67 .github-fork-ribbon {
68 display: none !important;
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export default async function fetchBrightDataBalance(
4 token: string,
5): Promise<number> {
6 try {
7 const result = await fetchJSON(
8 "https://api.brightdata.com/customer/balance",
9 {
14 return result.balance - result.pending_costs;
15 } catch (e) {
16 throw new Error(`Could not fetch balance (${e}).`);
17 }
18}