From b023b6034ea0f47fbafb396fa530c8e2eb7ba27b Mon Sep 17 00:00:00 2001 From: wushijishan <65406369+wushijishan@users.noreply.github.com> Date: Sat, 17 Jul 2021 17:11:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E4=BA=8C=E6=9F=84APP=20(#7799)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: auto-bot-ty <75887908+auto-bot-ty@users.noreply.github.com> Co-authored-by: auto-bot-ty <1093034894@qq.com> --- lib/routes/erbingapp/news.js | 67 ++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/lib/routes/erbingapp/news.js b/lib/routes/erbingapp/news.js index b09d19920..411474b34 100644 --- a/lib/routes/erbingapp/news.js +++ b/lib/routes/erbingapp/news.js @@ -1,42 +1,51 @@ const got = require('@/utils/got'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const response = await got({ method: 'get', url: `https://api.diershoubing.com:5001/feed/tag/?pn=0&rn=20&tag_type=0&src=ios`, - resolveBodyOnly: true, - responseType: 'json', }); - const data = response.feeds; + const data = JSON.parse(response.body).feeds; + const items = data.map((item) => { + let description = `

${item.content}

`; + const acontent = item.acontent.toString(); + const ProcessDesc = (link, type) => { + if (type) { + description += `

More

`; + } else { + for (const item of link) { + description += `

`; + } + } + }; + + if (item.video_img !== null) { + ProcessDesc([item.video_img]); + } else if (acontent.indexOf('104129') !== -1) { + ProcessDesc([item.article.humb.split('?')[0]]); + } else if (acontent.indexOf('.html') !== -1) { + ProcessDesc([acontent], 'html'); + } else if (acontent.indexOf('"imgs') !== -1) { + const imgs = JSON.parse(acontent).imgs.split(','); + ProcessDesc(imgs); + } else { + const imgs = acontent.split(','); + ProcessDesc(imgs); + } + return { + title: item.title, + link: item.share.url, + description, + pubDate: timezone(parseDate(item.create_time), +8), + }; + }); ctx.state.data = { title: `二柄APP`, - link: `https://www.diershoubing.com/`, + link: `https://www.diershoubing.com`, description: `二柄APP新闻`, - item: data.map((item) => { - let description = item.content; - if (item.video_img !== null) { - description += `
`; - } else if (item.acontent.indexOf('104129') !== -1) { - description += `
`; - } else if (item.acontent.indexOf('.html') !== -1) { - description += `
More`; - } else if (item.acontent.indexOf('"imgs') !== -1) { - const imgs = item.acontent.split(','); - for (let i = 1; i < imgs.length; i++) { - description += `
`; - } - } else { - const imgs = item.acontent.split(','); - for (let i = 0; i < imgs.length; i++) { - description += `
`; - } - } - return { - description, - link: item.share.url, - title: item.title, - }; - }), + item: items, }; };