"use strict";(()=>{var e={};e.id=5609,e.ids=[5609],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")},4351:(e,t,a)=>{a.r(t),a.d(t,{originalPathname:()=>R,patchFetch:()=>S,requestAsyncStorage:()=>y,routeModule:()=>f,serverHooks:()=>x,staticGenerationAsyncStorage:()=>v});var i={};a.r(i),a.d(i,{POST:()=>b,maxDuration:()=>h});var r=a(9303),s=a(8716),n=a(670),o=a(7070),l=a(5655),u=a(2822),c=a(6097),d=a(2582),m=a(1789),p=a(987),k=a(6066),g=a(4437);let h=60;async function b(e){try{let t,a;if(!(0,p._)(e))return o.NextResponse.json((0,p.E)(),{status:403});let i=(0,l.e)(),{data:{user:r},error:s}=await i.auth.getUser();if(s||!r)return o.NextResponse.json({success:!1,error:"Unauthorized"},{status:401});let n=await (0,c.D)(r.id);if(!n.allowed)return o.NextResponse.json({success:!1,error:"Rate limit exceeded. Coba lagi dalam 1 menit."},{status:429});let h=await (0,d.Sb)(i,r.id);if(!(0,d.q9)(h))return o.NextResponse.json({success:!1,error:"Belum ada AI API key. Tambahkan di Settings → API Keys.",redirectTo:"/settings"},{status:402});let b=await (0,m.T)(i,r.id,1);if("quota_exceeded"===b)return o.NextResponse.json({success:!1,error:"Kuota habis. Upgrade plan untuk lebih banyak generasi."},{status:403});let f=await e.json(),{url:y,style:v="cinematic",length:x="medium",language:R="id",tone:S,targetAudience:A,customInstructions:N,customSceneCount:$,sceneDurationPreset:U,customSceneDuration:w,totalDurationPreset:T,customTotalDuration:D}=f;if(!y||"string"!=typeof y)return o.NextResponse.json({success:!1,error:"URL tidak boleh kosong"},{status:400});if("custom"===x&&void 0!==$&&($<1||$>30))return o.NextResponse.json({success:!1,error:"Jumlah scene harus antara 1–30"},{status:400});try{t=await (0,k.K)(y)}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. Pastikan URL dapat diakses publik."},{status:422});let{sceneCountInstruction:j,sceneDurationInstruction:E,totalDurationInstruction:P,estimatedDuration:C}=function(e){let t,a,i,r;let{length:s="medium",customSceneCount:n,sceneDurationPreset:o,customSceneDuration:l,totalDurationPreset:u,customTotalDuration:c}=e;if("custom"===s&&n&&n>=1&&n<=30)t=`Buat TEPAT ${n} scene (tidak kurang, tidak lebih).`;else{let e=g.qP[s];t=`Buat ${e?.scenes??"6-9 scene"}.`}if("custom"===o&&l?.trim())l.trim(),a=`Setiap scene berdurasi ${l.trim()}.`;else if(o&&"custom"!==o){let e=g.Mx[o];e.value,a=`Setiap scene berdurasi ${e.value}.`}else a="Setiap scene berdurasi sekitar 3-5 detik (sesuaikan dengan konten).";if("custom"===u&&c?.trim())r=c.trim(),i=`Total durasi video sekitar ${c.trim()}.`;else if(u&&"custom"!==u){let e=g.eQ[u];r=e.value,i=`Total durasi video sekitar ${e.value}.`}else{let e=g.qP[s];r=e?.duration??"30-60 detik",i=`Total estimasi durasi: ${r}.`}return{sceneCountInstruction:t,sceneDurationInstruction:a,totalDurationInstruction:i,estimatedDuration:r}}(f),L=g.bQ[v],I="id"===R?"Bahasa Indonesia":"English",O=`Kamu adalah profesional Storyboard Writer dan Storyteller kelas dunia.
Tugasmu: membaca konten dari sebuah postingan/artikel, lalu mengubahnya menjadi storyboard visual yang menarik.

ATURAN PENTING:
1. JANGAN keluar dari tema/topik utama postingan asli
2. Boleh merangkum, memperluas, atau merestrukturisasi — ASAL masih relevan dengan tema asli
3. Pertahankan fakta dan pesan inti konten asli
4. Output HARUS dalam ${I}
5. Output HARUS berupa JSON valid, tidak ada teks di luar JSON

STYLE: ${L?.label??v} — ${L?.description??""}

INSTRUKSI SCENE:
- ${j}
- ${E}
- ${P}
${S?`TONE: ${S}`:""}
${A?`TARGET AUDIENCE: ${A}`:""}
${N?`INSTRUKSI KHUSUS: ${N}`:""}

PENTING TENTANG DURASI:
- Field "duration" pada setiap scene HARUS mengikuti instruksi durasi per scene di atas
- Jangan abaikan instruksi durasi — ini adalah kebutuhan produksi yang wajib dipenuhi

OUTPUT FORMAT (JSON):
{
  "theme": "tema utama yang diidentifikasi dari konten",
  "hook": "kalimat pembuka yang menarik perhatian",
  "summary": "ringkasan cerita keseluruhan (2-3 paragraf)",
  "callToAction": "ajakan bertindak yang relevan",
  "scenes": [
    {
      "sceneNumber": 1,
      "title": "judul singkat scene",
      "narration": "teks narasi/voiceover untuk scene ini",
      "visualDescription": "deskripsi visual yang harus ditampilkan",
      "duration": "durasi scene sesuai instruksi di atas",
      "cameraAngle": "sudut kamera yang disarankan",
      "emotion": "emosi dominan scene ini",
      "transition": "transisi ke scene berikutnya"
    }
  ]
}`,q=`Berikut konten yang perlu dijadikan storyboard:

SUMBER: ${t.platform.toUpperCase()} — ${t.url}
JUDUL: ${t.title}
${t.author?`PENULIS: ${t.author}`:""}

KONTEN:
${t.body}

Buat storyboard style ${L?.label??v} dalam ${I}.
${j}
${E}`,K="",M="unknown",B="unknown",G=null;for(let e=0;e<=2;e++)try{let e=await (0,u.SN)([{role:"system",content:O},{role:"user",content:q}],{temperature:.75,maxTokens:8e3},h);K=e.content,M=e.model,B=e.provider,G=null;break}catch(t){G=t,e<2&&await new Promise(t=>setTimeout(t,1e3*(e+1)))}if(G)return o.NextResponse.json({success:!1,error:G.message},{status:500});try{let e=K.replace(/^```(?:json)?\s*/i,"").replace(/\s*```$/i,"").trim();a=JSON.parse(e)}catch{let e=K.match(/\{[\s\S]*\}/);if(!e)return o.NextResponse.json({success:!1,error:"AI menghasilkan output tidak valid. Coba lagi."},{status:500});try{a=JSON.parse(e[0])}catch{return o.NextResponse.json({success:!1,error:"Gagal memparse output AI. Coba lagi."},{status:500})}}let _=Array.isArray(a.scenes)?a.scenes:[],J="3-5 detik";"custom"===U&&w?J=w:U&&"custom"!==U&&(J=g.Mx[U]?.value??"3-5 detik");let F=C;"custom"===T&&D?F=D:T&&"custom"!==T&&(F=g.eQ[T]?.value??C);let H={sourceUrl:t.url,sourcePlatform:t.platform,sourceTitle:t.title,theme:a.theme??"Tidak terdeteksi",hook:a.hook??"",summary:a.summary??"",callToAction:a.callToAction??"",scenes:_,metadata:{generatedAt:new Date().toISOString(),model:`${B}/${M}`,style:v,length:x,totalScenes:_.length,estimatedDuration:F,sceneCount:_.length,sceneDuration:J,totalDuration:F}};return await i.from("storyboard_history").insert({user_id:r.id,source_url:t.url,source_platform:t.platform,source_title:t.title,style:v,length:x,language:R,output:H}),o.NextResponse.json({success:!0,data:H},{headers:{"X-RateLimit-Remaining":String(n.remaining)}})}catch(e){return console.error("[storyboard]",e),o.NextResponse.json({success:!1,error:"Internal server error"},{status:500})}}let f=new r.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/storyboard/route",pathname:"/api/storyboard",filename:"route",bundlePath:"app/api/storyboard/route"},resolvedPagePath:"/home/user/.workspace/projects/promptmotion-ai/src/app/api/storyboard/route.ts",nextConfigOutput:"",userland:i}),{requestAsyncStorage:y,staticGenerationAsyncStorage:v,serverHooks:x}=f,R="/api/storyboard/route";function S(){return(0,n.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:v})}},6066:(e,t,a)=>{function i(e,t,a){let i=e.indexOf(t);if(-1===i)return"";let r=i+t.length,s=e.indexOf(a,r);return -1===s?"":e.slice(r,s).trim()}function r(e,t,a){for(let i of[RegExp(`<meta[^>]+${t}=["']${a}["'][^>]+content=["']([^"']+)["']`,"i"),RegExp(`<meta[^>]+content=["']([^"']+)["'][^>]+${t}=["']${a}["']`,"i")]){let t=e.match(i);if(t?.[1])return s(t[1].trim())}return""}function s(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 n(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 u=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(!u.ok)throw Error(`Gagal mengambil konten dari URL (HTTP ${u.status}). Pastikan URL valid dan dapat diakses publik.`);let c=await u.text(),d=r(c,"property","og:title"),m=r(c,"property","og:description"),p=r(c,"property","og:image"),k=r(c,"property","article:author")||r(c,"name","author"),g=r(c,"property","article:published_time"),h=i(c,"<title>","</title>"),b=d||s(h)||"Untitled",f=r(c,"name","description"),y=m||f||"",v=[y,function(e){let t="";for(let{open:a,close:r}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 s=e.indexOf(a);if(-1===s)continue;let n="";(n="</div>"===r?function(e,t){let a=0,i=t,r=e.length;for(;i<r;)if("<div"===e.slice(i,i+4).toLowerCase())a++,i+=4;else if("</div>"===e.slice(i,i+6).toLowerCase()){if(--a<=0)return e.slice(t,i+6);i+=6}else i++;return e.slice(t)}(e,s):i(e,a,r)).length>t.length&&(t=n)}return t||(t=Array.from(e.matchAll(/<p[^>]*>([\s\S]*?)<\/p>/gi)).map(e=>n(e[1])).filter(e=>e.length>40).slice(0,20).join("\n\n")),n(t).slice(0,8e3)}(c)].filter(Boolean).join("\n\n");return{url:o,platform:a,title:b,description:y,body:v.slice(0,8e3),author:k||void 0,imageUrl:p||void 0,publishedAt:g||void 0,rawLength:c.length}}a.d(t,{K:()=>o})},4437:(e,t,a)=>{a.d(t,{Mx:()=>s,bQ:()=>i,eQ:()=>n,qP:()=>r});let i={cinematic:{label:"Cinematic",icon:"\uD83C\uDFAC",description:"Dramatis, sinematik, nuansa film"},documentary:{label:"Dokumenter",icon:"\uD83D\uDCF9",description:"Faktual, informatif, terstruktur"},social_media:{label:"Social Media",icon:"\uD83D\uDCF1",description:"Singkat, catchy, viral-ready"},ugc:{label:"UGC",icon:"\uD83E\uDD33",description:"Kasual, autentik, user-generated feel"},explainer:{label:"Explainer",icon:"\uD83D\uDCA1",description:"Edukatif, jelas, step-by-step"},emotional:{label:"Emotional",icon:"\uD83D\uDC96",description:"Menyentuh hati, penuh empati"},humorous:{label:"Humoris",icon:"\uD83D\uDE04",description:"Ringan, lucu, menghibur"}},r={short:{label:"Pendek",scenes:"3–5 scene",duration:"15–30 detik",count:[3,5]},medium:{label:"Sedang",scenes:"6–9 scene",duration:"30–60 detik",count:[6,9]},long:{label:"Panjang",scenes:"10–15 scene",duration:"1–3 menit",count:[10,15]},custom:{label:"Custom",scenes:"kamu tentukan",duration:"kamu tentukan"}},s={"2-3s":{label:"2–3 detik",value:"2-3 detik"},"3-5s":{label:"3–5 detik",value:"3-5 detik"},"5-8s":{label:"5–8 detik",value:"5-8 detik"},"8-12s":{label:"8–12 detik",value:"8-12 detik"},custom:{label:"Custom",value:""}},n={"15s":{label:"15 detik",value:"15 detik"},"30s":{label:"30 detik",value:"30 detik"},"60s":{label:"60 detik",value:"60 detik"},"90s":{label:"90 detik",value:"90 detik"},"3min":{label:"3 menit",value:"3 menit"},"5min":{label:"5 menit",value:"5 menit"},custom:{label:"Custom",value:""}}}};var t=require("../../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),i=t.X(0,[9276,6164,5972,3454],()=>a(4351));module.exports=i})();