Dough Git

commit

aaaa

commit
a1e1a4da7495a3d105dd00bffd4c041aebb7d1d3
author
Clove Twilight <[email protected]>
date
2026-07-13 00:56

diff --git a/assets/capes/1bd448116a6e4912ab6772849bc89018.png b/assets/capes/1bd448116a6e4912ab6772849bc89018.png
new file mode 100644
index 0000000..e40d2d8
Binary files /dev/null and b/assets/capes/1bd448116a6e4912ab6772849bc89018.png differ
diff --git a/assets/icon.png b/assets/icon.png
new file mode 100644
index 0000000..fa7ac1b
Binary files /dev/null and b/assets/icon.png differ
diff --git a/src/docs.ts b/src/docs.ts
index b8a83b3..0fddcd1 100644
--- a/src/docs.ts
+++ b/src/docs.ts
@@ -12,6 +12,7 @@ export const DOCS_HTML = `<!doctype html>
 <head>
 <meta charset="utf-8" />
 <meta name="viewport" content="width=device-width, initial-scale=1" />
+<link rel="icon" type="image/png" href="/icon.png" />
 <title>Doughmination API reference</title>
 <style>
   :root {
@@ -255,9 +256,13 @@ var GROUPS = [
     id: "minecraft", name: "Minecraft", blurb: "Skins and Hypixel stats for a Minecraft account.",
     endpoints: [
       { m: "GET", path: "/minecraft/general/:uuid", auth: "public",
-        desc: "A player's Mojang identity: username, UUID (both dashed and short forms), skin and cape texture URLs, the skin's arm model (classic or slim), and a set of ready-to-embed mc-heads render images (face, head, body, player, combo, skin) — each render includes the overlay/hat layer, with _flat variants for the inner skin only. Returns 404 if no Minecraft account has that UUID.",
+        desc: "A player's Mojang identity: username, UUID (both dashed and short forms), skin and cape texture URLs, the skin's arm model (classic or slim), every cape the player has across providers (Minecraft, OptiFine, MinecraftCapes, LabyMod, 5zig, TLauncher, SkinMC — plus a custom 'doughmination' cape for hand-picked accounts) via the capes array, and a set of ready-to-embed mc-heads render images (face, head, body, player, combo, skin) — each render includes the overlay/hat layer, with _flat variants for the inner skin only. Returns 404 if no Minecraft account has that UUID.",
         params: [["uuid", "Minecraft UUID — 32 hex characters, dashes optional."], ["?fresh / ?nocache / ?refresh", "Skip the cache and fetch fresh."]],
-        example: 'GET /minecraft/general/853c80ef3c3749fdaa49938b674adae6  →  { name, uuid, skin_url, cape_url, skin_model, render: { face, face_flat, head, head_flat, body, body_flat, player, player_flat, combo, skin } }' },
+        example: 'GET /minecraft/general/853c80ef3c3749fdaa49938b674adae6  →  { name, uuid, skin_url, cape_url, skin_model, capes: [ { source, cape_url } ], render: { face, head, body, player, combo, skin } }' },
+      { m: "GET", path: "/minecraft/capes", auth: "public",
+        desc: "The accumulated catalogue of vanilla (Mojang) capes the API has seen. It grows over time: every account looked up via /minecraft/general contributes its equipped vanilla cape once, keyed by texture hash. Handy for building up a list of all vanilla capes in circulation.",
+        params: [],
+        example: 'GET /minecraft/capes  →  { count, capes: [ { hash, url, first_seen } ] }' },
       { m: "GET", path: "/minecraft/hypixel/:uuid", auth: "public",
         desc: "A player's Hypixel stats: the full player object (network level and every game's stats — Bedwars, SkyWars, Duels, and the rest) plus their SkyBlock profiles. Always returns 200; the 'source' field tells you whether each section loaded ('ok') or why it's null — 'not_found' if the player has never joined Hypixel, 'unavailable' if this server isn't serving Hypixel data.",
         params: [["uuid", "Minecraft UUID — 32 hex characters, dashes optional."], ["?fresh / ?nocache / ?refresh", "Skip the cache and fetch fresh."]],
diff --git a/src/index.ts b/src/index.ts
index 5e851ed..57e8b86 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -23,12 +23,13 @@ import type {
   UnifiedGirlsMember,
   UnifiedMinecraftGeneral,
   UnifiedMinecraftHypixel,
+  VanillaCapeList,
 } from "./types";
 import { getProfile } from "./profile";
 import { GatewayManager } from "./gateway";
 import { getGuildInvite } from "./guild";
 import { getGirlsResource, isGirlsIdType } from "./girls";
-import { getMinecraftGeneral, getMinecraftHypixel, normalizeMcUuid, MojangUpstreamError } from "./minecraft";
+import { getMinecraftGeneral, getMinecraftHypixel, getVanillaCapeList, normalizeMcUuid, MojangUpstreamError } from "./minecraft";
 import { getContributions } from "./contribapi";
 import { DOCS_HTML } from "./docs";
 import { SystemState } from "./system/do";
@@ -243,6 +244,14 @@ export default {
       }
     }
 
+    // ---- /v2/minecraft/capes  (accumulated vanilla cape catalogue) -------
+    // Grows as accounts are looked up via /general — every vanilla Mojang cape
+    // seen is catalogued once, keyed by texture hash.
+    if (path === "/v2/minecraft/capes") {
+      const data = await getVanillaCapeList(env);
+      return json<VanillaCapeList>({ success: true, data });
+    }
+
     // ---- /v2/minecraft/general/:uuid  (Mojang profile + skin) ------------
     // Just Mojang identity + skin/cape, so callers that only want a skin
     // don't trigger the Hypixel round-trips.
diff --git a/src/minecraft.ts b/src/minecraft.ts
index 3381361..d0205f9 100644
--- a/src/minecraft.ts
+++ b/src/minecraft.ts
@@ -14,14 +14,18 @@
 import type {
   Env,
   MinecraftSourceState,
+  UnifiedCape,
   UnifiedMinecraftGeneral,
   UnifiedMinecraftHypixel,
+  VanillaCapeList,
+  VanillaCapeRegistry,
 } from "./types";
 
 const MOJANG_PROFILE = "https://sessionserver.mojang.com/session/minecraft/profile";
 const HYPIXEL_BASE = "https://api.hypixel.net/v2";
 const CRAFTHEAD = "https://crafthead.net";
 const MCHEADS = "https://mc-heads.net";
+const CAPES_API = "https://api.capes.dev/load";
 const TTL_SECONDS = 300;
 const USER_AGENT = "doughmination-restful/2.0 (+https://doughmination.uk)";
 
@@ -132,6 +136,8 @@ export function isMinecraftUuid(uuid: string): boolean {
 
 const generalKey = (short: string) => `minecraft:general:${short}`;
 const hypixelKey = (short: string) => `minecraft:hypixel:${short}`;
+/** KV key holding the accumulated registry of vanilla cape textures we've seen. */
+const VANILLA_CAPES_KEY = "minecraft:capes:vanilla";
 
 interface MojangTexturePayload {
   textures?: {
@@ -146,6 +152,96 @@ interface MojangProfileResponse {
   properties?: Array<{ name: string; value: string }>;
 }
 
+/** One provider block in a capes.dev /load response. */
+interface CapesDevEntry {
+  type: string;
+  exists: boolean;
+  capeUrl?: string | null;
+}
+
+const DOUGH_BASE_URL = "https://doughmination.uk";
+
+/**
+ * Custom "doughmination" cape for hand-picked accounts. A cape is enabled simply
+ * by dropping a PNG at assets/capes/<uuid>.png (undashed or dashed) — this checks
+ * the ASSETS binding for its existence and, if found, returns a cape entry
+ * pointing at the public URL. Returns null when there's no file (or no binding).
+ */
+async function fetchDoughminationCape(env: Env, short: string): Promise<UnifiedCape | null> {
+  if (!env.ASSETS) return null;
+  const base = env.BASE_URL ?? DOUGH_BASE_URL;
+  for (const id of [short, dash(short)]) {
+    const url = `${base}/capes/${id}.png`;
+    try {
+      const res = await env.ASSETS.fetch(new Request(url, { method: "GET" }));
+      if (res.ok) return { source: "doughmination", cape_url: url };
+    } catch {
+      /* asset lookup failed — treat as no cape */
+    }
+  }
+  return null;
+}
+
+/**
+ * List every cape a player has via capes.dev, which aggregates all the cape
+ * providers (Minecraft, OptiFine, MinecraftCapes, LabyMod, 5zig, TLauncher,
+ * SkinMC). Returns only the providers where a cape actually exists. Best-effort:
+ * any failure yields [] so the general endpoint still succeeds without capes.
+ */
+async function fetchCapes(short: string): Promise<UnifiedCape[]> {
+  try {
+    const res = await fetch(`${CAPES_API}/${short}`, {
+      headers: { Accept: "application/json", "User-Agent": USER_AGENT },
+    });
+    if (!res.ok) return [];
+    const body = (await res.json()) as Record<string, CapesDevEntry>;
+    return Object.values(body)
+      .filter((c) => c && c.exists)
+      .map((c) => ({
+        source: c.type,
+        cape_url: c.capeUrl ?? null,
+      }));
+  } catch {
+    return [];
+  }
+}
+
+/** Pull the stable texture hash out of a textures.minecraft.net cape URL. */
+function capeTextureHash(url: string | null): string | null {
+  return url?.match(/\/texture\/([0-9a-f]+)/i)?.[1]?.toLowerCase() ?? null;
+}
+
+/**
+ * Add a vanilla (Mojang) cape to the shared registry the first time we see it,
+ * so /v2/minecraft/capes builds up a catalogue of every vanilla cape that has
+ * passed through the API. Keyed by texture hash. Best-effort and fire-and-forget:
+ * it reads-modifies-writes a single KV entry, so under heavy concurrency an
+ * occasional new cape could be missed — acceptable for a slowly-growing list.
+ */
+function recordVanillaCape(env: Env, capeUrl: string | null, ctx?: ExecutionContext): void {
+  const hash = capeTextureHash(capeUrl);
+  if (!hash || !capeUrl) return;
+  const work = (async () => {
+    try {
+      const reg =
+        ((await env.PROFILE_CACHE.get(VANILLA_CAPES_KEY, "json")) as VanillaCapeRegistry | null) ?? {};
+      if (reg[hash]) return; // already catalogued
+      reg[hash] = { hash, url: capeUrl, first_seen: Date.now() };
+      await env.PROFILE_CACHE.put(VANILLA_CAPES_KEY, JSON.stringify(reg));
+    } catch {
+      /* registry write failed — non-fatal */
+    }
+  })();
+  if (ctx) ctx.waitUntil(work);
+}
+
+/** The accumulated vanilla-cape catalogue, newest first. */
+export async function getVanillaCapeList(env: Env): Promise<VanillaCapeList> {
+  const reg = ((await env.PROFILE_CACHE.get(VANILLA_CAPES_KEY, "json")) as VanillaCapeRegistry | null) ?? {};
+  const capes = Object.values(reg).sort((a, b) => b.first_seen - a.first_seen);
+  return { count: capes.length, capes };
+}
+
 /** Fetch a Hypixel v2 endpoint and unwrap { success, <key> }.
  *  Returns [value, state] where state explains a null value. */
 async function fetchHypixel<T>(
@@ -194,9 +290,15 @@ export async function getMinecraftGeneral(
   let cape_url: string | null = null;
   let skin_model: "classic" | "slim" | null = null;
 
-  // Throws MojangUpstreamError if every source is blocked/errored; returns null
+  // Profile resolution, cape aggregation, and the custom doughmination cape are
+  // independent upstreams, so fire them together. fetchMojangProfile throws
+  // MojangUpstreamError if every source is blocked/errored, and returns null
   // only on a definitive not-found.
-  const data = await fetchMojangProfile(short);
+  const [data, providerCapes, doughCape] = await Promise.all([
+    fetchMojangProfile(short),
+    fetchCapes(short),
+    fetchDoughminationCape(env, short),
+  ]);
   if (!data) return null;
 
   name = data.name ?? null;
@@ -212,6 +314,12 @@ export async function getMinecraftGeneral(
     }
   }
 
+  // Every vanilla cape we see contributes to the shared registry, so the list at
+  // /v2/minecraft/capes fills in over time. Best-effort, off the response path.
+  recordVanillaCape(env, cape_url, ctx);
+
+  const capes = doughCape ? [...providerCapes, doughCape] : providerCapes;
+
   const result: UnifiedMinecraftGeneral = {
     uuid: dash(short),
     uuid_short: short,
@@ -219,6 +327,7 @@ export async function getMinecraftGeneral(
     skin_url,
     skin_model,
     cape_url,
+    capes,
     // mc-heads renders the overlay (hat/jacket/second layer) by default, so the
     // base URLs include the outer layer; the `_flat` variants append `/nohelm`
     // to drop it and show the inner skin only. `face` is the 2D head, `head`
diff --git a/src/types.ts b/src/types.ts
index fc06f72..0f76fc4 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -9,6 +9,10 @@ export interface Env {
   GATEWAY: DurableObjectNamespace;
   PROFILE_CACHE: KVNamespace;
 
+  /** Cloudflare Static Assets binding (./assets served at root). Used to check
+   *  whether a custom doughmination cape exists at /capes/<uuid>.png. */
+  ASSETS?: Fetcher;
+
   /** Durable Object that runs the Doughmination system API (/v2/plural,
    *  /v2/battery, /v2/system-data) — state store + realtime WebSocket hub. */
   SYSTEM: DurableObjectNamespace;
@@ -422,6 +426,35 @@ export interface UnifiedGirlsMember {
   communication_disabled_until: string | null;
 }
 
+/** One cape a player has, resolved via capes.dev across every cape provider
+ *  it knows (Minecraft, OptiFine, MinecraftCapes, LabyMod, 5zig, TLauncher,
+ *  SkinMC). Only providers where the player actually has a cape are listed. */
+export interface UnifiedCape {
+  /** Provider the cape lives on: "minecraft", "optifine", "labymod", etc. */
+  source: string;
+  /** Raw cape texture PNG. */
+  cape_url: string | null;
+}
+
+/** One vanilla (Mojang) cape in the accumulated registry. */
+export interface VanillaCapeEntry {
+  /** textures.minecraft.net texture hash — the stable id for the cape. */
+  hash: string;
+  /** Full cape texture URL. */
+  url: string;
+  /** Epoch ms when this cape was first catalogued by the API. */
+  first_seen: number;
+}
+
+/** Registry blob stored in KV: texture hash -> entry. */
+export type VanillaCapeRegistry = Record<string, VanillaCapeEntry>;
+
+/** Response for GET /v2/minecraft/capes — the built-up vanilla cape catalogue. */
+export interface VanillaCapeList {
+  count: number;
+  capes: VanillaCapeEntry[];
+}
+
 /** Mojang identity + skin/cape for a Minecraft account
  *  (/v2/minecraft/general/:uuid). */
 export interface UnifiedMinecraftGeneral {
@@ -434,8 +467,12 @@ export interface UnifiedMinecraftGeneral {
   skin_url: string | null;
   /** "classic" (Steve) or "slim" (Alex) arm model; null if unknown. */
   skin_model: "classic" | "slim" | null;
-  /** Raw cape texture file URL; null if the account has no cape. */
+  /** Raw texture URL of the *currently equipped* cape (from Mojang); null if
+   *  none. See `capes` for every cape the player has across providers. */
   cape_url: string | null;
+  /** Every cape the player has, one entry per provider that has one. Empty if
+   *  the player has no capes anywhere (or capes.dev couldn't be reached). */
+  capes: UnifiedCape[];
   /** Ready-to-embed render URLs from the public mc-heads.net proxy. Base URLs
    *  include the overlay (hat/jacket) layer; `_flat` variants show the inner
    *  skin only. */
diff --git a/wrangler.jsonc b/wrangler.jsonc
index ff0b313..73345ec 100644
--- a/wrangler.jsonc
+++ b/wrangler.jsonc
@@ -39,6 +39,17 @@
 			"id": "0ad7fefa9239482a9028c820e4a0cec1"
 		}
 	],
+	// Static assets: everything under ./assets is served at the site root, so
+	// ./assets/capes/<uuid>.png is reachable at /capes/<uuid>.png and
+	// ./assets/icon.png at /icon.png. Unmatched paths fall through to the Worker
+	// router (src/index.ts). The ASSETS binding lets the Worker check whether a
+	// given asset exists (used for doughmination capes).
+	"assets": {
+		"directory": "./assets",
+		"binding": "ASSETS",
+		"html_handling": "none",
+		"not_found_handling": "none"
+	},
 	"triggers": {
 		"crons": [
 			"*/2 * * * *"