feat: mockup modal avec sélection image existante, familles sheets et métachamps produit

This commit is contained in:
2026-06-24 14:33:19 +02:00
parent 93a616e997
commit 5a10fd4221
3 changed files with 214 additions and 51 deletions
+18
View File
@@ -0,0 +1,18 @@
import { NextRequest } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
export async function GET(req: NextRequest) {
const session = await getServerSession(authOptions)
if (!session) return new Response('Non authentifié', { status: 401 })
const url = req.nextUrl.searchParams.get('url')
if (!url) return new Response('url requis', { status: 400 })
const res = await fetch(url)
if (!res.ok) return new Response('Fetch failed', { status: 502 })
const buffer = await res.arrayBuffer()
const contentType = res.headers.get('content-type') ?? 'image/jpeg'
return new Response(buffer, { headers: { 'Content-Type': contentType } })
}
@@ -0,0 +1,30 @@
import { NextRequest } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
const API_VERSION = '2024-01'
export async function GET(_req: NextRequest, { params }: { params: { shopifyId: string } }) {
const session = await getServerSession(authOptions)
if (!session) return Response.json({ error: 'Non authentifié' }, { status: 401 })
const domain = process.env.SHOPIFY_STORE_DOMAIN
const token = process.env.SHOPIFY_ADMIN_API_TOKEN
if (!domain || !token) return Response.json({ error: 'Config Shopify manquante' }, { status: 500 })
const res = await fetch(
`https://${domain}/admin/api/${API_VERSION}/products/${params.shopifyId}/metafields.json`,
{ headers: { 'X-Shopify-Access-Token': token, 'Content-Type': 'application/json' } },
)
if (!res.ok) return Response.json({ error: `Shopify error: ${res.status}` }, { status: 502 })
const data = await res.json()
const metafields = (data.metafields ?? []) as Array<{
namespace: string
key: string
value: string
type: string
}>
return Response.json({ metafields })
}