Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions apps/web/app/api/v1/sessions/[slug]/access/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { beforeEach, describe, expect, mock, test } from "bun:test";

let signedIn: { primaryEmailAddress: { emailAddress: string; verification: { status: string } } } | null = null;
let entitled = false;
let uploaded = true;
let uploaded: Record<string, number> = {};

mock.module("@clerk/nextjs/server", () => ({ currentUser: async () => signedIn }));
mock.module("@/lib/entitlements", () => ({ getEntitlementByEmail: async () => ({ hasEntitlement: entitled, packageBundle: null }) }));
mock.module("@/lib/db", () => ({ sql: () => async () => (uploaded ? [{ duration_s: 1640 }] : []) }));
mock.module("@/lib/db", () => ({ sql: () => async () => Object.entries(uploaded).map(([slug, duration_s]) => ({ slug, duration_s })) }));

const { GET } = await import("./route");
const call = (slug: string) => GET(new Request(`http://x/api/v1/sessions/${slug}/access`), { params: Promise.resolve({ slug }) });
Expand All @@ -15,7 +15,7 @@ const buyer = { primaryEmailAddress: { emailAddress: "a@example.com", verificati
beforeEach(() => {
signedIn = null;
entitled = false;
uploaded = true;
uploaded = { "made-lando-stack": 1640, "look-lit-room": 4200, "look-lit-room-2": 2760, unlisted: 60 };
});

describe("GET /api/v1/sessions/[slug]/access", () => {
Expand All @@ -34,14 +34,37 @@ describe("GET /api/v1/sessions/[slug]/access", () => {
const res = await call("made-lando-stack");
expect(res.status).toBe(200);
expect(res.headers.get("cache-control")).toBe("private, no-store");
expect(await res.json()).toEqual({ email: "a@example.com", session: { poster: "npt:4:00", seconds: 1640 } });
expect(await res.json()).toEqual({ email: "a@example.com", session: { poster: "npt:4:00", seconds: 1640 }, takes: [] });
});
test("a buyer gets no session for a piece without one, or one not uploaded", async () => {
signedIn = buyer;
entitled = true;
expect(await (await call("toast")).json()).toEqual({ email: "a@example.com", session: null });
uploaded = false;
expect(await (await call("made-lando-stack")).json()).toEqual({ email: "a@example.com", session: null });
expect(await (await call("toast")).json()).toEqual({ email: "a@example.com", session: null, takes: [] });
uploaded = {};
expect(await (await call("made-lando-stack")).json()).toEqual({ email: "a@example.com", session: null, takes: [] });
});
test("a buyer gets the later sessions of a piece that are uploaded, in order, and no other slug", async () => {
signedIn = buyer;
entitled = true;
const body = await (await call("look-lit-room")).json();
expect(body.session).toEqual({ poster: "npt:45:00", seconds: 4200 });
expect(body.takes.map((t: { slug: string; seconds: number }) => [t.slug, t.seconds])).toEqual([["look-lit-room-2", 2760]]);
uploaded["look-lit-room-3"] = 2400;
const all = await (await call("look-lit-room")).json();
expect(all.takes.map((t: { slug: string }) => t.slug)).toEqual(["look-lit-room-2", "look-lit-room-3"]);
expect(JSON.stringify(all)).not.toContain("unlisted");
});
test("without a purchase the later sessions are not listed", async () => {
expect(await (await call("look-lit-room")).text()).not.toContain("look-lit-room-2");
signedIn = buyer;
const res = await call("look-lit-room");
expect(res.status).toBe(403);
expect(await res.text()).not.toContain("look-lit-room-2");
});
test("a later session is not a piece of its own", async () => {
signedIn = buyer;
entitled = true;
expect((await call("look-lit-room-2")).status).toBe(404);
});
test("an unknown piece is 404", async () => {
signedIn = buyer;
Expand Down
14 changes: 10 additions & 4 deletions apps/web/app/api/v1/sessions/[slug]/access/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ import { gateSession } from "@/lib/session-access";

export const dynamic = "force-dynamic";

/** What a buyer may open on a piece's page: who they are and, when the piece has an uploaded session, where its preview starts. */
/** What a buyer may open on a piece's page: who they are and, for each of the piece's sessions that is uploaded, where its preview starts. */
export async function GET(_req: Request, { params }: { params: Promise<{ slug: string }> }) {
const gate = await gateSession(await currentUser(), async (email) => (await getEntitlementByEmail(email, WORKSHOP.id)).hasEntitlement);
if (!gate.ok) return error(gate.status, gate.code, gate.message);
const { slug } = await params;
const entry = GALLERY.find((g) => g.slug === slug);
if (!entry) return error(404, "piece.not-found", "No piece with that slug.");
const rows = entry.sessionPoster
? ((await sql()`select duration_s from sessions where workshop_id = ${WORKSHOP.id} and slug = ${slug}`) as { duration_s: number }[])
? ((await sql()`select slug, duration_s from sessions where workshop_id = ${WORKSHOP.id}`) as { slug: string; duration_s: number }[])
: [];
const session = rows[0] && entry.sessionPoster ? { poster: entry.sessionPoster, seconds: rows[0].duration_s } : null;
return Response.json({ email: gate.email, session }, { headers: { "cache-control": "private, no-store" } });
const seconds = new Map(rows.map((r) => [r.slug, r.duration_s]));
const first = seconds.get(slug);
const session = first !== undefined && entry.sessionPoster ? { poster: entry.sessionPoster, seconds: first } : null;
const takes = (entry.takes ?? []).flatMap((t) => {
const length = seconds.get(t.slug);
return length === undefined ? [] : [{ ...t, seconds: length }];
});
return Response.json({ email: gate.email, session, takes }, { headers: { "cache-control": "private, no-store" } });
}
46 changes: 1 addition & 45 deletions apps/web/app/taste-hacking/[piece]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
import { JsonLd } from "@/components/json-ld";
import { SITE } from "@/lib/site";
import { chapterNumber } from "../chapters";
import { Clip } from "../clip";
import { GALLERY } from "../gallery";
import { MaterialNav } from "../material-nav";
import { PieceAccess } from "../piece-access";
import { articleLd, LAYER_ROWS } from "../piece-ld";
import { CHAPTER_BY_LAYER, PIECES, PIECES_PUBLISHED, type Piece, pieceByPath, pieceBySlug, pieceHref } from "../pieces";
import { WORKSHOP } from "../workshop";

Expand Down Expand Up @@ -45,50 +45,6 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
};
}

const LAYER_ROWS = [
{ key: "seVe", name: "Cómo se ve" },
{ key: "seMueve", name: "Cómo se mueve" },
{ key: "estaHecho", name: "Cómo está hecho" },
] as const;

function articleLd(piece: Piece, poster: string) {
const url = `${SITE}${pieceHref(piece)}`;
const layers = LAYER_ROWS.filter((l) => piece.layers[l.key]).map((l) => ({ "@type": "Thing", name: l.name }));
const reference = piece.reference
? [
{
"@type": "CreativeWork",
name: piece.reference.name,
url: piece.reference.url,
author: { "@type": "Organization", name: piece.reference.author },
},
]
: [];
return {
"@context": "https://schema.org",
"@type": "Article",
headline: piece.title,
description: piece.metaDescription,
inLanguage: "es",
image: [`${SITE}${poster}`],
url,
mainEntityOfPage: url,
datePublished: PIECES_PUBLISHED,
author: { "@type": "Person", name: "Railly Hugo", url: "https://railly.dev" },
publisher: { "@type": "Organization", name: "hack0", url: SITE },
about: [...reference, ...layers],
isPartOf: {
"@type": "Event",
name: `${WORKSHOP.title}: ${WORKSHOP.subtitle}`,
startDate: WORKSHOP.startAt,
endDate: WORKSHOP.endAt,
eventAttendanceMode: "https://schema.org/OnlineEventAttendanceMode",
location: { "@type": "VirtualLocation", url: WORKSHOP.luma },
url: `${SITE}/taste-hacking`,
},
};
}

function faqLd(piece: Piece) {
return {
"@context": "https://schema.org",
Expand Down
10 changes: 9 additions & 1 deletion apps/web/app/taste-hacking/gallery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Layer } from "./pieces";

type Take = { slug: string; title: string; poster: string };

type GalleryEntry = {
slug: string;
title: string;
Expand All @@ -12,6 +14,8 @@ type GalleryEntry = {
session?: string;
/** Still shown before the session is played. Set with `session`. */
sessionPoster?: string;
/** Later sessions on the same piece, in order, listed under the first. Each is stored under its own slug. */
takes?: Take[];
/** Paths under /public. Clips are muted loops; `sound` marks a video meant to be played with controls. */
video: string;
poster: string;
Expand Down Expand Up @@ -142,10 +146,14 @@ export const GALLERY: GalleryEntry[] = [
slug: "look-lit-room",
title: "Lit Room",
layer: "look",
original: "https://claude.ai/artifact/D5pdvChFfvxBsvVNb5KNCJ",
original: "https://x.com/felixrieseberg/status/2122036839238492493",
credit: "Felix Rieseberg, Lit Room (2026)",
session: `${material}#look-lit-room`,
sessionPoster: "npt:45:00",
takes: [
{ slug: "look-lit-room-2", title: "Sesión 2 · bordes, objetos y materiales", poster: "npt:30:00" },
{ slug: "look-lit-room-3", title: "Sesión 3 · color, cámara y encuadre 4:5", poster: "npt:25:00" },
],
video: `${dir}/look-lit-room.mp4`,
poster: `${dir}/look-lit-room.webp`,
after: "Una página HTML viva que ilumina su propio cuarto: cambias el CSS del cartel y el escritorio y la pared cambian de color.",
Expand Down
13 changes: 13 additions & 0 deletions apps/web/app/taste-hacking/material/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ function Material({
) : (
<p className="th-cast-fail">La sesión todavía no está subida.</p>
)}
{(g.takes ?? []).map((t) => {
const takeLength = lengths.get(t.slug);
return takeLength ? (
<div key={t.slug} className="th-take">
<div className="th-take-head">
<h4 className="th-take-title">{t.title}</h4>
<span className="th-session-meta">{minutes(takeLength)}</span>
<SessionState slug={t.slug} />
</div>
<SessionPlayer slug={t.slug} title={t.title} poster={t.poster} />
</div>
) : null;
})}
<aside className="th-session-result" aria-label={`Resultado de ${g.title}`}>
<div className="th-piece-clip">
<Clip src={g.video} poster={g.poster} label={`Resultado: ${g.title}`} sound={g.sound} />
Expand Down
21 changes: 18 additions & 3 deletions apps/web/app/taste-hacking/piece-access.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import Link from "next/link";
import { useEffect, useState } from "react";
import { Code } from "./code";
import { SessionPlayer } from "./session-player";
import { SessionState } from "./session-state";
import { CLI } from "./workshop";

type Access = { email: string; session: { poster: string; seconds: number } | null };
type Access = {
email: string;
session: { poster: string; seconds: number } | null;
takes: { slug: string; title: string; poster: string; seconds: number }[];
};
type Checked = { slug: string; access: Access | null };

const MATERIAL = "/taste-hacking/material";
Expand All @@ -18,10 +23,20 @@ function Buyer({ slug, title, access }: { slug: string; title: string; access: A
{access.session ? (
<>
<p className="th-prose">
Entraste como {access.email}. La sesión dura unos {Math.max(1, Math.round(access.session.seconds / 60))} minutos y abre donde la
dejaste.
Entraste como {access.email}. La {access.takes.length ? "primera sesión" : "sesión"} dura unos{" "}
{Math.max(1, Math.round(access.session.seconds / 60))} minutos y abre donde la dejaste.
</p>
<SessionPlayer slug={slug} title={title} poster={access.session.poster} />
{access.takes.map((t) => (
<div key={t.slug} className="th-take">
<div className="th-take-head">
<h3 className="th-take-title">{t.title}</h3>
<span className="th-session-meta">{Math.max(1, Math.round(t.seconds / 60))} min</span>
<SessionState slug={t.slug} />
</div>
<SessionPlayer slug={t.slug} title={t.title} poster={t.poster} />
</div>
))}
</>
) : (
<p className="th-prose">
Expand Down
21 changes: 21 additions & 0 deletions apps/web/app/taste-hacking/piece-ld.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, test } from "bun:test";
import { articleLd } from "./piece-ld";
import { PIECES } from "./pieces";

function referenceAuthor(slug: string) {
const piece = PIECES.find((p) => p.slug === slug);
if (!piece) throw new Error(`No piece ${slug}`);
const about = articleLd(piece, "/poster.webp").about as { "@type": string; author?: { "@type": string; name: string } }[];
return about.find((a) => a["@type"] === "CreativeWork")?.author;
}

describe("articleLd", () => {
test("a reference made by a person is typed Person", () => {
expect(referenceAuthor("look-lit-room")).toEqual({ "@type": "Person", name: "Felix Rieseberg" });
expect(referenceAuthor("motion-family-morph")).toEqual({ "@type": "Person", name: "Benji Taylor" });
});
test("every other reference author stays an Organization", () => {
expect(referenceAuthor("look-liquid-glass")).toEqual({ "@type": "Organization", name: "Apple" });
expect(referenceAuthor("made-lando-stack")).toEqual({ "@type": "Organization", name: "OFF+BRAND" });
});
});
48 changes: 48 additions & 0 deletions apps/web/app/taste-hacking/piece-ld.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { SITE } from "@/lib/site";
import { PIECES_PUBLISHED, type Piece, pieceHref } from "./pieces";
import { WORKSHOP } from "./workshop";

export const LAYER_ROWS = [
{ key: "seVe", name: "Cómo se ve" },
{ key: "seMueve", name: "Cómo se mueve" },
{ key: "estaHecho", name: "Cómo está hecho" },
] as const;

/** Article structured data for a piece page. A reference author is an Organization unless the piece types it as a person. */
export function articleLd(piece: Piece, poster: string) {
const url = `${SITE}${pieceHref(piece)}`;
const layers = LAYER_ROWS.filter((l) => piece.layers[l.key]).map((l) => ({ "@type": "Thing", name: l.name }));
const reference = piece.reference
? [
{
"@type": "CreativeWork",
name: piece.reference.name,
url: piece.reference.url,
author: { "@type": piece.reference.authorType ?? "Organization", name: piece.reference.author },
},
]
: [];
return {
"@context": "https://schema.org",
"@type": "Article",
headline: piece.title,
description: piece.metaDescription,
inLanguage: "es",
image: [`${SITE}${poster}`],
url,
mainEntityOfPage: url,
datePublished: PIECES_PUBLISHED,
author: { "@type": "Person", name: "Railly Hugo", url: "https://railly.dev" },
publisher: { "@type": "Organization", name: "hack0", url: SITE },
about: [...reference, ...layers],
isPartOf: {
"@type": "Event",
name: `${WORKSHOP.title}: ${WORKSHOP.subtitle}`,
startDate: WORKSHOP.startAt,
endDate: WORKSHOP.endAt,
eventAttendanceMode: "https://schema.org/OnlineEventAttendanceMode",
location: { "@type": "VirtualLocation", url: WORKSHOP.luma },
url: `${SITE}/taste-hacking`,
},
};
}
8 changes: 5 additions & 3 deletions apps/web/app/taste-hacking/pieces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type Piece = {
/** 155 characters or fewer. */
metaDescription: string;
/** Null for the specimens built for the promo, which have no outside reference. */
reference: { name: string; author: string; url: string } | null;
reference: { name: string; author: string; authorType?: "Person"; url: string } | null;
layers: {
seVe: string | null;
seMueve: string | null;
Expand Down Expand Up @@ -143,7 +143,8 @@ export const PIECES: Piece[] = [
reference: {
name: "Lit Room",
author: "Felix Rieseberg",
url: "https://claude.ai/artifact/D5pdvChFfvxBsvVNb5KNCJ",
authorType: "Person",
url: "https://x.com/felixrieseberg/status/2122036839238492493",
},
layers: {
seVe: "Un escritorio de noche donde la pantalla es la única luz. Deja un charco cálido delante del monitor, sombras suaves, madera barnizada y una pared que toma el color del cartel. Encima van profundidad de campo, viñeta y grain.",
Expand Down Expand Up @@ -196,7 +197,7 @@ export const PIECES: Piece[] = [
],
lesson: "Una pantalla en un cuarto oscuro es una luz. El look aparece cuando los pixeles de la página iluminan la escena.",
paidTeaser:
"La pieza tomó tres sesiones. La que se abre aquí es la primera, de la captura de la referencia al cuarto funcionando con dos rondas de crítica, en unos 70 minutos.",
"La pieza tomó tres sesiones y aquí se abren las tres. La primera va de la captura de la referencia al cuarto funcionando con dos rondas de crítica, en unos 70 minutos. La segunda cierra bordes, objetos y materiales en unos 46. La tercera ajusta el color, la cámara y el encuadre 4:5 en unos 40.",
faq: [
{
q: "¿En qué navegadores funciona esta pieza?",
Expand Down Expand Up @@ -271,6 +272,7 @@ export const PIECES: Piece[] = [
reference: {
name: "Family Values",
author: "Benji Taylor",
authorType: "Person",
url: "https://benji.org/family-values",
},
layers: {
Expand Down
23 changes: 23 additions & 0 deletions apps/web/app/taste-hacking/taste-hacking.css
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,21 @@ html:has(.th) {
margin-left: auto;
font-variant-numeric: tabular-nums;
}
.th-take {
margin-top: 24px;
}
.th-take-head {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 4px 12px;
padding-bottom: 10px;
}
.th-take-title {
font-size: var(--t-small);
font-weight: 800;
letter-spacing: -0.01em;
}
.th-session-result {
display: grid;
grid-template-columns: var(--m-result) minmax(0, 1fr);
Expand Down Expand Up @@ -2318,6 +2333,14 @@ html:has(.th) {
.th-paid-open h3 {
margin-top: 48px;
}
.th-paid-open > .th-take {
max-width: none;
margin-top: 32px;
}
.th-paid-open .th-take-title {
margin-top: 0;
font-size: var(--t-small);
}
.th-read-nav {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
Expand Down
Loading