@@ -29,37 +29,34 @@ cloudinary.v2.config({
29
29
} ) ;
30
30
type SemesterType = IAdminPaper [ "semester" ] ; // Extract the exam type from the IPaper interface
31
31
32
- const cloudinaryConfig1 = cloudinary . v2 ;
33
- cloudinaryConfig1 . config ( {
32
+ const config1 = {
34
33
cloud_name : process . env . NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME_1 ,
35
34
api_key : process . env . CLOUDINARY_API_KEY_1 ,
36
35
api_secret : process . env . CLOUDINARY_SECRET_1 ,
37
- } ) ;
36
+ } ;
38
37
39
- const cloudinaryConfig2 = cloudinary . v2 ;
40
- cloudinaryConfig2 . config ( {
38
+ const config2 = {
41
39
cloud_name : process . env . NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME_2 ,
42
40
api_key : process . env . CLOUDINARY_API_KEY_2 ,
43
41
api_secret : process . env . CLOUDINARY_SECRET_2 ,
44
- } ) ;
45
- const cloudinaryConfigs = [ cloudinaryConfig1 , cloudinaryConfig2 ] ;
42
+ } ;
43
+ const cloudinaryConfigs = [ config1 , config2 ] ;
46
44
47
45
export async function POST ( req : Request ) {
48
46
try {
49
47
if ( ! process . env . NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET ) {
50
48
return NextResponse . json ( { message : "ServerMisconfig" } , { status : 500 } ) ;
51
49
}
52
50
await connectToDatabase ( ) ;
53
-
54
51
const count : number = await PaperAdmin . countDocuments ( ) ;
55
52
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
+
58
56
const uploadPreset = process . env . NEXT_PUBLIC_CLOUDINARY_UPLOAD_PRESET ;
59
57
const formData = await req . formData ( ) ;
60
58
const files : File [ ] = formData . getAll ( "files" ) as File [ ] ;
61
59
const isPdf = formData . get ( "isPdf" ) === "true" ; // Convert string to boolean
62
-
63
60
let imageURL = "" ;
64
61
if ( isPdf ) {
65
62
imageURL = formData . get ( "image" ) as string ;
@@ -162,7 +159,7 @@ export async function POST(req: Request) {
162
159
uploadPreset ,
163
160
) ;
164
161
}
165
-
162
+ console . log ( finalUrl )
166
163
const thumbnailResponse = cloudinary . v2 . image ( finalUrl ! , {
167
164
format : "jpg" ,
168
165
} ) ;
0 commit comments