mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-23 15:08:13 +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
|
localPort = 43245
|
||||||
externalPort = 3001
|
externalPort = 3001
|
||||||
|
|
||||||
[[ports]]
|
|
||||||
localPort = 46679
|
|
||||||
externalPort = 3000
|
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
PORT = "5000"
|
PORT = "5000"
|
||||||
|
|
||||||
|
|||||||
+19
-7
@@ -7,7 +7,7 @@ import passport from "./auth";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { openRouterService } from "./services/openrouter";
|
import { openRouterService } from "./services/openrouter";
|
||||||
import { cloudinaryService } from "./services/cloudinary";
|
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";
|
import type { User, InsertUser } from "@shared/schema";
|
||||||
|
|
||||||
const upload = multer({ storage: multer.memoryStorage() });
|
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 user = req.user as User;
|
||||||
const userId = user.id;
|
const userId = user.id;
|
||||||
|
|
||||||
const configData = insertOpenrouterConfigSchema.parse({
|
|
||||||
...req.body,
|
|
||||||
userId,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Check if config already exists
|
// Check if config already exists
|
||||||
const existingConfig = await storage.getOpenrouterConfig(userId);
|
const existingConfig = await storage.getOpenrouterConfig(userId);
|
||||||
|
|
||||||
let config;
|
let config;
|
||||||
if (existingConfig) {
|
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 {
|
} else {
|
||||||
|
// Pour les créations, exiger tous les champs
|
||||||
|
const configData = insertOpenrouterConfigSchema.parse({
|
||||||
|
...req.body,
|
||||||
|
userId,
|
||||||
|
});
|
||||||
config = await storage.createOpenrouterConfig(configData);
|
config = await storage.createOpenrouterConfig(configData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -226,6 +226,10 @@ export const insertOpenrouterConfigSchema = createInsertSchema(openrouterConfig)
|
|||||||
updatedAt: true,
|
updatedAt: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const updateOpenrouterConfigSchema = insertOpenrouterConfigSchema.partial({
|
||||||
|
apiKey: true,
|
||||||
|
});
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
export type User = typeof users.$inferSelect;
|
export type User = typeof users.$inferSelect;
|
||||||
export type InsertUser = z.infer<typeof insertUserSchema>;
|
export type InsertUser = z.infer<typeof insertUserSchema>;
|
||||||
|
|||||||
Reference in new issue
Block a user