mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-21 22:18:12 +02:00
fix: Improve Reel text generation and add FFmpeg settings - Fix generate-text to use productInfo as ProductInfo object - Add FFmpeg API configuration section in Settings page - Add /api/ffmpeg/config GET/POST routes
This commit is contained in:
1 parent
c2c2fef62f
commit
4903aa5555
3 files changed
+194
-22
No files matched your search
@@ -1587,6 +1587,66 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// FFmpeg API Configuration
|
||||
app.get("/api/ffmpeg/config", requireAdmin, async (req, res) => {
|
||||
try {
|
||||
const user = req.user as User;
|
||||
// Lire depuis les variables d'environnement ou un storage dédié
|
||||
// Pour simplifier, on renvoie juste si c'est configuré ou non
|
||||
const apiUrl = process.env.FFMPEG_API_URL || "";
|
||||
|
||||
res.json({
|
||||
apiUrl: apiUrl,
|
||||
configured: !!apiUrl && !!process.env.FFMPEG_API_KEY,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error fetching FFmpeg config:", error);
|
||||
res.status(500).json({ error: "Failed to fetch FFmpeg config" });
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/api/ffmpeg/config", requireAdmin, async (req, res) => {
|
||||
try {
|
||||
const { apiUrl, apiKey } = req.body;
|
||||
|
||||
if (!apiUrl) {
|
||||
return res.status(400).json({ error: "URL de l'API FFmpeg requise" });
|
||||
}
|
||||
|
||||
// Configurer le service FFmpeg avec les nouvelles valeurs
|
||||
const { ffmpegService } = await import("./services/ffmpeg");
|
||||
|
||||
// Si apiKey fourni, configurer avec
|
||||
if (apiKey) {
|
||||
ffmpegService.configure(apiUrl, apiKey);
|
||||
} else if (process.env.FFMPEG_API_KEY) {
|
||||
// Garder la clé existante
|
||||
ffmpegService.configure(apiUrl, process.env.FFMPEG_API_KEY);
|
||||
} else {
|
||||
return res.status(400).json({ error: "Clé API FFmpeg requise pour la première configuration" });
|
||||
}
|
||||
|
||||
// Stocker dans les variables d'environnement (pour cette session)
|
||||
process.env.FFMPEG_API_URL = apiUrl;
|
||||
if (apiKey) {
|
||||
process.env.FFMPEG_API_KEY = apiKey;
|
||||
}
|
||||
|
||||
// Tester la connexion
|
||||
const isHealthy = await ffmpegService.healthCheck();
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
apiUrl: apiUrl,
|
||||
configured: true,
|
||||
healthy: isHealthy,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error saving FFmpeg config:", error);
|
||||
res.status(500).json({ error: "Failed to save FFmpeg config" });
|
||||
}
|
||||
});
|
||||
|
||||
const httpServer = createServer(app);
|
||||
|
||||
return httpServer;
|
||||
|
||||
+11
-2
@@ -145,12 +145,21 @@ reelsRouter.post('/reels/generate-text', async (req: Request, res: Response) =>
|
||||
return res.status(400).json({ error: 'Informations produit requises' });
|
||||
}
|
||||
|
||||
const generatedTexts = await openRouterService.generatePostText(productInfo, user.id, model);
|
||||
// Convertir la chaîne de texte simple en objet ProductInfo
|
||||
// Si l'utilisateur envoie une chaîne, on l'utilise comme description du produit
|
||||
const productInfoObject = typeof productInfo === 'string'
|
||||
? {
|
||||
name: productInfo.trim(), // Utiliser le texte comme nom
|
||||
description: productInfo.trim(), // Et comme description
|
||||
}
|
||||
: productInfo;
|
||||
|
||||
const generatedTexts = await openRouterService.generatePostText(productInfoObject, user.id, model);
|
||||
|
||||
// Sauvegarder la génération
|
||||
await storage.createAiGeneration({
|
||||
userId: user.id,
|
||||
productInfo,
|
||||
productInfo: productInfoObject,
|
||||
generatedTexts,
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user