import{t as e}from"./config-BYRrjYC5.mjs";import{t}from"./cache-DUthuMSu.mjs";import{t as n}from"./got-BBDj7u1e.mjs";import{t as r}from"./rss-parser-CtkSf1Et.mjs";import{FetchError as i}from"ofetch";const a={path:`/:lang/:category?`,categories:[`new-media`],example:`/malaysiakini/en`,parameters:{lang:`Language, see below`,category:`Category, see below, news by default`},features:{requirePuppeteer:!1,antiCrawler:!1,supportBT:!1,supportPodcast:!1,supportScihub:!1,requireConfig:[{name:`MALAYSIAKINI_EMAIL`,optional:!0,description:`Malaysiakini Email or Username`},{name:`MALAYSIAKINI_PASSWORD`,optional:!0,description:`Malaysiakini Password`},{name:`MALAYSIAKINI_REFRESHTOKEN`,optional:!0,description:"To obtain the refresh token, log into Malaysiakini and look for the cookie `nl____refreshToken` within document.cookie in the browser console. The token is the value of the cookie."}]},name:`News`,maintainers:[`quiniapiezoelectricity`],handler:o,description:"\n| Language | English | Bahasa Malaysia | 华文     |\n| -------- | ------ | ------- | ------ | \n| `:lang`  | `en`    | `my`   | `zh`    |\n\n| Category               | `:category` |\n| ---------------------- | ------------- |\n| News                   | `news`      |\n| Columns                | `columns`   |\n| From Our Readers       | `letters`   |",radar:[{source:[`malaysiakini.com/`],target:`/en`},{source:[`malaysiakini.com/:lang`],target:`/:lang`},{source:[`www.malaysiakini.com/:lang/latest/:category`],target:`/:lang/:category`}]};async function o(a){let o=a.req.param(`lang`),s=a.req.param(`category`)??`news`,c={email:e.malaysiakini.email,password:e.malaysiakini.password,apiKey:`UFXL7F1EL53S8DZ5SGJUMG5IIFVRY4WI`},l=JSON.stringify(c),u,d=await t.get(`malaysiakini:cookie`);if(d&&(u=d),u===void 0&&e.malaysiakini.email&&e.malaysiakini.password){let e=await n.post(`https://membership.malaysiakini.com/api/v1/auth/local`,{headers:{"Content-Type":`application/json`,Accept:`*/*`,Connection:`keep-alive`},body:l});e.data.accessToken&&e.data.refreshToken&&(u=`nl____accessToken=${e.data.accessToken}; nl____refreshToken=${e.data.refreshToken};`,t.set(`malaysiakini:cookie`,u))}u===void 0&&e.malaysiakini.refreshToken&&(u=`nl____refreshToken=${e.malaysiakini.refreshToken};`,t.set(`malaysiakini:cookie`,u));let f=`https://www.malaysiakini.com/rss/${o}/${s}.rss`,p=await r.parseURL(f);if(u)try{await n({method:`get`,url:`https://www.malaysiakini.com/api/full_content/${p.items[0].guid}`,headers:{Cookie:u}})}catch(e){throw e instanceof i&&e.statusCode===401&&await t.set(`malaysiakini:cookie`,``),e}let m=await Promise.all(p.items.map(e=>t.tryGet(e.link,async()=>{let t=await n(`https://www.malaysiakini.com/api/content/${e.guid}`);if(t.data.stories.content)e.description=t.data.stories.content;else if(e.description=t.data.stories.teaser,u){let t;try{t=await n({method:`get`,url:`https://www.malaysiakini.com/api/full_content/${e.guid}`,headers:{Cookie:u}})}finally{t&&(e.description=t.data.content)}}if(t.data.stories.image_feat){let n=t.data.stories.image_feat;n.length>0&&(e.description=`<img src=${n[0]}>`+e.description)}return t.data.stories.author&&(e.author=t.data.stories.author),t.data.stories.tags&&(e.category=t.data.stories.tags),e})));return{title:p.title,link:p.link,description:p.description,language:o,item:m}}export{a as route};