• Console DevTools
  • devtools.fm
Readme
Fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Hono } from "https://deno.land/x/hono@v3.11.1/mod.ts";
import { getItunesId, isApplePodcast } from "https://esm.town/v/vladimyr/applePodcast?v=5";
import { getLastPubDate } from "https://esm.town/v/vladimyr/podcast?v=21";
import { getFeedUrl } from "https://esm.town/v/vladimyr/podnews?v=16";
import { getSpotifyId, isSpotifyPodcast } from "https://esm.town/v/vladimyr/spotifyPodcast?v=1";
import { badgen as createBadge, BadgenOptions } from "npm:badgen@3.2.3";
import friendlyTime from "npm:friendly-time@1.1.1";
import ky, { HTTPError } from "npm:ky@1.1.3";
import { withQuery } from "npm:ufo@1.3.2";
const BADGE_LABEL = "last episode";
const app = new Hono();
app.get("/", async (c) => {
const { q: feedUrl, ...query } = c.req.query();
if (!feedUrl) return c.body("");
if (isApplePodcast(feedUrl)) {
return c.redirect(withQuery(`/i/${getItunesId(feedUrl)}`, query));
}
if (isSpotifyPodcast(feedUrl)) {
return c.redirect(withQuery(`/s/${getSpotifyId(feedUrl)}`, query));
}
const badgeOptions = await getBadgeOptions(feedUrl);
if (query.format === "json") {
return c.json({
schemaVersion: 1,
label: badgeOptions.label,
message: badgeOptions.status,
color: badgeOptions.color,
});
}
c.header("Content-Type", "image/svg+xml");
return c.body(createBadge(badgeOptions));
});
app.get("/:service{(?:i(?:tunes)?|s(?:potify)?)}/:podcastId", async (c) => {
const podcastId = c.req.param("podcastId");
const { format, debug } = c.req.query();
const feedUrl = await getFeedUrl({ podcastId });
const badgeOptions = await getBadgeOptions(feedUrl);
if (format === "json") {
const badgeInfo = {
schemaVersion: 1,
label: badgeOptions.label,
message: badgeOptions.status,
color: badgeOptions.color,
};
if (debug) {
Object.assign(badgeInfo, {
_debug: { feedUrl },
});
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.
Comments
stevekrouse avatar

So cool! Coincidentally @just_be of devtools.fm is in our office today!

just_be avatar

This is awesome @vladimyr! Thanks for making it. I'll share it with Andrew, I'm sure he'll get a kick out of it.