From f4b05dbe34e8e1a533c7ffd15bea812a73a8441a Mon Sep 17 00:00:00 2001 From: minty_frankie <77310871+mintyfrankie@users.noreply.github.com> Date: Wed, 5 Jun 2024 17:40:44 +0200 Subject: [PATCH] fix(route): update The Inithium authentication method (#15797) * fix: delete deprecated INITIUM_IAP_RECEIPT authentication method * fix(route): fix username and password authentication method * chore: update route maintainers * fix: delete all fields for iap_receipt * fix: delete finally all IAP_RECEIPT field * fix: correct login request headers --- lib/config.ts | 4 +--- lib/routes/theinitium/channel.ts | 2 +- lib/routes/theinitium/follow.ts | 7 +------ lib/routes/theinitium/utils.ts | 20 ++------------------ 4 files changed, 5 insertions(+), 28 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index 34d1c0f45..9acd71a49 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -1,5 +1,5 @@ -import 'dotenv/config'; import randUserAgent from '@/utils/rand-user-agent'; +import 'dotenv/config'; import { ofetch } from 'ofetch'; let envs = process.env; @@ -154,7 +154,6 @@ export type Config = { username?: string; password?: string; bearertoken?: string; - iap_receipt?: string; }; instagram: { username?: string; @@ -513,7 +512,6 @@ const calculateValue = () => { username: envs.INITIUM_USERNAME, password: envs.INITIUM_PASSWORD, bearertoken: envs.INITIUM_BEARER_TOKEN, - iap_receipt: envs.INITIUM_IAP_RECEIPT, }, instagram: { username: envs.IG_USERNAME, diff --git a/lib/routes/theinitium/channel.ts b/lib/routes/theinitium/channel.ts index b418b0921..762446b68 100644 --- a/lib/routes/theinitium/channel.ts +++ b/lib/routes/theinitium/channel.ts @@ -6,7 +6,7 @@ const handler = (ctx) => processFeed('channel', ctx); export const route: Route = { path: '/channel/:type?/:language?', name: '专题・栏目', - maintainers: ['prnake'], + maintainers: ['prnake', 'mintyfrankie'], parameters: { type: '栏目,缺省为最新', language: '语言,简体`zh-hans`,繁体`zh-hant`,缺省为简体', diff --git a/lib/routes/theinitium/follow.ts b/lib/routes/theinitium/follow.ts index 84fd599f3..6c4d1d4d2 100644 --- a/lib/routes/theinitium/follow.ts +++ b/lib/routes/theinitium/follow.ts @@ -20,7 +20,7 @@ export const route: Route = { handler, example: '/theinitium/author/ninghuilulu/zh-hans', categories: ['new-media'], - description: 'Web 版认证 token 和 iOS 内购回执认证 token 只需选择其一填入即可。你也可选择直接在环境设置中填写明文的用户名和密码', + description: '需填入 Web 版认证 token, 也可选择直接在环境设置中填写明文的用户名和密码', features: { requireConfig: [ { @@ -28,11 +28,6 @@ export const route: Route = { optional: true, description: `端传媒 Web 版认证 token。获取方式:登陆后打开端传媒站内任意页面,打开浏览器开发者工具中 “网络”(Network) 选项卡,筛选 URL 找到任一个地址为 \`api.initium.com\` 开头的请求,点击检查其 “消息头”,在 “请求头” 中找到Authorization字段,将其值复制填入配置即可。你的配置应该形如 \`INITIUM_BEARER_TOKEN: 'Bearer eyJxxxx......xx_U8'\`。使用 token 部署的好处是避免占据登陆设备数的额度,但这个 token 一般有效期为两周,因此只可作临时测试使用。`, }, - { - name: 'INITIUM_IAP_RECEIPT', - optional: true, - description: `端传媒 iOS 版内购回执认证 token。获取方式:登陆后打开端传媒 iOS app 内任意页面,打开抓包工具,筛选 URL 找到任一个地址为 \`api.initium.com\` 开头的请求,点击检查其 “消息头”,在 “请求头” 中找到 \`X-IAP-Receipt\` 字段,将其值复制填入配置即可。你的配置应该形如 \`INITIUM_IAP_RECEIPT: ef81dee9e4e2fe084a0af1ea82da2f7b16e75f756db321618a119fa62b52550e\`。`, - }, { name: 'INITIUM_USERNAME', optional: true, diff --git a/lib/routes/theinitium/utils.ts b/lib/routes/theinitium/utils.ts index 3a818fcf3..5ede1da12 100644 --- a/lib/routes/theinitium/utils.ts +++ b/lib/routes/theinitium/utils.ts @@ -39,7 +39,6 @@ export const processFeed = async (model: string, ctx: Context) => { const key = { email: config.initium.username, password: config.initium.password, - iapReceipt: config.initium.iap_receipt, }; const body = JSON.stringify(key); @@ -59,25 +58,11 @@ export const processFeed = async (model: string, ctx: Context) => { Accept: 'application/json', Connection: 'keep-alive', Authorization: TOKEN, - Origin: `https://theinitium.com/`, - Referer: `https://theinitium.com/`, - 'X-Client-Name': 'Web', }, body, }); - /* - const devices = login.data.access.devices; - - for (const key in devices) { - const device = devices[key]; - if (device.status === 'logged_in' && !device.logout_at && device.platform === 'web') { - token = 'Bearer ' + device.device_id; - break; - } - } - */ - token = 'Bearer ' + login.data.token; + token = 'token ' + login.data.token; cache.set('initium:token', token); } @@ -85,7 +70,6 @@ export const processFeed = async (model: string, ctx: Context) => { Accept: '*/*', Connection: 'keep-alive', Authorization: token, - 'X-IAP-Receipt': key.iapReceipt || '', }; let response; @@ -154,7 +138,7 @@ export const processFeed = async (model: string, ctx: Context) => { const items = await Promise.all( articles .filter((a) => a.article) - .slice(0, token === TOKEN && key.iapReceipt === undefined ? 25 : articles.length) + .slice(0, token === TOKEN ? 25 : articles.length) .map(async (item) => { item.article.date = parseDate(item.article.date); item.article.updated = parseDate(item.article.updated);