From f57dae4adc337c241548fb14c8f2c546b432e6a0 Mon Sep 17 00:00:00 2001 From: chenhb23 Date: Wed, 17 Jul 2024 09:43:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=99=E8=AF=B7=E6=B1=82=E5=8A=A0?= =?UTF-8?q?=E4=B8=8A=E5=90=8C=E6=BA=90referer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/package.json | 2 +- package.json | 2 +- src/common/core/profile.ts | 4 +++- src/common/http.ts | 14 +++++++++++++- src/renderer/store/Config.ts | 1 + src/renderer/store/task/UploadTask.ts | 4 +++- 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/package.json b/app/package.json index 8778003..80b709a 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "lanzouyun-pan", - "version": "3.5.1", + "version": "3.5.2", "private": true, "main": "build/main/index.js", "description": "蓝奏云网盘客户端", diff --git a/package.json b/package.json index 35f6c30..e9e8e68 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lanzouyun-pan", - "version": "3.5.1", + "version": "3.5.2", "private": true, "main": "build/main/index.js", "description": "蓝奏云网盘客户端", diff --git a/src/common/core/profile.ts b/src/common/core/profile.ts index 1a1ba2a..b505b4b 100644 --- a/src/common/core/profile.ts +++ b/src/common/core/profile.ts @@ -2,6 +2,7 @@ import * as http from '../http' import cheerio from 'cheerio' import {Matcher} from './matcher' import type {Config} from '../../renderer/store/Config' +import store from '../store' enum PROFILE_EL { 个性域名 = '个性域名', // domain @@ -39,7 +40,7 @@ export async function profile() { return {...prev, verification: $my('#phone_id', el).text().trim()} } return prev - }, {} as Pick & {supportList: string[]}) + }, {} as Pick & {supportList: string[]}) const iframe = $main('iframe').attr('src') const mainPage = await http.request.get(iframe).text() @@ -48,5 +49,6 @@ export async function profile() { return { ...profiles, more: ajaxData, + referer: new URL(iframe, store.get('lanzouUrl')).href, } } diff --git a/src/common/http.ts b/src/common/http.ts index 8d8076d..767d817 100644 --- a/src/common/http.ts +++ b/src/common/http.ts @@ -1,10 +1,10 @@ import got from 'got' import {cookieJar, shareCookieJar} from './cookie' -import config from '../project.config' import store from './store' import {delay} from './util' import electronApi from '../renderer/electronApi' import {message} from 'antd' +import {config} from '../renderer/store/Config' const base = got.extend({ headers: { @@ -78,6 +78,18 @@ const base = got.extend({ export const request = got.extend(base, { cookieJar, prefixUrl: store.get('lanzouUrl'), + hooks: { + beforeRequest: [ + options => { + if (config.referer && (!options.headers['referer'] || !options.headers['Referer'])) { + const url = typeof options.url === 'string' ? new URL(options.url) : options.url + if (url.origin === new URL(config.referer).origin) { + options.headers['referer'] = config.referer + } + } + }, + ], + }, }) export const share = got.extend(base, { diff --git a/src/renderer/store/Config.ts b/src/renderer/store/Config.ts index b2073d7..7a21535 100644 --- a/src/renderer/store/Config.ts +++ b/src/renderer/store/Config.ts @@ -5,6 +5,7 @@ type BaseProps = Partial