feat: modernize admin panel UI and add openinary integration
This commit is contained in:
+8
-14
@@ -1,5 +1,6 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import cloudinary from '@/lib/cloudinary'
|
||||
import { uploadToOpeninary } from '@/lib/openinary'
|
||||
import { optimizedImage } from '@/lib/openinary-url'
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
@@ -10,21 +11,14 @@ export async function POST(request: NextRequest) {
|
||||
return NextResponse.json({ error: 'Dosya bulunamadı.' }, { status: 400 })
|
||||
}
|
||||
|
||||
// Convert file to buffer
|
||||
const arrayBuffer = await file.arrayBuffer()
|
||||
const buffer = Buffer.from(arrayBuffer)
|
||||
const base64 = `data:${file.type};base64,${buffer.toString('base64')}`
|
||||
// Upload to Openinary
|
||||
const result = await uploadToOpeninary(file, 'moyqr');
|
||||
|
||||
// Upload to Cloudinary
|
||||
const result = await cloudinary.uploader.upload(base64, {
|
||||
folder: 'moy-qr/products',
|
||||
transformation: [
|
||||
{ width: 800, height: 800, crop: 'limit' },
|
||||
{ quality: 'auto', fetch_format: 'auto' }
|
||||
]
|
||||
})
|
||||
// Generate optimized URL
|
||||
// e.g. "w_800,h_800,c_limit,q_auto,f_auto" parameters format for Openinary
|
||||
const optimizedUrl = optimizedImage(result.path, 'w_800,h_800,c_limit,q_auto,f_auto');
|
||||
|
||||
return NextResponse.json({ url: result.secure_url })
|
||||
return NextResponse.json({ url: optimizedUrl })
|
||||
} catch (error) {
|
||||
console.error('Upload error:', error)
|
||||
return NextResponse.json({ error: 'Yükleme başarısız oldu.' }, { status: 500 })
|
||||
|
||||
Reference in New Issue
Block a user