mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Merge pull request #29 from R0m1k3/dev
Preserve Cloudinary configuration on settings update
This commit is contained in:
3 files changed
+42
-12
No files matched your search
@@ -55,18 +55,28 @@ export default function Settings() {
|
||||
const hasExistingConfig = !!openrouterConfig;
|
||||
|
||||
const saveCloudinaryMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
apiRequest('POST', '/api/cloudinary/config', {
|
||||
mutationFn: () => {
|
||||
const payload: any = {
|
||||
cloudName,
|
||||
apiKey,
|
||||
apiSecret,
|
||||
}),
|
||||
};
|
||||
|
||||
// N'inclure apiKey et apiSecret que s'ils ne sont pas vides
|
||||
if (apiKey && apiKey.trim() !== "") {
|
||||
payload.apiKey = apiKey;
|
||||
}
|
||||
if (apiSecret && apiSecret.trim() !== "") {
|
||||
payload.apiSecret = apiSecret;
|
||||
}
|
||||
|
||||
return apiRequest('POST', '/api/cloudinary/config', payload);
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['/api/cloudinary/config'] });
|
||||
toast({
|
||||
title: "Configuration sauvegardée",
|
||||
description: "Vos paramètres Cloudinary ont été enregistrés",
|
||||
});
|
||||
setApiKey(""); // Clear the API key after saving
|
||||
setApiSecret(""); // Clear the secret after saving
|
||||
},
|
||||
onError: () => {
|
||||
|
||||
+20
-7
@@ -8,7 +8,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, updateOpenrouterConfigSchema, insertUserSchema, postMedia } from "@shared/schema";
|
||||
import { insertPostSchema, insertScheduledPostSchema, insertSocialPageSchema, insertAiGenerationSchema, insertCloudinaryConfigSchema, updateCloudinaryConfigSchema, insertOpenrouterConfigSchema, updateOpenrouterConfigSchema, insertUserSchema, postMedia } from "@shared/schema";
|
||||
import type { User, InsertUser } from "@shared/schema";
|
||||
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
@@ -618,18 +618,31 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
const user = req.user as User;
|
||||
const userId = user.id;
|
||||
|
||||
const configData = insertCloudinaryConfigSchema.parse({
|
||||
...req.body,
|
||||
userId,
|
||||
});
|
||||
|
||||
// Check if config already exists
|
||||
const existingConfig = await storage.getCloudinaryConfig(userId);
|
||||
|
||||
let config;
|
||||
if (existingConfig) {
|
||||
config = await storage.updateCloudinaryConfig(userId, configData);
|
||||
// Pour les mises à jour, utiliser le schéma qui rend les secrets optionnels
|
||||
const updateData = updateCloudinaryConfigSchema.parse({
|
||||
...req.body,
|
||||
userId,
|
||||
});
|
||||
|
||||
// Si apiKey/apiSecret ne sont pas fournis, garder les anciens
|
||||
const finalData = {
|
||||
...updateData,
|
||||
apiKey: updateData.apiKey || existingConfig.apiKey,
|
||||
apiSecret: updateData.apiSecret || existingConfig.apiSecret,
|
||||
};
|
||||
|
||||
config = await storage.updateCloudinaryConfig(userId, finalData);
|
||||
} else {
|
||||
// Pour les créations, exiger tous les champs
|
||||
const configData = insertCloudinaryConfigSchema.parse({
|
||||
...req.body,
|
||||
userId,
|
||||
});
|
||||
config = await storage.createCloudinaryConfig(configData);
|
||||
}
|
||||
|
||||
|
||||
@@ -230,6 +230,11 @@ export const updateOpenrouterConfigSchema = insertOpenrouterConfigSchema.partial
|
||||
apiKey: true,
|
||||
});
|
||||
|
||||
export const updateCloudinaryConfigSchema = insertCloudinaryConfigSchema.partial({
|
||||
apiKey: true,
|
||||
apiSecret: true,
|
||||
});
|
||||
|
||||
// Types
|
||||
export type User = typeof users.$inferSelect;
|
||||
export type InsertUser = z.infer<typeof insertUserSchema>;
|
||||
@@ -251,8 +256,10 @@ export type InsertAiGeneration = z.infer<typeof insertAiGenerationSchema>;
|
||||
|
||||
export type CloudinaryConfig = typeof cloudinaryConfig.$inferSelect;
|
||||
export type InsertCloudinaryConfig = z.infer<typeof insertCloudinaryConfigSchema>;
|
||||
export type UpdateCloudinaryConfig = z.infer<typeof updateCloudinaryConfigSchema>;
|
||||
|
||||
export type OpenrouterConfig = typeof openrouterConfig.$inferSelect;
|
||||
export type InsertOpenrouterConfig = z.infer<typeof insertOpenrouterConfigSchema>;
|
||||
export type UpdateOpenrouterConfig = z.infer<typeof updateOpenrouterConfigSchema>;
|
||||
|
||||
export type PostMedia = typeof postMedia.$inferSelect;
|
||||
Reference in new issue
Block a user