fix(route): 1X Gallery (#7923)

This commit is contained in:
Ethan Shen
2021-08-12 16:08:43 +08:00
committed by GitHub
parent 64dc230548
commit cce38cfd75
4 changed files with 81 additions and 44 deletions

View File

@@ -8,11 +8,13 @@ pageClass: routes
### Photos
<RouteEn author="nczitzk" example="/1x/latest/all" path="/1x/:type?/:caty?" :paramsDesc="['sort type, `latest` by default, or `popular` or `curators-choice`', 'picture category, `all` by default, see below']">
<RouteEn author="nczitzk" example="/1x" path="/1x/:category?" :paramsDesc="['Category, Latest awarded by default, see below']">
| Picture Category | Code |
| Category | Title |
| ---------------- | ------------- |
| All categories | all |
| Latest awarded | latest |
| Popular | popular |
| Latest published | published |
| Abstract | abstract |
| Action | action |
| Animals | animals |

View File

@@ -8,31 +8,33 @@ pageClass: routes
### Photos
<Route author="nczitzk" example="/1x/latest/all" path="/1x/:type?/:caty?" :paramsDesc="['排序类型,默认为 `latest`,亦可选 `popular``curators-choice`', '图片类别,默认为 `all`,见下表']">
<Route author="nczitzk" example="/1x" path="/1x/:category?" :paramsDesc="['类别,默认为 Latest awarded,见下表']">
| 图片类别 | 代码 |
| -------------- | ------------- |
| 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 |
</Route>

View File

@@ -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'));

View File

@@ -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: `<img src="${item.attr('src')}">`,
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: `<img src="${item.find('.photos-feed-image').attr('src')}">`,
};
})
.get();
});
ctx.state.data = {
title: `${$('title').text()} - ${ctx.params.caty}`,
title: `${category} - 1X`,
link: currentUrl,
item: list,
item: items,
};
};