import{t as e}from"./ofetch-Dl6dVB_5.mjs";import{t}from"./parse-date-BdYTmLpo.mjs";import{load as n}from"cheerio";const r=async(t,r)=>{let i=n(await e(t,{headers:{Referer:r,Accept:`application/json, text/plain, */*`}})),a=``;return i(`script`).each((e,t)=>{let n=(i(t).html()||``).match(/PAGE\s*=\s*{\s*id\s*:\s*(\d+)\s*}/);n&&(a=n[1])}),a},i=async(n,r)=>{let i=await e(`${n}/api/top/${r}`,{headers:{Referer:n,Accept:`application/json, text/plain, */*`}}),a=`热榜`;switch(r){case`pic3days`:a+=` - 3天内无聊图`;break;case`pic7days`:a+=` - 7天内无聊图`;break;default:a+=` - 4小时热门`;break}if(i.code===0&&i.data&&Array.isArray(i.data)){let e=i.data.map(e=>{let r=e.content.replaceAll(/img src="(.*?)"/g,(e,t)=>e.replace(t,t.replace(/^https?:\/\/(\w+)\.moyu\.im/,`https://$1.sinaimg.cn`)));return{author:e.author,title:`${e.author}: ${r.replaceAll(/<[^>]+>/g,``)}`,description:r,pubDate:t(e.date),link:`${n}/t/${e.id}`}});return{title:a,items:e}}return{title:a,items:[{title:`获取失败: ${a}`,description:`未能获取热榜数据`,link:`${n}/top`,pubDate:new Date}]}},a=async n=>{let i=`煎蛋 - 鱼塘`,a=`${n}/bbs`;try{let o=await r(a,n);if(!o)return{title:i,items:[{title:`获取失败: ${i}`,description:`无法获取论坛ID`,link:a,pubDate:new Date}]};let s=await e(`${n}/api/forum/posts/${o}?page=1`,{headers:{Referer:a,Accept:`application/json, text/plain, */*`}});return s.code===0&&s.data&&s.data.list&&Array.isArray(s.data.list)?{title:i,items:s.data.list.map(e=>{let r=e.content.replaceAll(/img src="(.*?)"/g,(e,t)=>e.replace(t,t.replace(/^https?:\/\/(\w+)\.moyu\.im/,`https://$1.sinaimg.cn`)));return{author:e.author_name,title:e.title||`${e.author_name}发表了新主题`,description:r,pubDate:t(e.update_time||e.create_time),link:`${n}/bbs#/topic/${e.post_id}`,category:e.reply_count>0?[`${e.reply_count}条回复`]:void 0}})}:{title:i,items:[{title:`获取失败: ${i}`,description:`未能获取鱼塘数据`,link:a,pubDate:new Date}]}}catch(e){return{title:i,items:[{title:`解析错误: 鱼塘`,description:`解析鱼塘页面时出错: ${e instanceof Error?e.message:String(e)}`,link:a,pubDate:new Date}]}}},o=async(i,a)=>{let o=`${i}/${a}`;try{let s=await r(o,i),c=n(await e(o,{headers:{Referer:i,Accept:`application/json, text/plain, */*`}})),l=String(c(`title`).text().trim())||`煎蛋 - ${a}`;if(!s)return{title:l,items:[{title:`无法解析: ${l}`,description:`无法从页面中获取到帖子ID，可能网站结构已变更`,link:o,pubDate:new Date}]};let u=await e(`${i}/api/comment/post/${s}?order=desc&page=1`,{headers:{Referer:o,Accept:`application/json, text/plain, */*`}});return u.code===0&&u.data&&u.data.list&&Array.isArray(u.data.list)?{title:l,items:u.data.list.map(e=>{let n=e.content.replaceAll(/img src="(.*?)"/g,(e,t)=>e.replace(t,t.replace(/^https?:\/\/(\w+)\.moyu\.im/,`https://$1.sinaimg.cn`)));return{author:e.author,title:`${e.author}: ${n.replaceAll(/<[^>]+>/g,``)}`,description:n,pubDate:t(e.date_gmt||e.date),link:`${i}/t/${e.id}`}})}:{title:l,items:[{title:`暂无内容: ${l||a}`,description:`没有获取到内容，可能需要更新解析规则`,link:o,pubDate:new Date}]}}catch{return{title:`煎蛋 - ${a}`,items:[{title:`解析错误: ${a}`,description:`解析页面时出错`,link:o,pubDate:new Date}]}}},s={path:`/:category/:type?`,example:`/jandan/top`,name:`Section`,maintainers:[`nczitzk`,`pseudoyu`],parameters:{category:{description:`板块`,options:[{label:`热榜`,value:`top`},{label:`问答`,value:`qa`},{label:`树洞`,value:`treehole`},{label:`随手拍`,value:`ooxx`},{label:`无聊图`,value:`pic`},{label:`鱼塘`,value:`bbs`}]},type:{description:"热榜类型，仅当 category 选择 `top` 时有效",default:`4hr`,options:[{label:`4小时热门`,value:`4hr`},{label:`3天内无聊图`,value:`pic3days`},{label:`7天内无聊图`,value:`pic7days`}]}},features:{requireConfig:!1,requirePuppeteer:!1,antiCrawler:!1,supportBT:!1,supportPodcast:!1,supportScihub:!1},radar:[{source:[`i.jandan.net/:category`],target:`/jandan/:category?`}],handler:c};async function c(e){let t=e.req.param(`category`)??`top`;t=t.replace(/#.*$/,``);let n=e.req.param(`type`)??`4hr`,r=`http://i.jandan.net`,s=`${r}/${t}`,c;try{c=t===`top`?await i(r,n):t===`bbs`?await a(r):await o(r,t)}catch(e){let n=e instanceof Error?e.message:String(e);c={title:`煎蛋 - ${t}`,items:[{title:`抓取出错: ${t}`,description:`抓取 ${t} 分区时出现错误: ${n}`,link:s,pubDate:new Date}]}}return{title:c.title,link:s,item:c.items}}export{s as route};