11const got = require ( '@/utils/got' ) ;
22const 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
57module . 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 } ` ,
0 commit comments