Files
RSSHub/lib/routes/36kr/utils.ts
T
dependabot[bot]andTony 07834413f5 chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0 (#22219)
* chore(deps-dev): bump eslint-plugin-unicorn from 64.0.0 to 65.0.0

Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 64.0.0 to 65.0.0.
- [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases)
- [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v64.0.0...v65.0.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-unicorn
  dependency-version: 65.0.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix: no-array-from-fill

* fix: unicorn-js/no-duplicate-set-values

* fix: no-this-outside-of-class

* fix: no-unnecessary-nested-ternary

* fix: prefer-array-last-methods

* fix: prefer-queue-microtask

* fix: prefer-split-limit

* fix: no-array-from-fill

* fix: no-unused-array-method-return

* fix: prefer-single-call

* fix: prefer-includes-over-repeated-comparisons

* fix: consistent-compound-words

* fix: prefer-includes-over-repeated-comparisons

* chore: add eslint-plugin-unicorn v65 recommended preset

* fix: correct duration parsing logic in parseDuration function

* fix: update oxlint-disable

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2026-06-09 00:08:15 +08:00

65 lines
2.1 KiB
TypeScript

import { load } from 'cheerio';
import CryptoJS from 'crypto-js';
import { solveWafChallenge } from '@/routes/juejin/utils';
import cache from '@/utils/cache';
import ofetch from '@/utils/ofetch';
export const rootUrl = 'https://www.36kr.com';
export const ProcessItem = (item, tryGet) =>
tryGet(item.link, async () => {
const detailResponse = await ofetch(item.link);
const cipherTextList = detailResponse.match(/\{"state":"(.*)","isEncrypt":true\}/) ?? [];
if (cipherTextList.length === 0) {
const $ = load(detailResponse);
item.description = $('div.articleDetailContent').html();
} else {
const key = CryptoJS.enc.Utf8.parse('efabccee-b754-4c');
const content = JSON.parse(
CryptoJS.AES.decrypt(cipherTextList[1], key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
})
.toString(CryptoJS.enc.Utf8)
.toString()
).articleDetail.articleDetailData.data;
item.description = content.widgetContent;
}
return item;
});
export const getWafTokenId = () =>
cache.tryGet(
'36kr:_waftokenid',
async () => {
const captchaResponse = await ofetch(rootUrl);
const $ = load(captchaResponse);
const payload = $('script')
.text()
.match(/atob\('(.*?)'\)\),/)?.[1];
const response = solveWafChallenge(payload);
const tokenIdResponse = await ofetch.raw(rootUrl, {
headers: {
Cookie: `_wafchallengeid=${response};`,
},
redirect: 'manual',
});
const _wafTokenId = tokenIdResponse.headers
.getSetCookie()
.find((cookie) => cookie.startsWith('_waftokenid='))
?.split(';', 1)[0]
.split('=', 2)[1];
return _wafTokenId as string;
},
300, // server-provided value
false
);