Skip to content

Commit e144873

Browse files
fix: cloudinary config getting selected correctly
1 parent 4d840bd commit e144873

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/app/api/ai-upload/route.ts

+9-12
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,34 @@ cloudinary.v2.config({
2929
});
3030
type SemesterType = IAdminPaper["semester"]; // Extract the exam type from the IPaper interface
3131

32-
const cloudinaryConfig1 = cloudinary.v2;
33-
cloudinaryConfig1.config({
32+
const config1 = {
3433
cloud_name: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME_1,
3534
api_key: process.env.CLOUDINARY_API_KEY_1,
3635
api_secret: process.env.CLOUDINARY_SECRET_1,
37-
});
36+
};
3837

39-
const cloudinaryConfig2 = cloudinary.v2;
40-
cloudinaryConfig2.config({
38+
const config2 = {
4139
cloud_name: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME_2,
4240
api_key: process.env.CLOUDINARY_API_KEY_2,
4341
api_secret: process.env.CLOUDINARY_SECRET_2,
44-
});
45-
const cloudinaryConfigs = [cloudinaryConfig1, cloudinaryConfig2];
42+
};
43+
const cloudinaryConfigs = [config1, config2];
4644

4745
export async function POST(req: Request) {
4846
try {
4947
if (!process.env.NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET) {
5048
return NextResponse.json({ message: "ServerMisconfig" }, { status: 500 });
5149
}
5250
await connectToDatabase();
53-
5451
const count: number = await PaperAdmin.countDocuments();
5552
const configIndex = count % cloudinaryConfigs.length;
56-
const selectedConfig = cloudinaryConfigs[configIndex];
57-
cloudinary.v2.config(selectedConfig);
53+
console.log(configIndex)
54+
cloudinary.v2.config(cloudinaryConfigs[configIndex]);
55+
5856
const uploadPreset = process.env.NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET;
5957
const formData = await req.formData();
6058
const files: File[] = formData.getAll("files") as File[];
6159
const isPdf = formData.get("isPdf") === "true"; // Convert string to boolean
62-
6360
let imageURL = "";
6461
if (isPdf) {
6562
imageURL = formData.get("image") as string;
@@ -162,7 +159,7 @@ export async function POST(req: Request) {
162159
uploadPreset,
163160
);
164161
}
165-
162+
console.log(finalUrl)
166163
const thumbnailResponse = cloudinary.v2.image(finalUrl!, {
167164
format: "jpg",
168165
});

0 commit comments

Comments
 (0)