mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Improve configuration saving for AI models in settings
Update the OpenRouter configuration route to handle updates more gracefully, allowing API keys to remain unchanged if not explicitly provided. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/35Hxx7C
This commit is contained in:
1 parent
4182ed10e5
commit
70dd8a4c87
3 files changed
+23
-11
No files matched your search
@@ -18,10 +18,6 @@ externalPort = 80
|
||||
localPort = 43245
|
||||
externalPort = 3001
|
||||
|
||||
[[ports]]
|
||||
localPort = 46679
|
||||
externalPort = 3000
|
||||
|
||||
[env]
|
||||
PORT = "5000"
|
||||
|
||||
|
||||
+19
-7
@@ -7,7 +7,7 @@ import passport from "./auth";
|
||||
import { z } from "zod";
|
||||
import { openRouterService } from "./services/openrouter";
|
||||
import { cloudinaryService } from "./services/cloudinary";
|
||||
import { insertPostSchema, insertScheduledPostSchema, insertSocialPageSchema, insertAiGenerationSchema, insertCloudinaryConfigSchema, insertOpenrouterConfigSchema, insertUserSchema } from "@shared/schema";
|
||||
import { insertPostSchema, insertScheduledPostSchema, insertSocialPageSchema, insertAiGenerationSchema, insertCloudinaryConfigSchema, insertOpenrouterConfigSchema, updateOpenrouterConfigSchema, insertUserSchema } from "@shared/schema";
|
||||
import type { User, InsertUser } from "@shared/schema";
|
||||
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
@@ -614,18 +614,30 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
const user = req.user as User;
|
||||
const userId = user.id;
|
||||
|
||||
const configData = insertOpenrouterConfigSchema.parse({
|
||||
...req.body,
|
||||
userId,
|
||||
});
|
||||
|
||||
// Check if config already exists
|
||||
const existingConfig = await storage.getOpenrouterConfig(userId);
|
||||
|
||||
let config;
|
||||
if (existingConfig) {
|
||||
config = await storage.updateOpenrouterConfig(userId, configData);
|
||||
// Pour les mises à jour, utiliser le schéma qui rend apiKey optionnel
|
||||
const updateData = updateOpenrouterConfigSchema.parse({
|
||||
...req.body,
|
||||
userId,
|
||||
});
|
||||
|
||||
// Si apiKey n'est pas fourni, garder l'ancien
|
||||
const finalData = {
|
||||
...updateData,
|
||||
apiKey: updateData.apiKey || existingConfig.apiKey,
|
||||
};
|
||||
|
||||
config = await storage.updateOpenrouterConfig(userId, finalData);
|
||||
} else {
|
||||
// Pour les créations, exiger tous les champs
|
||||
const configData = insertOpenrouterConfigSchema.parse({
|
||||
...req.body,
|
||||
userId,
|
||||
});
|
||||
config = await storage.createOpenrouterConfig(configData);
|
||||
}
|
||||
|
||||
|
||||
@@ -226,6 +226,10 @@ export const insertOpenrouterConfigSchema = createInsertSchema(openrouterConfig)
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
export const updateOpenrouterConfigSchema = insertOpenrouterConfigSchema.partial({
|
||||
apiKey: true,
|
||||
});
|
||||
|
||||
// Types
|
||||
export type User = typeof users.$inferSelect;
|
||||
export type InsertUser = z.infer<typeof insertUserSchema>;
|
||||
|
||||
Reference in new issue
Block a user