import{t as e}from"./ofetch-Dl6dVB_5.mjs";import{t}from"./config-BYRrjYC5.mjs";import{t as n}from"./parse-date-BdYTmLpo.mjs";import{t as r}from"./got-BBDj7u1e.mjs";import{t as i}from"./config-not-found-B9AOp828.mjs";import{t as a}from"./playwright-1-2p8zlN.mjs";import{Fragment as o,jsx as s,jsxs as c}from"hono/jsx/jsx-runtime";import{load as l}from"cheerio";import{renderToString as u}from"hono/jsx/dom/server";const d=`https://nhentai.net`,f=async(e,t,n)=>{let i=`https://nhentai.net/login/`,a=`nhentai:cookie`,o=await n.get(a);if(o){let{cookie:e,time:t}=JSON.parse(o);if(Date.now()-t<86400*3*1e3)return e}let{data:s,headers:c}=await r(i),l=s.match(/name="csrfmiddlewaretoken" value="(.*?)"/)[1],u=c[`set-cookie`].map(e=>e.split(`;`)[0]).join(`; `),d=await r.post(i,{headers:{referer:i,cookie:u},form:{csrfmiddlewaretoken:l,username_or_email:e,password:t,next:``},followRedirect:!1});if(d.statusCode!==302)return n.set(a,JSON.stringify({cookie:``,time:Date.now()})),``;let f=d.headers[`set-cookie`].map(e=>e.split(`;`)[0]).join(`; `);return n.set(a,JSON.stringify({cookie:f,time:Date.now()})),f},p=async t=>{try{return await e(t)}catch(e){if((e.status??e.statusCode)===403){let{page:e,destroy:n}=await a(t,{onBeforeLoad:async e=>{let t=new Set([`document`,`script`,`xhr`,`fetch`]);await e.setRequestInterception(!0),e.on(`request`,e=>{t.has(e.resourceType())?e.continue():e.abort()})}}),r=await e.content();return await n(),r}throw e}},m=async e=>{let t=l(await p(e));return t(`.gallery a.cover`).toArray().map(e=>v(t(e)))},h=(e,t,n)=>Promise.all(t.slice(0,n).map(t=>e.tryGet(t.link,()=>b(t)))),g=async(e,n,r)=>{if(!t.nhentai||!t.nhentai.username||!t.nhentai.password)throw new i(`nhentai RSS with torrents is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>`);let a=await f(t.nhentai.username,t.nhentai.password,e);if(!a)throw new i(`Invalid username (or email) or password for nhentai torrent download`);return _(e,n,a,r)},_=(e,t,n,r)=>Promise.all(t.slice(0,r).map(t=>e.tryGet(t.link+`download`,()=>y(t,n)))),v=e=>{let t=new URL(e.attr(`href`),d).href,n=e.children(`img`),r=(n.attr(`data-src`)||n.attr(`src`)).replace(`thumb`,`1`).replace(/t(\d+)\.nhentai\.net/,`i$1.nhentai.net`).replace(`.webp.webp`,`.webp`);return{title:e.children(`.caption`).text(),link:t,description:`<img src="${r}">`}},y=async(t,n)=>{let{link:r}=t,i=await e(r+`download`,{headers:{Cookie:n}});return{...t,enclosure_url:i,enclosure_type:`application/x-bittorrent`}},b=async e=>{let{link:t}=e,r=l(await p(t)),i=r(`.gallerythumb img`).toArray().map(e=>new URL(r(e).attr(`data-src`),d).href).map(e=>e.replace(/(.+)(\d+)t\.(.+)/,(e,t,n,r)=>`${t}${n}.${r}`)).map(e=>e.replace(/t(\d+)\.nhentai\.net/,`i$1.nhentai.net`)).map(e=>e.replace(/\.(jpg|png|gif)\.webp$/,`.$1`)).map(e=>e.replace(/\.webp\.webp$/,`.webp`));return{...e,title:r(`div#info > h2`).text()||r(`div#info > h1`).text(),pubDate:n(r(`time`).attr(`datetime`)),description:x(i.length,i)}},x=(e,t)=>u(c(o,{children:[c(`h1`,{children:[e,` pages`]}),s(`br`,{}),t.map((e,t)=>c(`span`,{children:[s(`img`,{src:e}),s(`br`,{})]},`${e}-${t}`))]}));export{m as n,g as r,h as t};