Horoskopska stran: slike znamenj (image_url + /api/horoscopes/images)
This commit is contained in:
@@ -25,6 +25,19 @@ export async function getHoroscopesForToday(): Promise<any[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
export async function setHoroscopeImages(dateStr: string, images: Record<string, string>): Promise<number> {
|
||||
let n = 0;
|
||||
for (const [key, url] of Object.entries(images || {})) {
|
||||
const idx = parseInt(key, 10);
|
||||
if (Number.isNaN(idx) || !url) continue;
|
||||
await db.update(dailyHoroscopes)
|
||||
.set({ imageUrl: url })
|
||||
.where(and(eq(dailyHoroscopes.dateStr, dateStr), eq(dailyHoroscopes.signIndex, idx)));
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
export async function generateDailyHoroscopes(): Promise<void> {
|
||||
const today = getTodayStr();
|
||||
|
||||
|
||||
+14
-1
@@ -3,7 +3,7 @@ import { createServer, type Server } from "http";
|
||||
import { storage } from "./storage";
|
||||
import { insertArticleSchema } from "@shared/schema";
|
||||
import { seedDatabase } from "./seed";
|
||||
import { generateDailyHoroscopes, getHoroscopesForToday, getOrGenerateHoroscope, getCosmicEventsForToday, generateCosmicEvents } from "./horoscope-generator";
|
||||
import { generateDailyHoroscopes, getHoroscopesForToday, getOrGenerateHoroscope, getCosmicEventsForToday, generateCosmicEvents, setHoroscopeImages } from "./horoscope-generator";
|
||||
import { startDailyScheduler } from "./scheduler";
|
||||
import { analyzeAllArticleImages, getCachedFocalPoints } from "./focal-point";
|
||||
import { optimizeImage } from "./image-optimizer";
|
||||
@@ -741,6 +741,19 @@ export async function registerRoutes(
|
||||
});
|
||||
|
||||
// Horoscope API
|
||||
app.post("/api/horoscopes/images", requireApiKey, async (req, res) => {
|
||||
try {
|
||||
const { dateStr, images } = req.body || {};
|
||||
if (!dateStr || typeof images !== "object" || images === null) {
|
||||
return res.status(400).json({ message: "dateStr und images sind erforderlich" });
|
||||
}
|
||||
const updated = await setHoroscopeImages(dateStr, images);
|
||||
res.json({ updated });
|
||||
} catch (err: any) {
|
||||
res.status(500).json({ message: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/api/horoscopes/today", async (_req, res) => {
|
||||
try {
|
||||
const horoscopes = await getHoroscopesForToday();
|
||||
|
||||
Reference in New Issue
Block a user