diff --git a/docs/design.md b/docs/design.md index 61709f535..44f74ac3b 100755 --- a/docs/design.md +++ b/docs/design.md @@ -37,7 +37,10 @@ pageClass: routes ## Unit Image - +### Films + + + ## 站酷 ### 推荐 diff --git a/docs/en/design.md b/docs/en/design.md index 93ebe05ed..753ff96ba 100755 --- a/docs/en/design.md +++ b/docs/en/design.md @@ -24,6 +24,9 @@ pageClass: routes + ## Unit Image - +### Films + + diff --git a/lib/router.js b/lib/router.js index e9e010cb8..3fb8d5c13 100755 --- a/lib/router.js +++ b/lib/router.js @@ -2556,5 +2556,5 @@ router.get('/51voa/:channel', require('./routes/51voa/channel')); router.get('/zhuixinfan/list', require('./routes/zhuixinfan/list')); // unit-image -router.get('/unit-image', require('./routes/unit-image/films')); +router.get('/unit-image/films/:type?', require('./routes/unit-image/films')); module.exports = router; diff --git a/lib/routes/unit-image/films.js b/lib/routes/unit-image/films.js index ef309c7b4..bdb51e40f 100755 --- a/lib/routes/unit-image/films.js +++ b/lib/routes/unit-image/films.js @@ -1,19 +1,17 @@ const got = require('@/utils/got'); module.exports = async (ctx) => { + const type = ctx.params.type ? `?filter=${ctx.params.type}` : ''; + const dataurl = `https://www.unit-image.fr/data/en/wp-json/unitimage/v1/films${type}`; const response = await got({ method: 'get', - url: `https://www.unit-image.fr/data/en/wp-json/unitimage/v1/films`, + url: dataurl, }); - const data = response.data.slice(0, 5); - const list = data.content.posts; + const data = response.data; + const list = data.content.posts.slice(0, 5); const articledata = await Promise.all( list.map(async (item) => { const url = `https://www.unit-image.fr/data/en/wp-json/unitimage/v1${item.href}`; // 获取所有文章URL - const cache = await ctx.cache.get(url); // 这里是不是单单缓存 URL? - if (cache) { - return Promise.resolve(JSON.phrase(cache)); // 如果有 URL 的缓存,则返回 JSON.phrase 的数据 - } const response2 = await got({ method: 'get', @@ -65,14 +63,13 @@ module.exports = async (ctx) => { compare, bhts, }; - ctx.cache.set(url, JSON.stringify(single)); // 设定缓存为序列化文章数据 return Promise.resolve(single); // 返回 articledata 为序列化文章数据。 }) ); ctx.state.data = { // 源标题 - title: `Unit Image Films`, + title: `Unit Image | ${ctx.params.type}`, // 源链接 link: `https://www.unit-image.fr/films`, // 源说明