mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-12 01:36:54 +02:00
Preserve Cloudinary configuration on settings update
Modify Cloudinary configuration endpoint to allow partial updates and preserve existing API keys and secrets when not explicitly provided, and clear input fields on successful save. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/sEXz3DF
This commit is contained in:
1 parent
d57bc0fb81
commit
3adfbb57bd
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