feat(router/u3c3): support preview (#14548)
* feat(router/u3c3): support preview * fix(router/u3c3): modify route maintainer
This commit is contained in:
parent
65f09c7ae2
commit
51f79ef184
|
|
@ -2,7 +2,7 @@ const got = require('@/utils/got');
|
|||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type;
|
||||
const { type, keywoard, preview } = ctx.params;
|
||||
// should be:
|
||||
// undefined
|
||||
// U3C3
|
||||
|
|
@ -15,13 +15,12 @@ module.exports = async (ctx) => {
|
|||
const rootURL = 'https://www.u3c3.com';
|
||||
let currentURL;
|
||||
let title;
|
||||
if (type === undefined) {
|
||||
if (keywoard) {
|
||||
currentURL = `${rootURL}/?search=${keywoard}`;
|
||||
title = `search ${keywoard} - u3c3`;
|
||||
} else if (type === undefined) {
|
||||
currentURL = rootURL;
|
||||
title = 'home - u3c3';
|
||||
} else if (type === 'search') {
|
||||
const keyword = ctx.params.keyword === undefined ? '' : ctx.params.keyword;
|
||||
currentURL = `${rootURL}/?search=${keyword}`;
|
||||
title = `search ${keyword} - u3c3`;
|
||||
} else {
|
||||
currentURL = `${rootURL}/?type=${type}&p=1`;
|
||||
title = `${type} - u3c3`;
|
||||
|
|
@ -30,7 +29,7 @@ module.exports = async (ctx) => {
|
|||
const response = await got(currentURL);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const items = $('body > div.container > div.table-responsive > table > tbody > tr')
|
||||
const list = $('body > div.container > div.table-responsive > table > tbody > tr')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
|
@ -50,6 +49,21 @@ module.exports = async (ctx) => {
|
|||
};
|
||||
});
|
||||
|
||||
const items = preview
|
||||
? await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
item.description = $('div.panel-footer > img:first-child').parent().html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
)
|
||||
: list;
|
||||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
description: title,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = {
|
||||
'/:type?/:keyword?': ['noname1897'],
|
||||
'/search/:keyword/:preview?': ['storytellerF'],
|
||||
'/:type?/:preview?': ['noname1897', 'storytellerF'],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/:type?/:keyword?', require('./index'));
|
||||
router.get('/search/:keyword/:preview?', require('./index'));
|
||||
router.get('/:type?/:preview?', require('./index'));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1198,11 +1198,11 @@ Refer to [https://developers.themoviedb.org/3/getting-started/languages](https:/
|
|||
|
||||
### Keyword Search {#u3c3-keyword-search}
|
||||
|
||||
<Route author="noname1897" example="/u3c3/search/les" path="/u3c3/search/:keyword?" paramsDesc={['search keyword']} supportBT="1" radar="1" />
|
||||
<Route author="noname1897" example="/u3c3/search/les" path="/u3c3/search/:keyword/:preview?" paramsDesc={['search keyword', 'Show image preview, off by default, non empty value means on']} supportBT="1" radar="1" />
|
||||
|
||||
### Type {#u3c3-type}
|
||||
|
||||
<Route author="noname1897" example="/u3c3/U3C3" path="/u3c3/:type?" paramsDesc={['type, pay attention to case, it should be exactly same as the choices: `U3C3`/`Video`/`Photo`/`Book`/`Game`/`Software`/`Other`, if no type is provided, show the home index']} supportBT="1" radar="1" />
|
||||
<Route author="noname1897" example="/u3c3/U3C3" path="/u3c3/:type?/:preview?" paramsDesc={['type, pay attention to case, it should be exactly same as the choices: `U3C3`/`Video`/`Photo`/`Book`/`Game`/`Software`/`Other`, if no type is provided, show the home index','Show image preview, off by default, non empty value means on']} supportBT="1" radar="1" />
|
||||
|
||||
## U9A9 {#u9a9}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue