import{t as e}from"./config-BYRrjYC5.mjs";import{t}from"./logger-B0fjfmRH.mjs";import{t as n}from"./got-BBDj7u1e.mjs";import r from"node:tls";import i from"ip-regex";const a={"App-OS":`ios`,"App-OS-Version":`10.3.1`,"App-Version":`6.7.1`,"User-Agent":`PixivIOSApp/6.7.1 (iOS 10.3.1; iPhone8,1)`};async function o(e,r){try{let i=await n(r,{searchParams:{name:e,type:`A`},headers:{accept:`application/dns-json`}});if(i.data.Status===0)return i.data.Answer.map(e=>e.data);t.error(`Error ${i.data.Status} when querying DoH endpoint ${r}`)}catch(n){t.error(`Failed to resolve ${e}`),t.debug(n)}return[]}const s=n.extend({hooks:{beforeRequest:[async n=>{if(!e.pixiv.bypassCdn)return;let a=null;if(i({exact:!0}).test(e.pixiv.bypassCdnHostname))a=e.pixiv.bypassCdnHostname;else{let n=await o(e.pixiv.bypassCdnHostname,e.pixiv.bypassCdnDoh);n.length?a=n[Math.floor(n.length*Math.random())]:t.warn(`No IPv4 address resolved from ${e.pixiv.bypassCdnHostname}`)}if(a){let e=n.url.host;n.headers={...n.headers,host:e},n.url.hostname=a,n.checkServerIdentity=function(t,n){return r.checkServerIdentity(e,n)}}}]}});let c=null;const l={client_id:`MOBrBDS8blbauoSck0ZfDbtuzpyT`,client_secret:`lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj`,hash_secret:`28c1fdd170a5204386cb1313c7077b34f83e4aaf4aa829ce78c231e05b0bae2c`},u=t=>t(`pixiv:accessToken`,()=>s.post(`https://oauth.secure.pixiv.net/auth/token`,{form:{...l,get_secure_url:1,grant_type:`refresh_token`,refresh_token:e.pixiv.refreshToken},headers:{...a}}),3600,!1);async function d(e){let{data:n}=await u(e);return n&&n.access_token&&(t.debug(`Pixiv refresh token success.`),c=n.access_token),c}var f={getImgs(t){let n=[];if(t.meta_pages?.length)for(let r of t.meta_pages){let t=r.image_urls.original.replace(`https://i.pximg.net`,e.pixiv.imgProxy);n.push(`<p><img src="${t}" width="${r.width}" height="${r.height}" /></p>`)}else if(t.meta_single_page.original_image_url){let r=t.meta_single_page.original_image_url.replace(`https://i.pximg.net`,e.pixiv.imgProxy);n.push(`<p><img src="${r}" width="${t.width}" height="${t.height}" /></p>`)}return n},getProxiedImageUrl(t){return t.replace(`https://i.pximg.net`,e.pixiv.imgProxy||``)}};export{a as i,d as n,s as r,f as t};