0e4c2ebef4
Squash-merge the cloudflare-migration branch (7 commits by Kai ki) into staging with conflict resolution, feature integration, and bug fixes. Engine: - Paradigm D: single-stream Writer replacing dual-phase Plan/Beats - Delete Architect agent; story bible generated via Writer <plan> tag - Modular prompt architecture (segments/registry/builder) - StreamRouter for tagged stream splitting (<plan>/<story>/<choices>) Infrastructure: - Cloudflare Workers deployment (wrangler.jsonc, OpenNext adapter) - D1 database schema + Drizzle ORM (scaffolded, not yet active) - R2 storage helpers (scaffolded, not yet active) - Story persistence API routes + client-side persistence BYOK (Bring Your Own Key): - /api/llm/user-proxy with SSRF-protected LLM proxy (+ requireUser auth) - CORS-aware fetch in ai-client: auto-detect CORS failure, fallback to server proxy transparently via OpenAI SDK custom fetch - BYO config support added to classify-freeform and vision routes - SettingsModal CORS privacy notice (keys never logged/stored) SSE streaming: - engineClient.ts: fetchSSE helper for progressive scene events - startSession/requestScene accept optional emit callback - Fix SSE error event field name (error → message) in scene/start routes i18n integration: - Wire buildLanguageDirective into paradigm D's prompt builder - Update corsNotice i18n keys (zh-CN/en/ja) with CORS proxy privacy text - Preserve Session.language + LanguageSwitcher from i18n commit Co-authored-by: Kai ki <155355644+zbf1009@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
46 lines
1.5 KiB
TypeScript
46 lines
1.5 KiB
TypeScript
import "server-only";
|
|
|
|
import { eq, and, sql } from "drizzle-orm";
|
|
import type { DbInstance } from "../client";
|
|
import { featuredStories } from "../schema";
|
|
import type { FeaturedStory } from "../schema";
|
|
|
|
/**
|
|
* Featured Story Repository - encapsulates D1 access for homepage featured stories.
|
|
*
|
|
* Provides: listByGender (active only, sorted by sortOrder), incrementClick (analytics).
|
|
*/
|
|
export class FeaturedRepository {
|
|
constructor(private db: DbInstance) {}
|
|
|
|
/**
|
|
* List active featured stories for a given gender, ordered by sortOrder.
|
|
*
|
|
* @param gender "male" or "female"
|
|
* @returns Array of FeaturedStory (only isActive=1, sorted by sortOrder ASC)
|
|
*/
|
|
async listByGender(gender: "male" | "female"): Promise<FeaturedStory[]> {
|
|
return this.db
|
|
.select()
|
|
.from(featuredStories)
|
|
.where(and(eq(featuredStories.gender, gender), eq(featuredStories.isActive, 1)))
|
|
.orderBy(featuredStories.sortOrder);
|
|
}
|
|
|
|
/**
|
|
* Increment click count for a featured story (analytics).
|
|
*
|
|
* @param id Featured story ID (e.g. "m0", "f12")
|
|
* @returns true if updated, false if not found
|
|
*/
|
|
async incrementClick(id: string): Promise<boolean> {
|
|
const result = await this.db
|
|
.update(featuredStories)
|
|
.set({ clickCount: sql`${featuredStories.clickCount} + 1` })
|
|
.where(eq(featuredStories.id, id));
|
|
|
|
// Drizzle D1 update returns { success, meta: { changes }, results }
|
|
return ((result as any).meta?.changes ?? 0) > 0;
|
|
}
|
|
}
|