Skip to content

Commit 6f8c2a2

Browse files
authored
Merge pull request #947 from DIYgod/master
[pull] master from diygod:master
2 parents 81d327c + 48c624b commit 6f8c2a2

File tree

7 files changed

+54
-34
lines changed

7 files changed

+54
-34
lines changed

docs/shopping.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ For instance, in <https://www.zagg.com/en_us/new-arrivals?brand=164&cat=3038%2C3
328328

329329
### 搜索结果
330330

331-
<Route author="fengkx" example="/duozhuayu/search/JavaScript" path="/duozhuayu/search/:wd" :paramsDesc="['搜索关键词']"/>
331+
<Route author="fengkx" example="/duozhuayu/search/JavaScript" path="/duozhuayu/search/:wd" :paramsDesc="['搜索关键词']" radar="1"/>
332332

333333
## 逛丢
334334

lib/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ router.get('/allpoetry/:order?', lazyloadRouteHandler('./routes/allpoetry/order'
11641164
// router.get('/wallstreetcn/live/:channel?', lazyloadRouteHandler('./routes/wallstreetcn/live'));
11651165

11661166
// 多抓鱼搜索
1167-
router.get('/duozhuayu/search/:wd', lazyloadRouteHandler('./routes/duozhuayu/search'));
1167+
// router.get('/duozhuayu/search/:wd', lazyloadRouteHandler('./routes/duozhuayu/search'));
11681168

11691169
// 创业邦
11701170
router.get('/cyzone/author/:id', lazyloadRouteHandler('./routes/cyzone/author'));

lib/v2/duozhuayu/maintainer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
'/search/:wd': ['fengkx'],
3+
};

lib/v2/duozhuayu/radar.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
'duozhuayu.com': {
3+
_name: '多抓鱼',
4+
'.': [
5+
{
6+
title: '搜索结果',
7+
docs: 'https://docs.rsshub.app/shopping.html#duo-zhua-yu',
8+
source: ['/search/book/:wd'],
9+
target: '/duozhuayu/search/:wd',
10+
},
11+
],
12+
},
13+
};

lib/v2/duozhuayu/router.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = (router) => {
2+
router.get('/search/:wd', require('./search'));
3+
};
Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
const got = require('@/utils/got');
22
const aesjs = require('aes-js');
3-
const queryString = require('query-string');
3+
const { art } = require('@/utils/render');
4+
const { join } = require('path');
5+
const { parseDate } = require('@/utils/parse-date');
46

57
module.exports = async (ctx) => {
68
const wd = ctx.params.wd;
7-
const link = `https://www.duozhuayu.com/search/${wd}`;
9+
const baseUrl = 'https://www.duozhuayu.com';
10+
const type = 'book';
11+
const link = `${baseUrl}/search/${type}/${wd}`;
812

913
// token获取见 https://github.com/wong2/userscripts/blob/master/duozhuayu.user.js
1014
const key = 'DkOliWvFNR7C4WvR'.split('').map((c) => c.charCodeAt());
@@ -24,48 +28,35 @@ module.exports = async (ctx) => {
2428
const token = encrypt([timestamp, userId, securityKey].join(':'));
2529
const requestId = [userId, timestamp, Math.round(1e5 * Math.random())].join('-');
2630
return {
27-
'x-timestamp': timestamp,
31+
'x-api-version': '0.0.48',
32+
'x-refer-request-id': requestId,
33+
'x-request-id': requestId,
34+
'x-request-misc': '{"platform":"browser","originSource":"search","originFrom":"normal","webVersion":"1.2.201774"}',
35+
'x-request-token': token,
2836
'x-security-key': securityKey,
37+
'x-timestamp': timestamp,
2938
'x-user-id': userId,
30-
'x-request-token': token,
31-
'x-request-misc': '{"platform":"browser"}',
32-
'x-api-version': '0.0.15',
33-
'x-request-id': requestId,
34-
'x-refer-request-id': requestId,
3539
};
3640
};
3741

3842
const response = await got({
3943
method: 'get',
40-
url: 'https://www.duozhuayu.com/api/search',
41-
searchParams: queryString.stringify({
44+
url: `${baseUrl}/api/search/book`,
45+
searchParams: {
4246
type: 'normal',
4347
q: wd,
44-
}),
48+
},
4549
headers: getCustomRequestHeaders(),
4650
});
47-
const books = response.data.data || [];
4851

49-
const item = books
50-
.filter((item) => item.type === 'book')
51-
.map((item) => {
52-
const book = item.book;
53-
return {
54-
title: book.title,
55-
link: `https://www.duozhuayu.com/books/${book.id}`,
56-
pubDate: new Date(book.updated).toUTCString(),
57-
description: `
58-
<img src="${book.images.origin}" ><br>
59-
书名:${book.title} ${book.originalTitle}<br>
60-
作者:${book.rawAuthor}<br>
61-
ISBN:${book.isbn13}<br>
62-
出版社:${book.publisher}<br>
63-
出版时间:${book.publishDate}<br>
64-
价格:${(book.price / 100).toFixed(2)}元起 <del>${(book.originalPrice / 100).toFixed(2)}元</del><br>
65-
`,
66-
guid: book.id,
67-
};
68-
});
52+
const item = response.data.data
53+
.filter((item) => item.type === type)
54+
.map(({ [type]: item }) => ({
55+
title: item.title,
56+
link: `${baseUrl}/books/${item.id}`,
57+
pubDate: parseDate(item.updated), // 2023-05-07T13:33:09+08:00
58+
description: art(join(__dirname, 'templates/book.art'), { item }),
59+
}));
6960

7061
ctx.state.data = {
7162
title: `多抓鱼搜索-${wd}`,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<img src="{{ item.images.origin }}"><br>
2+
书名:{{ item.title }} {{ item.originalTitle }}<br>
3+
{{ if item.subtitle }}{{ item.subtitle }}<br>{{ /if }}
4+
作者:{{ item.rawAuthor }}<br>
5+
{{ if item.translators && item.translators.length }}译者:{{ item.translators.map((t) => t.name).join(' / ') }}<br>{{ /if }}
6+
ISBN:{{ item.isbn13 }}<br>
7+
出版社:{{ item.publisher }}<br>
8+
出版时间:{{ item.publishDate }}<br>
9+
豆瓣评分:{{ item.doubanRating }}<br>
10+
价格:{{ (item.price / 100).toFixed(2) }}元起 <del>{{ (item.originalPrice / 100).toFixed(2) }}元</del>

0 commit comments

Comments
 (0)