1// Convert image URL to base64
2async function getImageBase64(url: string): Promise<string> {
3 const res = await fetch(url);
4 const buffer = await res.arrayBuffer();
5 const base64 = btoa(String.fromCharCode(...new Uint8Array(buffer)));
25});
26
27fetch(`${url}?${searchParams.toString()}`, {
28 method: "GET",
29 headers: {
51 }
52 })
53 .catch(err => console.error("Fetch Error:", err));
16
17 const load = async () => {
18 const res = await fetch("/api/todos");
19 const data: Todo[] = await res.json();
20 setTodos(data);
27 const add = async (e: React.FormEvent) => {
28 e.preventDefault();
29 await fetch("/api/todos", {
30 method: "POST",
31 headers: { "Content-Type": "application/json" },
37
38 const complete = async (id: number) => {
39 await fetch("/api/complete", {
40 method: "POST",
41 headers: { "Content-Type": "application/json" },
23}
24
25// Fetch handler
26export async function GET(): Promise<Response> {
27 const rows = [...db.query("SELECT id, text, last_completed_date FROM todos")]
4app.get("/", (c) => c.text("Hono!"));
5
6export default app.fetch;
1import * as NodeIcal from "npm:node-ical";
2
3type FetchPanchangeOptions = {
4 /** https://www.geonames.org/ */
5 geoname: string;
10};
11
12async function fetchPanchangIcal(options: FetchPanchangeOptions) {
13 const ical = fetch(
14 "https://www.drikpanchang.com/ajax/ical/panchangam/dp-grid-panchangam-ical.php",
15 {
33}
34
35const ical = await fetchPanchangIcal({
36 date_from: "01/07/2025",
37 date_to: "03/07/2025",
1import { MhahPanchang } from "npm:mhah-panchang";
2import { fetchGeolocation } from "https://esm.town/v/mattrossman/geolocation/main.ts";
3
4export default async function (req: Request) {
5 const panchang = new MhahPanchang();
6 const now = new Date();
7 const geolocation = await fetchGeolocation(req);
8 const calendar = panchang.calendar(
9 now,
1# geolocation
2
3A helper function to fetch geolocation data from [ip-api](https://ip-api.com/)
4based on a visitor's IP address
5
6```ts
7import { fetchGeolocation } from "https://esm.town/v/mattrossman/geolocation/main.ts";
8
9export default async function (req: Request) {
10 const geolocation = await fetchGeolocation(req);
11 return new Response(`You're visiting from ${geolocation.city}`);
12}
21};
22
23export async function fetchGeolocation(req: Request) {
24 const ip = await getIp(req);
25 if (ip === undefined) throw new Error(`Missing "x-forwarded-for" header`);
26
27 const json = await fetch(`http://ip-api.com/json/${ip}`).then(
28 (res) => res.json(),
29 ) as IpApiGeolocation;
33
34export default async function (req: Request): Promise<Response> {
35 const geolocation = await fetchGeolocation(req);
36 return Response.json(geolocation);
37}
1import { fetchGeolocation } from "https://esm.town/v/mattrossman/geolocation/main.ts";
2
3export default async function (req: Request) {
4 const geolocation = await fetchGeolocation(req);
5 return new Response(`Hello from ${geolocation.city}`);
6}