From cce38cfd7540bc568812725e7ff652e52fa4924d Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 12 Aug 2021 16:08:43 +0800 Subject: [PATCH] fix(route): 1X Gallery (#7923) --- docs/en/picture.md | 8 ++++-- docs/picture.md | 50 ++++++++++++++++---------------- lib/router.js | 2 +- lib/routes/1x/index.js | 65 +++++++++++++++++++++++++++++++----------- 4 files changed, 81 insertions(+), 44 deletions(-) diff --git a/docs/en/picture.md b/docs/en/picture.md index 453e3276bf..57d1066001 100644 --- a/docs/en/picture.md +++ b/docs/en/picture.md @@ -8,11 +8,13 @@ pageClass: routes ### Photos - + -| Picture Category | Code | +| Category | Title | | ---------------- | ------------- | -| All categories | all | +| Latest awarded | latest | +| Popular | popular | +| Latest published | published | | Abstract | abstract | | Action | action | | Animals | animals | diff --git a/docs/picture.md b/docs/picture.md index 8d13903e62..6a23adbc18 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -8,31 +8,33 @@ pageClass: routes ### Photos - + -| 图片类别 | 代码 | -| -------------- | ------------- | -| All categories | all | -| Abstract | abstract | -| Action | action | -| Animals | animals | -| Architecture | architecture | -| Conceptual | conceptual | -| Creative edit | creative-edit | -| Documentary | documentary | -| Everyday | everyday | -| Fine Art Nude | fine-art-nude | -| Humour | humour | -| Landscape | landscape | -| Macro | macro | -| Mood | mood | -| Night | night | -| Performance | performance | -| Portrait | portrait | -| Still life | still-life | -| Street | street | -| Underwater | underwater | -| Wildlife | wildlife | +| Category | Title | +| ---------------- | ------------- | +| Latest awarded | latest | +| Popular | popular | +| Latest published | published | +| Abstract | abstract | +| Action | action | +| Animals | animals | +| Architecture | architecture | +| Conceptual | conceptual | +| Creative edit | creative-edit | +| Documentary | documentary | +| Everyday | everyday | +| Fine Art Nude | fine-art-nude | +| Humour | humour | +| Landscape | landscape | +| Macro | macro | +| Mood | mood | +| Night | night | +| Performance | performance | +| Portrait | portrait | +| Still life | still-life | +| Street | street | +| Underwater | underwater | +| Wildlife | wildlife | diff --git a/lib/router.js b/lib/router.js index 50da0f0c89..ded22da6a3 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3386,7 +3386,7 @@ router.get('/chaping/news/:caty?', require('./routes/chaping/news')); router.get('/feixuew/:id?', require('./routes/feixuew/index')); // 1X -router.get('/1x/:type?/:caty?', require('./routes/1x/index')); +router.get('/1x/:category?', require('./routes/1x/index')); // 剑网3 router.get('/jx3/:caty?', require('./routes/jx3/news')); diff --git a/lib/routes/1x/index.js b/lib/routes/1x/index.js index 5e4fc0c2b9..fee5008011 100644 --- a/lib/routes/1x/index.js +++ b/lib/routes/1x/index.js @@ -1,36 +1,69 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const categories = { + latest: 'latest', + popular: 'popular', + published: 'published', + abstract: 'latest:15:', + action: 'latest:1:', + animals: 'latest:21:', + architecture: 'latest:11:', + conceptual: 'latest:17:', + 'creative-edit': 'latest:10:', + documentary: 'latest:8:', + everyday: 'latest:14:', + 'fine-art-nude': 'latest:12:', + humour: 'latest:3:', + landscape: 'latest:6:', + macro: 'latest:2:', + mood: 'latest:4:', + night: 'latest:9:', + performance: 'latest:19:', + portrait: 'latest:13:', + 'still-life': 'latest:18:', + street: 'latest:7:', + underwater: 'latest:20:', + wildlife: 'latest:5:', +}; + module.exports = async (ctx) => { - ctx.params.type = ctx.params.type || 'latest'; - ctx.params.caty = ctx.params.caty || 'all'; + const category = ctx.params.category || 'latest'; const rootUrl = `https://1x.com`; - const currentUrl = `${rootUrl}/photos/${ctx.params.type}/${ctx.params.caty}`; + const currentUrl = `${rootUrl}/gallery/${category}`; + const apiUrl = `${rootUrl}/backend/lm.php?style=normal&mode=${categories[category]}&from=0&autoload=`; const response = await got({ method: 'get', - url: currentUrl, + url: apiUrl, }); const $ = cheerio.load(response.data); - const list = $('#photos_target') - .find('td a img') - .slice(0, 30) - .map((_, item) => { + const items = $('root data') + .html() + .split('\n') + .slice(0, -1) + .map((item) => { item = $(item); + + const id = item + .find('.photos-feed-image') + .attr('id') + .match(/img-(\d+)/)[1]; + return { - title: item.attr('title'), - link: `${rootUrl}/${item.parent().attr('href')}`, - description: ``, - author: item.attr('title'), + guid: id, + link: `${rootUrl}/photo/${id}`, + author: item.find('.photos-feed-data-name').eq(0).text(), + title: item.find('.photos-feed-data-title').text() || 'Untitled', + description: ``, }; - }) - .get(); + }); ctx.state.data = { - title: `${$('title').text()} - ${ctx.params.caty}`, + title: `${category} - 1X`, link: currentUrl, - item: list, + item: items, }; };