Skip to content

Commit

Permalink
feat(route): stream-capital (#15719)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored May 26, 2024
1 parent 26dfc27 commit 50c1bb7
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/routes/stream-capital/namespace.ts
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.stream-capital.com',
};
79 changes: 79 additions & 0 deletions lib/routes/stream-capital/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Route } from '@/types';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import { encrypt, decrypt } from './utils';
import { EncryptedResponse, WebBlog } from './types';
import cache from '@/utils/cache';

export const route: Route = {
path: '/search',
name: '最新',
categories: ['finance'],
example: '/stream-capital/search',
maintainers: ['TonyRL'],
handler,
radar: [
{
source: ['www.stream-capital.com/search'],
},
],
};

async function handler() {
const baseUrl = 'https://www.stream-capital.com';
const apiBaseUrl = 'https://api.yuanchuan.cn';

const response = await ofetch<EncryptedResponse>(`${apiBaseUrl}/yc/webbloglist`, {
method: 'POST',
query: {
apptype: 9,
},
body: encrypt(
JSON.stringify({
type: 0,
name: null,
page: 1,
})
),
});

const list = (JSON.parse(decrypt(response.data)).list as WebBlog[]).map((item) => ({
title: item.title,
author: item.userName,
pubDate: timezone(parseDate(item.ctime, 'YYYY-MM-DD HH:mm:ss'), 8),
link: `${baseUrl}/article/${item.id}`,
description: item.content,
category: item.tags.map((t) => t.tagName),
id: item.id,
}));

const items = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const response = await ofetch<EncryptedResponse>(`${apiBaseUrl}/yc/webblogdetail`, {
method: 'POST',
query: {
apptype: 9,
},
body: encrypt(
JSON.stringify({
blogId: item.id,
})
),
});

item.description = (JSON.parse(decrypt(response.data)) as WebBlog).detailInfo.articleContent;

return item;
})
)
);

return {
title: '最新 - 远川研究所',
link: `${baseUrl}/search`,
language: 'zh',
item: items,
};
}
44 changes: 44 additions & 0 deletions lib/routes/stream-capital/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export interface EncryptedResponse {
code: number;
data: string;
msg: string;
}

interface Tag {
blogId: number;
tagId: number;
length: number;
tagName: string;
beginIndex: number;
}

interface DetailInfo {
articleContent: string;
blogId: number;
videoCoverPicUrl: string;
excerpt: string;
id: number;
videoUrl: string;
}

export interface WebBlog {
title: string;
type: number;
intro: null;
avatarUrl: null;
userName: string;
ctime: string;
isPublish: number;
id: number;
themeTitle: string;
themeId: number;
viewCount: number;
coverUrl: string;
videoDuration: number;
originUrl: string;
userId: number;
content: string;
tags: Tag[];
isCollect: number;
detailInfo: DetailInfo;
}
18 changes: 18 additions & 0 deletions lib/routes/stream-capital/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import CryptoJS from 'crypto-js';

const secret = CryptoJS.enc.Utf8.parse('r4rt5A8L6ye6ts8y');
const iv = CryptoJS.enc.Utf8.parse('fs0Hkjg8a23u8sE0');

export const encrypt = (plainText) =>
CryptoJS.AES.encrypt(plainText, secret, {
iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
}).toString();

export const decrypt = (encrypted) =>
CryptoJS.AES.decrypt(encrypted, secret, {
iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
}).toString(CryptoJS.enc.Utf8);

0 comments on commit 50c1bb7

Please sign in to comment.