From 380b037add75459111180f6e9001680b5d4460fd Mon Sep 17 00:00:00 2001 From: "prompt.ac/@jeffrey" Date: Fri, 7 Aug 2026 12:31:03 -0700 Subject: [PATCH] Give the logo endpoint named pals and turnarounds --- system/backend/logo.mjs | 17 ++++++++--- system/netlify/functions/logo.js | 50 ++++++++++++++++++++++++++------ 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/system/backend/logo.mjs b/system/backend/logo.mjs index c06fbb47b4..e3f36dc7cd 100644 --- a/system/backend/logo.mjs +++ b/system/backend/logo.mjs @@ -4,7 +4,7 @@ // insta / natural trays), authored via marketing/podcast/bin/gen-pals.mjs and // hosted in the pals-aesthetic-computer DO Space. -const slugs = [ +export const logoSlugs = [ "pals-av-amethyst.png", "pals-av-balloon.png", "pals-av-chrome-cool.png", @@ -56,7 +56,16 @@ const slugs = [ "pals-wood.png", ]; -export function logoUrl() { - const i = Math.floor(Math.random() * slugs.length); - return `https://pals-aesthetic-computer.sfo3.cdn.digitaloceanspaces.com/${slugs[i]}`; +export const turnaroundSlugs = ["nat-amethyst"]; + +export function logoUrl(slug = null) { + const file = slug ? `pals-${slug}.png` : logoSlugs[Math.floor(Math.random() * logoSlugs.length)]; + if (!logoSlugs.includes(file)) return null; + return `https://pals-aesthetic-computer.sfo3.cdn.digitaloceanspaces.com/${file}`; +} + +export function turnaroundUrl(slug = null, format = "webp") { + const selected = slug || turnaroundSlugs[Math.floor(Math.random() * turnaroundSlugs.length)]; + if (!turnaroundSlugs.includes(selected) || !["mp4", "webp"].includes(format)) return null; + return `https://art.aesthetic.computer/pals/turnarounds/v1/${selected}.${format}`; } diff --git a/system/netlify/functions/logo.js b/system/netlify/functions/logo.js index 269ca7ada2..b8008541e1 100644 --- a/system/netlify/functions/logo.js +++ b/system/netlify/functions/logo.js @@ -8,13 +8,44 @@ #endregion */ import { respond } from "../../backend/http.mjs"; -import { logoUrl } from "../../backend/logo.mjs"; +import { logoUrl, turnaroundUrl } from "../../backend/logo.mjs"; export async function handler(event, context) { // Make sure this is a GET request - if (event.httpMethod !== "GET") { - return respond(405, { error: "Wrong request type." }); - } + if (event.httpMethod !== "GET") { + return respond(405, { error: "Wrong request type." }); + } + + const assetPath = event.path + .replace(/^\/api\/logo\/?/, "") + .replace(/^\//, ""); + const namedTurnaround = assetPath.match(/^(?:pals-)?([a-z0-9-]+)\.(mp4|webp)$/); + const turnaroundAlias = assetPath.match(/^(?:turnaround|random|auth0)\.(mp4|webp)$/); + const namedStill = assetPath.match(/^pals-([a-z0-9-]+)\.png$/); + + const canonicalAsset = turnaroundAlias + ? turnaroundUrl(null, turnaroundAlias[1]) + : namedTurnaround + ? turnaroundUrl(namedTurnaround[1], namedTurnaround[2]) + : namedStill + ? logoUrl(namedStill[1]) + : null; + + if ((namedTurnaround || turnaroundAlias || namedStill) && !canonicalAsset) { + return respond(404, { error: "Pal not found." }); + } + + if (canonicalAsset) { + return { + statusCode: 302, + headers: { + Location: canonicalAsset, + "Access-Control-Allow-Origin": "*", + "Cache-Control": "public, max-age=300", + }, + body: "", + }; + } const { got } = await import("got"); @@ -55,11 +86,12 @@ export async function handler(event, context) { body: base64Logo, isBase64Encoded: true, }; - } else { - const htmlResponse = ` + } else { + const turnaround = turnaroundUrl(); + const htmlResponse = ` - + - +