Skip to content

Commit

Permalink
fix(route): zhihu x-zse-96 v3 (DIYgod#11022)
Browse files Browse the repository at this point in the history
* fix(route): zhihu x-zse-96 v3

* revert: "chore: fix docker build (DIYgod#10956)"

This reverts commit 5af05ea.

* revert: "fix(dockerfile): add missing librsvg2 for arm64/v7 (DIYgod#11021)"

This reverts commit f340a90.

* chore: yarn rebuild

* fix: typo

* refactor: simpler got request

* fix: misc fixes
  • Loading branch information
TonyRL authored Oct 7, 2022
1 parent f340a90 commit 8486e9d
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 634 deletions.
12 changes: 1 addition & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ WORKDIR /app

# place ARG statement before RUN statement which need it to avoid cache miss
ARG USE_CHINA_NPM_REGISTRY=0
ARG TARGETPLATFORM
RUN \
set -ex && \
if [ "$USE_CHINA_NPM_REGISTRY" = 1 ]; then \
Expand All @@ -18,15 +17,6 @@ RUN \
COPY ./yarn.lock /app/
COPY ./package.json /app/

# required for building canvas in arm64 and arm/v7 (introduce in #10954)
RUN \
set -ex && \
if [ "$TARGETPLATFORM" != "linux/amd64" ]; then \
apt-get update && \
apt-get install -yq --no-install-recommends \
libpango1.0-dev ; \
fi;

# lazy install Chromium to avoid cache miss, only install production dependencies to minimize the image size
RUN \
set -ex && \
Expand Down Expand Up @@ -146,7 +136,7 @@ RUN \
; \
else \
apt-get install -yq --no-install-recommends \
chromium librsvg2-2 \
chromium \
&& \
echo 'CHROMIUM_EXECUTABLE_PATH=chromium' | tee /app/.env ; \
fi; \
Expand Down
15 changes: 5 additions & 10 deletions lib/v2/zhihu/activities.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable no-console */
const got = require('@/utils/got');
const utils = require('./utils');
const { parseDate } = require('@/utils/parse-date');
const g_encrypt = require('./execlib/g_encrypt_3');
const zhihu_hash = require('./execlib/hash.js');
const g_encrypt = require('./execlib/x-zse-96_v3');
const md5 = require('@/utils/md5');

module.exports = async (ctx) => {
const id = ctx.params.id;
Expand All @@ -14,9 +13,7 @@ module.exports = async (ctx) => {

// fisrt: get cookie(dc_0) from zhihu.com
const cookie_mes = await ctx.cache.tryGet('zhihu:cookies:d_c0', async () => {
const response = await got({
method: 'get',
url: `https://www.zhihu.com/people/${id}`,
const response = await got(`https://www.zhihu.com/people/${id}`, {
headers: {
...utils.header,
},
Expand All @@ -38,12 +35,10 @@ module.exports = async (ctx) => {

// calculate x-zse-96, refer to https://github.com/srx-2000/spider_collection/issues/18
const f = `101_3_3.0+${apiPath}+${cookie_mes}`;
const xzse96 = '2.0_' + g_encrypt(zhihu_hash(f));
const xzse96 = '2.0_' + g_encrypt(md5(f));
const _header = { cookie, 'x-zse-96': xzse96, 'x-app-za': 'OS=Web', 'x-zse-93': '101_3_3.0' };

const response = await got({
method: 'get',
url: `https://www.zhihu.com/api/v3/moments/${id}/activities?limit=7&desktop=true`,
const response = await got(`https://www.zhihu.com${apiPath}`, {
headers: {
...utils.header,
..._header,
Expand Down
Loading

0 comments on commit 8486e9d

Please sign in to comment.