Introduce horoscope generation via OpenAI API, including new API endpoints and database schema. Adjust card components in `home.tsx` to use `aspect-[16/9]` for consistent image sizing, resolving previous height stretching issues. Update dependencies in `package.json`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 413891e8-d784-4bea-b9f5-91a5a68316b4 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: ca1aa952-242c-43c1-9e28-47aed39cee1b Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/413891e8-d784-4bea-b9f5-91a5a68316b4/nTLKCC5 Replit-Helium-Checkpoint-Created: true
32 lines
872 B
TypeScript
32 lines
872 B
TypeScript
import type { Express, Request, Response } from "express";
|
|
import { openai } from "./client";
|
|
|
|
export function registerImageRoutes(app: Express): void {
|
|
app.post("/api/generate-image", async (req: Request, res: Response) => {
|
|
try {
|
|
const { prompt, size = "1024x1024" } = req.body;
|
|
|
|
if (!prompt) {
|
|
return res.status(400).json({ error: "Prompt is required" });
|
|
}
|
|
|
|
const response = await openai.images.generate({
|
|
model: "gpt-image-1",
|
|
prompt,
|
|
n: 1,
|
|
size: size as "1024x1024" | "512x512" | "256x256",
|
|
});
|
|
|
|
const imageData = response.data[0];
|
|
res.json({
|
|
url: imageData.url,
|
|
b64_json: imageData.b64_json,
|
|
});
|
|
} catch (error) {
|
|
console.error("Error generating image:", error);
|
|
res.status(500).json({ error: "Failed to generate image" });
|
|
}
|
|
});
|
|
}
|
|
|