-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import type { Namespace } from '@/types'; | ||
|
||
export const namespace: Namespace = { | ||
name: '精真估', | ||
url: 'www.jingzhengu.com', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Route } from '@/types'; | ||
import { NewsInfo, NewsDetail } from './types'; | ||
|
||
import cache from '@/utils/cache'; | ||
import ofetch from '@/utils/ofetch'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import timezone from '@/utils/timezone'; | ||
import { sign } from './utils'; | ||
|
||
export const route: Route = { | ||
path: '/news', | ||
categories: ['other'], | ||
example: '/jingzhengu/news', | ||
radar: [ | ||
{ | ||
source: ['www.jingzhengu.com'], | ||
}, | ||
], | ||
name: '资讯', | ||
maintainers: ['TonyRL'], | ||
handler, | ||
url: 'www.jingzhengu.com', | ||
}; | ||
|
||
async function handler() { | ||
const baseUrl = 'https://www.jingzhengu.com'; | ||
|
||
const payload: Map<string, any> = new Map([ | ||
['pageNo', 1], | ||
['middleware', String(Date.now())], | ||
]); | ||
const response = await ofetch<NewsInfo>(`${baseUrl}/news/makeNewsInfo`, { | ||
method: 'POST', | ||
body: { | ||
...Object.fromEntries(payload), | ||
sign: sign(payload), | ||
}, | ||
}); | ||
|
||
const list = response.data.articles.map((item) => ({ | ||
title: item.title, | ||
description: item.summary, | ||
link: `${baseUrl}/#/cn/Details_${item.addDate.split(' ')[0].replaceAll('-', '')}${item.id}.html`, | ||
pubDate: timezone(parseDate(item.addDate, 'YYYY-MM-DD HH:mm:ss'), 8), | ||
author: item.author, | ||
id: item.id, | ||
})); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const payload: Map<string, any> = new Map([ | ||
['id', item.id], | ||
['middleware', String(Date.now())], | ||
]); | ||
|
||
const response = await ofetch<NewsDetail>(`${baseUrl}/news/makeNewsDetail`, { | ||
method: 'POST', | ||
body: { | ||
...Object.fromEntries(payload), | ||
sign: sign(payload), | ||
}, | ||
}); | ||
|
||
item.description = response.data.content; | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
return { | ||
title: '精真估 > 资讯', | ||
link: `${baseUrl}/#/index/boot`, | ||
item: items, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
interface Article { | ||
addDate: string; | ||
author: string; | ||
channelId: number; | ||
content: string; | ||
externalUrl: string; | ||
firstPage: string; | ||
fromArticleId: number; | ||
fromChannelId: number; | ||
id: number; | ||
img2: string; | ||
imgUrl: string; | ||
isImg: number; | ||
summary: string; | ||
title: string; | ||
viewNum: number; | ||
} | ||
|
||
interface pageInf { | ||
currentPage: number; | ||
pageCount: number; | ||
pageSize: number; | ||
pageTotal: number; | ||
} | ||
|
||
export interface NewsInfo { | ||
code: number; | ||
data: { | ||
articles: Article[]; | ||
pageInf: pageInf; | ||
}; | ||
msg: string; | ||
} | ||
|
||
export interface NewsDetail { | ||
code: number; | ||
data: Article; | ||
msg: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import md5 from '@/utils/md5'; | ||
|
||
function link(str: string, ...args: string[]): string { | ||
let result = args.map((arg) => arg + str).join(''); | ||
if (result.search('-')) { | ||
result = result.substring(0, result.length - 1); | ||
} | ||
return result; | ||
} | ||
|
||
function replaceCharAt(str: string, index: number, replacement: string) { | ||
return index < 0 || index >= str.length ? str : str.slice(0, index) + replacement + str.slice(index + 1); | ||
} | ||
|
||
export function sign(payload: Map<string, any>) { | ||
const map = new Map(); | ||
const lowerCaseKeys: string[] = []; | ||
|
||
for (const [key, value] of payload.entries()) { | ||
const lowerCaseKey = key.toLowerCase(); | ||
lowerCaseKeys.push(lowerCaseKey); | ||
map.set(lowerCaseKey, typeof value === 'string' ? value.toLowerCase() : value); | ||
} | ||
|
||
const sortedString = lowerCaseKeys | ||
.sort() | ||
.map((key) => key + '=' + map.get(key)) | ||
.join(''); | ||
const linkedString = link('--'.substring(0, 1), '#CEAIWER', '892F', 'KB97', 'JKB6', 'HJ7OC7C8', 'GJZG'); | ||
const lastSeparatorIndex = linkedString.lastIndexOf('--'.substring(0, 1)); // 32 | ||
const replacedString = replaceCharAt(linkedString, lastSeparatorIndex, ''); // #CEAIWER-892F-KB97-JKB6-HJ7OC7C8GJZG | ||
const finalString = (sortedString + replacedString).toLowerCase(); | ||
|
||
return md5(finalString); | ||
} |