"use strict";(()=>{var e={};e.id=4191,e.ids=[4191],e.modules={2934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},4580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},5869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},4770:e=>{e.exports=require("crypto")},1668:(e,t,a)=>{a.r(t),a.d(t,{originalPathname:()=>R,patchFetch:()=>U,requestAsyncStorage:()=>x,routeModule:()=>f,serverHooks:()=>y,staticGenerationAsyncStorage:()=>b});var r={};a.r(r),a.d(r,{POST:()=>h,maxDuration:()=>k});var n=a(9303),i=a(8716),s=a(670),o=a(7070),l=a(5655),c=a(2822),u=a(6097),p=a(2582),d=a(1789),m=a(987),g=a(6066);let k=60;async function h(e){try{let t,a;if(!(0,m._)(e))return o.NextResponse.json((0,m.E)(),{status:403});let r=(0,l.e)(),{data:{user:n},error:i}=await r.auth.getUser();if(i||!n)return o.NextResponse.json({success:!1,error:"Unauthorized"},{status:401});let s=await (0,u.D)(n.id);if(!s.allowed)return o.NextResponse.json({success:!1,error:"Rate limit exceeded. Coba lagi dalam 1 menit."},{status:429});let k=await (0,p.Sb)(r,n.id);if(!(0,p.q9)(k))return o.NextResponse.json({success:!1,error:"Belum ada AI API key. Tambahkan di Settings → API Keys.",redirectTo:"/settings"},{status:402});let h=await (0,d.T)(r,n.id,1);if("quota_exceeded"===h)return o.NextResponse.json({success:!1,error:"Kuota habis. Upgrade plan untuk lebih banyak generasi."},{status:403});let{url:f}=await e.json();if(!f||"string"!=typeof f)return o.NextResponse.json({success:!1,error:"URL tidak boleh kosong"},{status:400});try{t=await (0,g.K)(f)}catch(e){return o.NextResponse.json({success:!1,error:`Gagal mengambil konten dari URL: ${e.message}`},{status:422})}if(!t.body&&!t.description)return o.NextResponse.json({success:!1,error:"Konten dari URL kosong atau tidak dapat dibaca."},{status:422});let x=`Kamu adalah ahli ekstraksi data produk e-commerce dan marketing.
Tugasmu: baca konten halaman produk, lalu ekstrak informasi produk terstruktur untuk keperluan pembuatan UGC (User Generated Content).

ATURAN:
1. Ekstrak informasi yang ADA di halaman — jangan mengarang
2. Jika informasi tidak tersedia, isi dengan string kosong ""
3. "masalahPainPoint" = masalah konsumen yang diselesaikan produk ini
4. "manfaatUtama" = 1-2 kalimat manfaat terpenting
5. "fiturKandungan" = bahan aktif / fitur teknis utama (singkat)
6. "targetAudiens" = siapa yang paling cocok pakai produk ini
7. Output HARUS valid JSON — tidak ada teks di luar JSON

OUTPUT FORMAT:
{
  "namaProduk": "...",
  "kategori": "...",
  "deskripsiProduk": "...",
  "masalahPainPoint": "...",
  "manfaatUtama": "...",
  "fiturKandungan": "...",
  "targetAudiens": "...",
  "harga": "..."
}`,b=`Ekstrak data produk dari halaman berikut:

URL: ${t.url}
JUDUL: ${t.title}
DESKRIPSI META: ${t.description}

KONTEN HALAMAN:
${t.body}

Ekstrak semua informasi produk yang relevan untuk pembuatan konten UGC marketing.`,y="",R=null;for(let e=0;e<=2;e++)try{y=(await (0,c.SN)([{role:"system",content:x},{role:"user",content:b}],{temperature:.3,maxTokens:2e3},k)).content,R=null;break}catch(t){R=t,e<2&&await new Promise(t=>setTimeout(t,1e3*(e+1)))}if(R)return o.NextResponse.json({success:!1,error:R.message},{status:500});try{let e=y.replace(/^```(?:json)?\s*/i,"").replace(/\s*```$/i,"").trim();a=JSON.parse(e)}catch{let e=y.match(/\{[\s\S]*\}/);if(!e)return o.NextResponse.json({success:!1,error:"AI gagal mengekstrak data produk. Coba lagi."},{status:500});try{a=JSON.parse(e[0])}catch{return o.NextResponse.json({success:!1,error:"Gagal memparse output AI."},{status:500})}}let U={namaProduk:a.namaProduk||t.title||"",kategori:a.kategori||"",deskripsiProduk:a.deskripsiProduk||t.description||"",masalahPainPoint:a.masalahPainPoint||"",manfaatUtama:a.manfaatUtama||"",fiturKandungan:a.fiturKandungan||"",targetAudiens:a.targetAudiens||"",harga:a.harga||"",imageUrl:t.imageUrl||void 0,sourceUrl:t.url};return o.NextResponse.json({success:!0,data:U},{headers:{"X-RateLimit-Remaining":String(s.remaining)}})}catch(e){return console.error("[ugc-extract]",e),o.NextResponse.json({success:!1,error:"Internal server error"},{status:500})}}let f=new n.AppRouteRouteModule({definition:{kind:i.x.APP_ROUTE,page:"/api/ugc-generator/extract/route",pathname:"/api/ugc-generator/extract",filename:"route",bundlePath:"app/api/ugc-generator/extract/route"},resolvedPagePath:"/home/user/.workspace/projects/promptmotion-ai/src/app/api/ugc-generator/extract/route.ts",nextConfigOutput:"",userland:r}),{requestAsyncStorage:x,staticGenerationAsyncStorage:b,serverHooks:y}=f,R="/api/ugc-generator/extract/route";function U(){return(0,s.patchFetch)({serverHooks:y,staticGenerationAsyncStorage:b})}},6066:(e,t,a)=>{function r(e,t,a){let r=e.indexOf(t);if(-1===r)return"";let n=r+t.length,i=e.indexOf(a,n);return -1===i?"":e.slice(n,i).trim()}function n(e,t,a){for(let r of[RegExp(`<meta[^>]+${t}=["']${a}["'][^>]+content=["']([^"']+)["']`,"i"),RegExp(`<meta[^>]+content=["']([^"']+)["'][^>]+${t}=["']${a}["']`,"i")]){let t=e.match(r);if(t?.[1])return i(t[1].trim())}return""}function i(e){return e.replace(/&amp;/g,"&").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&quot;/g,'"').replace(/&#39;/g,"'").replace(/&nbsp;/g," ").replace(/&#(\d+);/g,(e,t)=>String.fromCharCode(Number(t)))}function s(e){return e.replace(/<script[\s\S]*?<\/script>/gi," ").replace(/<style[\s\S]*?<\/style>/gi," ").replace(/<[^>]+>/g," ").replace(/\s{2,}/g," ").trim()}async function o(e){let t;let a=function(e){let t=e.toLowerCase();return t.includes("facebook.com")||t.includes("fb.com")?"facebook":t.includes("instagram.com")?"instagram":t.includes("twitter.com")||t.includes("x.com")?"twitter":"website"}(e),o=e.trim();o.startsWith("http")||(o=`https://${o}`);try{t=new URL(o)}catch{throw Error("URL tidak valid. Pastikan format URL benar (contoh: https://example.com/post).")}if("https:"!==t.protocol&&"http:"!==t.protocol)throw Error("Hanya URL dengan protokol http/https yang diizinkan.");let l=t.hostname.toLowerCase();if(["localhost","127.0.0.1","0.0.0.0","::1","[::1]"].includes(l))throw Error("URL tidak diizinkan: alamat loopback diblokir.");if(/^(10\.\d+\.\d+\.\d+|172\.(1[6-9]|2\d|3[01])\.\d+\.\d+|192\.168\.\d+\.\d+|169\.254\.\d+\.\d+|fc[0-9a-f]{2}:|fd[0-9a-f]{2}:)/i.test(l))throw Error("URL tidak diizinkan: rentang IP privat diblokir.");let c=await fetch(o,{headers:{"User-Agent":"Mozilla/5.0 (compatible; PromptMotionBot/1.0; +https://promptmotion.ai)",Accept:"text/html,application/xhtml+xml","Accept-Language":"id,en;q=0.9"},signal:AbortSignal.timeout(1e4),redirect:"follow"});if(!c.ok)throw Error(`Gagal mengambil konten dari URL (HTTP ${c.status}). Pastikan URL valid dan dapat diakses publik.`);let u=await c.text(),p=n(u,"property","og:title"),d=n(u,"property","og:description"),m=n(u,"property","og:image"),g=n(u,"property","article:author")||n(u,"name","author"),k=n(u,"property","article:published_time"),h=r(u,"<title>","</title>"),f=p||i(h)||"Untitled",x=n(u,"name","description"),b=d||x||"",y=[b,function(e){let t="";for(let{open:a,close:n}of[{open:"<article",close:"</article>"},{open:"<main",close:"</main>"},{open:'class="post-content',close:"</div>"},{open:'class="entry-content',close:"</div>"},{open:'class="article-body',close:"</div>"},{open:'class="content-body',close:"</div>"},{open:'class="post-body',close:"</div>"}]){let i=e.indexOf(a);if(-1===i)continue;let s="";(s="</div>"===n?function(e,t){let a=0,r=t,n=e.length;for(;r<n;)if("<div"===e.slice(r,r+4).toLowerCase())a++,r+=4;else if("</div>"===e.slice(r,r+6).toLowerCase()){if(--a<=0)return e.slice(t,r+6);r+=6}else r++;return e.slice(t)}(e,i):r(e,a,n)).length>t.length&&(t=s)}return t||(t=Array.from(e.matchAll(/<p[^>]*>([\s\S]*?)<\/p>/gi)).map(e=>s(e[1])).filter(e=>e.length>40).slice(0,20).join("\n\n")),s(t).slice(0,8e3)}(u)].filter(Boolean).join("\n\n");return{url:o,platform:a,title:f,description:b,body:y.slice(0,8e3),author:g||void 0,imageUrl:m||void 0,publishedAt:k||void 0,rawLength:u.length}}a.d(t,{K:()=>o})}};var t=require("../../../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),r=t.X(0,[9276,6164,5972,3454],()=>a(1668));module.exports=r})();