Files
RSSHub/lib/v2/linkedin/cn/utils.js
T
Felix Hsuanddependabot[bot] a47a886f29 fix(route): linkedin.cn Fix the job desc section formatting error with renderer by attributes. (#11736)
* fix(route): xiaomiyoupin crowdfunding error and migrate to v2

* initial commit

* add searchHit

* add jobPosting

* linkedincn

* add linkedincn ok

* feat(route): 中国新闻周刊 (#11665)

* feat(route): 中国新闻周刊

* fix: decode via iconv instead of puppeteer

* fix: cache full text request

* Update lib/v2/inewsweek/index.js

* fix: exact publish time

* fix: timezone

* feat(route): 修复 HelloGitHub 的 月刊 路由 (#11675)

* feat(route): 添加 百度股市通

* fix: 修改 百度股市通 路径

* docs: 添加 百度股市通 文档

* feat: 添加 radar 支持

* fix: 按字母顺序插入新路由

* feat(route): 新增 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪

* fix: 优化 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 的标题

* fix: 修复 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 部分情况下的非空判断

* fix: 修复 地区名称标题的问题

* fix: 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 的 guid 增加 pubDate

* fix: 修复 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 guid 中添加 pubDate

* fix: 修改 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 的 title

* feat(route): 修复 HelloGitHub 的 月刊 路由

* fix: remove guid

* fix(route): x6d (#11676)

* chore(deps): bump rand-user-agent from 1.0.101 to 1.0.102 (#11678)

Bumps [rand-user-agent](https://github.com/WebScrapingAPI/rand-user-agent) from 1.0.101 to 1.0.102.
- [Release notes](https://github.com/WebScrapingAPI/rand-user-agent/releases)
- [Commits](https://github.com/WebScrapingAPI/rand-user-agent/commits)

---
updated-dependencies:
- dependency-name: rand-user-agent
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump @sentry/node from 7.31.1 to 7.32.1 (#11680)

Bumps [@sentry/node](https://github.com/getsentry/sentry-javascript) from 7.31.1 to 7.32.1.
- [Release notes](https://github.com/getsentry/sentry-javascript/releases)
- [Changelog](https://github.com/getsentry/sentry-javascript/blob/master/CHANGELOG.md)
- [Commits](https://github.com/getsentry/sentry-javascript/compare/7.31.1...7.32.1)

---
updated-dependencies:
- dependency-name: "@sentry/node"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump jsdom from 21.0.0 to 21.1.0 (#11681)

Bumps [jsdom](https://github.com/jsdom/jsdom) from 21.0.0 to 21.1.0.
- [Release notes](https://github.com/jsdom/jsdom/releases)
- [Changelog](https://github.com/jsdom/jsdom/blob/master/Changelog.md)
- [Commits](https://github.com/jsdom/jsdom/compare/21.0.0...21.1.0)

---
updated-dependencies:
- dependency-name: jsdom
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): bump puppeteer from 19.5.2 to 19.6.0 (#11679)

Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 19.5.2 to 19.6.0.
- [Release notes](https://github.com/puppeteer/puppeteer/releases)
- [Changelog](https://github.com/puppeteer/puppeteer/blob/main/release-please-config.json)
- [Commits](https://github.com/puppeteer/puppeteer/compare/puppeteer-v19.5.2...puppeteer-v19.6.0)

---
updated-dependencies:
- dependency-name: puppeteer
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat(route): famitsu (#11682)

* fix(route): xiaomiyoupin crowdfunding error and migrate to v2 (#11677)

* fix(route): xiaomiyoupin crowdfunding error and migrate to v2

* Update lib/v2/xiaomiyoupin/maintainer.js

* Update docs/shopping.md

* use single api endpoint for both module

* add pubDate()

* fix(route): ikea (#11685)

* chore(deps): bump @sentry/node from 7.32.1 to 7.33.0 (#11687)

Bumps [@sentry/node](https://github.com/getsentry/sentry-javascript) from 7.32.1 to 7.33.0.
- [Release notes](https://github.com/getsentry/sentry-javascript/releases)
- [Changelog](https://github.com/getsentry/sentry-javascript/blob/master/CHANGELOG.md)
- [Commits](https://github.com/getsentry/sentry-javascript/compare/7.32.1...7.33.0)

---
updated-dependencies:
- dependency-name: "@sentry/node"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps-dev): bump jest from 29.3.1 to 29.4.0 (#11686)

Bumps [jest](https://github.com/facebook/jest/tree/HEAD/packages/jest) from 29.3.1 to 29.4.0.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/commits/v29.4.0/packages/jest)

---
updated-dependencies:
- dependency-name: jest
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix(route): bloomberg videopage parse error (#11688)

* fix(route): clickme (#11689)

* fix(route): lofter (#11696)

* fix(route): caixin blog (#11695)

* fix(route): caixin blog

* fix: url

* chore(deps): bump ioredis from 5.2.5 to 5.3.0 (#11697)

Bumps [ioredis](https://github.com/luin/ioredis) from 5.2.5 to 5.3.0.
- [Release notes](https://github.com/luin/ioredis/releases)
- [Changelog](https://github.com/luin/ioredis/blob/main/CHANGELOG.md)
- [Commits](https://github.com/luin/ioredis/compare/v5.2.5...v5.3.0)

---
updated-dependencies:
- dependency-name: ioredis
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix(route): bioone (#11699)

* feat(route): github wiki history (#11700)

* feat(route): wuhan (#11701)

Co-authored-by: nczitzk <nczitzk@gmail.com>

* chore(deps): bump puppeteer from 19.6.0 to 19.6.1 (#11702)

Bumps [puppeteer](https://github.com/puppeteer/puppeteer) from 19.6.0 to 19.6.1.
- [Release notes](https://github.com/puppeteer/puppeteer/releases)
- [Changelog](https://github.com/puppeteer/puppeteer/blob/main/release-please-config.json)
- [Commits](https://github.com/puppeteer/puppeteer/compare/puppeteer-v19.6.0...puppeteer-v19.6.1)

---
updated-dependencies:
- dependency-name: puppeteer
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps-dev): bump jest from 29.4.0 to 29.4.1 (#11703)

Bumps [jest](https://github.com/facebook/jest/tree/HEAD/packages/jest) from 29.4.0 to 29.4.1.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/commits/v29.4.1/packages/jest)

---
updated-dependencies:
- dependency-name: jest
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix(route): fix date err and refactor to v2 (#11705)

* fix(route): fix date err and refactor to v2

* docs: add en docs

* fix: typo

* feat(route): add mixcloud (#11672)

* feat(route): add mixcloud

* docs

* feat(route): add mixcloud

* convert linebreaks to <br>

* docs: add supportPodcast

* codestyle: use template literals

* refactor: split graph ql queries

* fix(route): 软餐 (#11708)

* feat(route): gelonghui (#11710)

* chore(deps): bump @sentry/node from 7.33.0 to 7.34.0 (#11711)

Bumps [@sentry/node](https://github.com/getsentry/sentry-javascript) from 7.33.0 to 7.34.0.
- [Release notes](https://github.com/getsentry/sentry-javascript/releases)
- [Changelog](https://github.com/getsentry/sentry-javascript/blob/master/CHANGELOG.md)
- [Commits](https://github.com/getsentry/sentry-javascript/compare/7.33.0...7.34.0)

---
updated-dependencies:
- dependency-name: "@sentry/node"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix(route): fix not unique guid and refactor to v2 (#11712)

* add null check

* add more null check for compensation

* remove unused key

* refactor: change route

* fix typo

* add desc text formatting and caching

* posting forget to accept

* Fix async/await mismatch

* Fix async/await mismatch on ctx.cache.tryGet

---------
2023-02-01 00:52:03 +08:00

123 lines
3.8 KiB
JavaScript

const crypto = require('crypto');
const path = require('path');
const { art } = require('@/utils/render');
const got = require('@/utils/got');
const { parseAttr } = require('./renderer');
const apiUrl = 'https://www.linkedin.cn/karpos/api/graphql';
const searchHitQueryId = 'searchSearchHitsByJob.be362cd720abd0ebf89b4bbc3253047f';
const jobPostingQueryId = 'jobsJobPostingsById.3b9573e88687a86607ddb74ff013ef50';
const makeHeader = () => {
const sessionId = crypto.randomBytes(8).toString('hex').slice(0, 8);
const headers = {
Accept: '*/*',
Cookie: `JSESSIONID="ajax:${sessionId}"`,
'Content-Type': 'application/x-www-form-urlencoded',
Referer: 'https://www.linkedin.cn/incareer/jobs/search',
'csrf-token': `ajax:${sessionId}`,
'x-http-method-override': 'GET',
'x-restli-protocol-version': '2.0.0',
};
return headers;
};
const period = {
1: 'r86400',
7: 'r604800',
30: 'r2592000',
};
const location = {
china: '102890883',
shanghai: '102772228',
beijing: '103873152',
};
const makeVariables = (variables) =>
'(' +
Object.entries(variables)
.filter(([, v]) => v)
.map(([k, v]) => `${k}:${encodeURIComponent(v)}`)
.join(',') +
')';
const makeBody = (body) => {
let output = '';
Object.entries(body).forEach(([key, value], index) => {
output += `${key}=${value}`;
if (index < Object.keys(body).length - 1) {
output += '&';
}
});
return output;
};
const ctxToTitle = (ctx) => {
const { keywords } = ctx.params;
const { geo, remote, location, period, relevant } = ctx.query;
const g = location || geo || 'China';
const r = remote ? '远程' : '';
const p = period ? `近${period}天` : '';
const o = relevant ? '相关' : '最新';
return `${o}${p}在${g}的${keywords || ''}${r}工作机会`;
};
const parseSearchHit = async (ctx) => {
const variables = {
origin: 'jserp',
isForRemoteJobsPage: !!ctx.query.remote,
isChinaMultiNationalCorporation: false,
count: ctx.query.limit || 20,
start: '0',
geoUrn: `urn:li:ks_geo:${location[ctx.query.location] || ctx.query.geo || location.china}`,
keywords: decodeURIComponent(ctx.params.keywords || ''),
f_TPR: period[ctx.query.period] || '',
sortType: ctx.query.relevant ? '' : 'DATE_DESCENDING',
};
const resp = await got.post(apiUrl, {
headers: makeHeader(),
body: makeBody({
operationName: 'searchSearchHitsByJob',
variables: makeVariables(variables),
queryId: searchHitQueryId,
}),
});
return {
jobs: resp.data.data.searchSearchHitsByJob.elements.map((e) => e.target.jobPosting),
title: ctxToTitle(ctx),
};
};
const parseJobPosting = (ctx, jobPosting) => {
const entityUrn = jobPosting.entityUrn;
return ctx.cache.tryGet(`linkedincn:${entityUrn}`, async () => {
const resp = await got.post(apiUrl, {
headers: makeHeader(),
body: makeBody({
operationName: 'jobViewPage',
variables: makeVariables({
jobPostingUrn: entityUrn,
}),
queryId: jobPostingQueryId,
}),
});
const job = resp.data.data.jobsJobPostingsById;
job.desc = parseAttr(job.description);
return {
title: `${jobPosting.companyName} 正在找 ${jobPosting.title}`,
link: `https://www.linkedin.cn/incareer/jobs/view/${entityUrn.split(':').pop()}`,
guid: `linkedincn:${entityUrn}`,
description: art(path.join(__dirname, '../templates/cn/posting.art'), job),
pubDate: jobPosting.listedAt,
};
});
};
module.exports = {
parseSearchHit,
parseJobPosting,
};