51e6722f4c
Two changes to the no-photo cover placeholder shipped last version: 1. Muted the gradient palette (100/40-opacity tints instead of solid -200/ -950 stops) — the original was too saturated next to real cover photos in the same grid, per feedback. 2. New coverIcon/coverColor columns on recipes (nullable text, migration 0048, additive-only) let the author pin a specific color+icon from the recipe editor instead of the automatic per-id pick. getRecipePlaceholder now checks these first, falling back to the deterministic hash pick when unset — existing recipes are unaffected until edited. Wired coverIcon/coverColor through every explicit-column recipe select that feeds a grid card (explore trending/recent, search, feed, for-you) — the relational-query call sites (recipes page, collections, profile pages) already return all columns and needed no changes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
71 lines
2.5 KiB
TypeScript
71 lines
2.5 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { db, recipes, users, userFollows, eq, and, ne, sql } from "@epicure/db";
|
|
import { requireSessionOrApiKey } from "@/lib/api-auth";
|
|
import { desc, inArray } from "@epicure/db";
|
|
import { attachCardExtras } from "@/lib/recipe-card-extras";
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const { session, response } = await requireSessionOrApiKey(req);
|
|
if (response) return response;
|
|
|
|
const { searchParams } = new URL(req.url);
|
|
const limit = Math.min(parseInt(searchParams.get("limit") ?? "20"), 50);
|
|
const offset = parseInt(searchParams.get("offset") ?? "0");
|
|
|
|
// Get IDs of users the current user follows
|
|
const followedRows = await db
|
|
.select({ followingId: userFollows.followingId })
|
|
.from(userFollows)
|
|
.where(eq(userFollows.followerId, session!.user.id));
|
|
|
|
const followedIds = followedRows.map((r) => r.followingId);
|
|
|
|
if (followedIds.length === 0) {
|
|
return NextResponse.json({ data: [], total: 0, limit, offset, message: "Follow some users to see their recipes here." });
|
|
}
|
|
|
|
const where = and(inArray(recipes.authorId, followedIds), ne(recipes.visibility, "private"));
|
|
|
|
const [feedRecipes, totalRow] = await Promise.all([
|
|
db
|
|
.select({
|
|
id: recipes.id,
|
|
title: recipes.title,
|
|
description: recipes.description,
|
|
baseServings: recipes.baseServings,
|
|
prepMins: recipes.prepMins,
|
|
cookMins: recipes.cookMins,
|
|
difficulty: recipes.difficulty,
|
|
visibility: recipes.visibility,
|
|
tags: recipes.tags,
|
|
isBatchCook: recipes.isBatchCook,
|
|
sourceUrl: recipes.sourceUrl,
|
|
recipeType: recipes.recipeType,
|
|
coverIcon: recipes.coverIcon,
|
|
coverColor: recipes.coverColor,
|
|
createdAt: recipes.createdAt,
|
|
updatedAt: recipes.updatedAt,
|
|
authorId: recipes.authorId,
|
|
authorName: users.name,
|
|
authorUsername: users.username,
|
|
authorAvatarUrl: users.avatarUrl,
|
|
})
|
|
.from(recipes)
|
|
.innerJoin(users, eq(recipes.authorId, users.id))
|
|
.where(where)
|
|
.orderBy(desc(recipes.createdAt))
|
|
.limit(limit)
|
|
.offset(offset),
|
|
db
|
|
.select({ total: sql<number>`count(*)::int` })
|
|
.from(recipes)
|
|
.innerJoin(users, eq(recipes.authorId, users.id))
|
|
.where(where),
|
|
]);
|
|
|
|
const total = totalRow[0]?.total ?? 0;
|
|
const data = await attachCardExtras(feedRecipes, session!.user.id);
|
|
|
|
return NextResponse.json({ data, total, limit, offset });
|
|
}
|