import{logger as e}from"../../logger/index.mjs";import{launchBrowser as t}from"../../utils/puppeteer/launchBrowser.mjs";import{deleteShowcaseScreenshot as n,uploadShowcaseScreenshot as r}from"../showcase/showcaseUploadScreenshot.service.mjs";const i=/^(localhost|127\.\d+\.\d+\.\d+|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(1[6-9]|2\d|3[01])\.\d+\.\d+|::1)$/i,a=e=>{try{let{hostname:t,protocol:n}=new URL(e);return!(n!==`http:`&&n!==`https:`||i.test(t)||!t.includes(`.`))}catch{return!1}},o=async(n,i)=>{let a=await t({pipe:!1,dumpio:!1});try{let e=await a.newPage();await e.setViewport({width:1280,height:720}),await e.goto(n,{waitUntil:`domcontentloaded`,timeout:45e3}),await e.waitForSelector(`body`,{timeout:1e4}),await e.waitForNetworkIdle({idleTime:1e3,timeout:1e4}).catch(()=>{});let t=await e.screenshot({type:`jpeg`,quality:30});return await e.close(),await r(t,n,i)}catch(t){return e.error(`[projectScreenshot] Failed to screenshot ${n}: ${t}`),null}finally{await a.close()}},s=async({newApplicationUrl:e,previousApplicationUrl:t,existingImageUrl:r,projectId:i})=>{if(!e||e===t||!a(e))return r;let s=await o(e,i);return r&&t&&e!==t&&n(r).catch(()=>{}),s??r};export{s as refreshProjectScreenshotIfChanged,o as takeAndUploadProjectScreenshot};
//# sourceMappingURL=projectScreenshot.service.mjs.map