import{t as e}from"./ofetch-Dl6dVB_5.mjs";import{t}from"./cache-DUthuMSu.mjs";import{t as n}from"./parse-date-BdYTmLpo.mjs";import{load as r}from"cheerio";const i={path:`/:id?/:type?/:keyword?`,url:`cool18.com`,example:`/cool18/bbs4`,parameters:{id:"the name of the bbs, use `global` for site-wide search",type:"the type of the post. Can be `home`, `gold`, `threadsearch`. Default: `home`",keyword:`the keyword to search.`},categories:[`bbs`],radar:[{source:[`cool18.com/:id/`],target:`/:id/:type?/:keyword?`}],name:`禁忌书屋`,maintainers:[`nczitzk`,`Gabrlie`],handler:d,features:{nsfw:!0}};function a(e,t,n,r){return r&&(t===`search`||t===`threadsearch`)?`${e}/search.php?keyword=${encodeURIComponent(n||``)}&sa=全成人区搜索`:e+{home:``,gold:`?app=forum&act=gold`,threadsearch:`?action=search&act=threadsearch&app=forum&keywords=${encodeURIComponent(n||``)}&submit=查询`,search:`?action=search&act=threadsearch&app=forum&keywords=${encodeURIComponent(n||``)}&submit=查询`}[t]}function o(e,t,r){try{let i=e(`script:contains("_PageData")`).text().match(/const\s+_PageData\s*=\s*(\[[\s\S]*?]);/);return i?.[1]?JSON.parse(i[1]).slice(0,r).map(e=>({title:e.subject,link:`${t}?app=forum&act=threadview&tid=${e.tid}`,pubDate:n(e.dateline,`MM/DD/YY`),author:e.username,category:e.type?[e.type]:[],description:``})):[]}catch{return[]}}function s(e,t,r){return e(`#d_list ul li, #thread_list li, .t_l .t_subject, .post-list.thread-list li`).slice(0,r).toArray().map(r=>{let i=e(r),a=i.find(`a`).first(),o=a.attr(`href`)||``,s=a.find(`span`).first().text().trim(),c=i.find(`font[color="black"]`).text().trim(),l=i.find(`a`).last().text().trim(),u=c||l;return{title:a.text().trim(),link:o.startsWith(`http`)?o:`${t}/${o}`,pubDate:n(i.find(`i`).text(),`MM/DD/YY`),author:u,category:s?[s]:[],description:``}}).filter(e=>e.link)}function c(e,t){return e(`.search-content ul li`).slice(0,t).toArray().map(t=>{let r=e(t).find(`a`).first(),i=r.attr(`href`)||``,a=r.find(`p`),o=a.filter(`.lf`).first().text().trim().replaceAll(/[【】]/g,``),s=a.filter(`.lf`).eq(1).text().trim(),c=a.filter(`.lr`).text().trim();return{title:s||r.text().trim(),link:i.startsWith(`http`)?i:`https://www.cool18.com/${i}`,pubDate:n(c,`YYYY-MM-DD HH:mm`),author:``,category:o?[o]:[],description:``}}).filter(e=>e.link&&e.title)}function l(e,t,n){return e(`.section .post-list .post-item`).slice(0,n).toArray().map(n=>{let r=e(n).find(`a`).first(),i=r.attr(`href`)||``;return{title:r.text().trim().replace(/^\.\s+/,``),link:i.startsWith(`http`)?i:`${t}/${i}`,pubDate:void 0,author:``,category:[`精华`],description:``}}).filter(e=>e.link&&e.title)}async function u(n){return n.link?await t.tryGet(n.link,async()=>{let t=r(await e(n.link))(`pre`);if(t.length>0){let e=t.html();e&&(n.description=e.replaceAll(`<font color="#E6E6DD">cool18.com</font>`,``))}return n}):n}async function d(t){let{id:n=`bbs4`,type:i=`home`,keyword:d}=t.req.param(),f=i,p=n===`global`,m=p?`https://www.cool18.com`:`https://www.cool18.com/${n}/index.php`,h=a(m,f,d,p),g=r(await e(h)),_=t.req.query(`limit`),v=_?Number.parseInt(_,10):20,y;if(p&&(f===`search`||f===`threadsearch`))y=c(g,v);else switch(f){case`home`:y=o(g,m,v);break;case`gold`:y=l(g,m,v);break;case`threadsearch`:case`search`:y=s(g,m,v);break;default:y=s(g,m,v);break}let b=await Promise.all(y.map(e=>u(e)));return{title:g(`title`).text(),link:h,item:b}}export{i as route};