-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix the problem that the search can't pass the verification code
- Loading branch information
Hiram
committed
Mar 29, 2024
1 parent
62e4dc3
commit 3f62128
Showing
2 changed files
with
22 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
/*! | ||
* @module drpy3 | ||
* @brief T3数据处理核心库 | ||
* @version 3.1.0 | ||
* @version 3.1.1 | ||
* | ||
* @original-author hjdhnx | ||
* @original-source {@link https://github.com/hjdhnx/hipy-server/blob/master/app/t4/files/drpy3_libs/drpy3.js | Source on GitHub} | ||
* | ||
* @modified-by HiramWong <[email protected]> | ||
* @modification-date 2023-03-24T18:21:29+08:00 | ||
* @modification-date 2023-03-29T23:02:29+08:00 | ||
* @modification-description 使用TypeScript适配, 适用于JavaScript项目, 并采取措施防止 Tree-Shaking 删除关键代码 | ||
* | ||
* **防止 Tree-Shake 说明**: | ||
|
@@ -87,7 +87,7 @@ const RULE_CK = 'cookie'; // 源cookie的key值 | |
// const KEY = typeof(key)!=='undefined'&&key?key:'drpy_' + (rule.title || rule.host); // 源的唯一标识 | ||
const CATE_EXCLUDE = '首页|留言|APP|下载|资讯|新闻|动态'; | ||
const TAB_EXCLUDE = '猜你|喜欢|下载|剧情|热播'; | ||
const OCR_RETRY = 3;//ocr验证重试次数 | ||
const OCR_RETRY = 3; // ocr验证重试次数 | ||
// const OCR_API = 'http://dm.mudery.com:10000';//ocr在线识别接口 | ||
// const OCR_API = 'http://192.168.3.239:5705/parse/ocr';//ocr在线识别接口 | ||
// const OCR_API = 'http://cms.nokia.press/parse/ocr';//ocr在线识别接口 | ||
|
@@ -816,8 +816,8 @@ const verifyCode = (url) => { | |
let json = JSON.parse(JSON.stringify(hhtml)); | ||
|
||
if (!cookie) { | ||
let setCk = Object.keys(json.headers).find((it) => it.toLowerCase() === 'set-cookie'); | ||
cookie = setCk ? json.headers[setCk].split(';')[0] : ''; | ||
let setCk = Object.keys(json).find(it => it.toLowerCase() === 'set-cookie'); | ||
cookie = setCk ? json[setCk].split(';')[0] : ''; | ||
} | ||
|
||
let img = json.body; | ||
|
@@ -929,7 +929,7 @@ const $require = (url) => { | |
* @param ocr_flag 标识此flag是用于请求ocr识别的,自动过滤content-type指定编码 | ||
* @returns {string|string|DocumentFragment|*} | ||
*/ | ||
const request = (url: string, obj: any = undefined, ocr_flag = false) => { | ||
const request = (url: string, obj: any = undefined, ocr_flag: boolean = false) => { | ||
if (typeof obj === 'undefined' || !obj) { | ||
if (!fetch_params || !fetch_params.headers) { | ||
const headers = { | ||
|
@@ -977,10 +977,9 @@ const request = (url: string, obj: any = undefined, ocr_flag = false) => { | |
const res = req(url, obj); | ||
const html = res["content"] || ''; | ||
if (obj.withHeaders) { | ||
return { | ||
headers: res["headers"], | ||
body: html | ||
} | ||
let htmlWithHeaders = res.headers; | ||
htmlWithHeaders!.body = html; | ||
return JSON.stringify(htmlWithHeaders); | ||
} else { | ||
return html; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
/*! | ||
* @module drpyInject | ||
* @brief T3网络请求、缓存模块处理库 | ||
* @version 3.1.0 | ||
* @version 3.1.1 | ||
* | ||
* @original-author hjdhnx | ||
* @original-source {@link https://github.com/hjdhnx/hipy-server/blob/master/app/utils/quickjs_ctx.py | Source on GitHub} | ||
* | ||
* @modified-by HiramWong <[email protected]> | ||
* @modification-date 2023-03-24T18:21:29+08:00 | ||
* @modification-date 2023-03-29T23:02:29+08:00 | ||
* @modification-description Python转TypeScript, 适用于JavaScript项目 | ||
*/ | ||
|
||
|
@@ -38,17 +38,20 @@ const baseRequest = (_url: string, _object: RequestOptions, _js_type: number = 0 | |
const withHeaders: boolean = _object.withHeaders || false; | ||
const body: string = _object.body || ''; | ||
const bufferType: number = _object.buffer || 0; | ||
let data: { [key: string]: string } = _object.data || {}; | ||
let data: any = _object.data || {}; | ||
const headers = _object.headers || {}; | ||
const emptyResult: Response = { content: '', body: '', headers: {} }; | ||
|
||
if (body && !data) { | ||
data = {}; | ||
if (body && Object.keys(data).length == 0) { | ||
body.split('&').forEach((param) => { | ||
const [key, value] = param.split('='); | ||
data[key] = value; | ||
}); | ||
} | ||
|
||
const headers = _object.headers || {}; | ||
if (headers['Content-Type']?.includes('application/x-www-form-urlencoded')) { | ||
data = new URLSearchParams(data).toString(); | ||
} | ||
|
||
const customHeaders = { | ||
'Cookie': 'custom-cookie', | ||
|
@@ -72,20 +75,16 @@ const baseRequest = (_url: string, _object: RequestOptions, _js_type: number = 0 | |
credentials: 'include' | ||
}); | ||
} else { | ||
headers["Content-Type"] = "application/json" | ||
const requestOptions: any = { | ||
method, | ||
headers, | ||
body: JSON.stringify(data), | ||
body: typeof data === 'string' ? data : JSON.stringify(data), | ||
credentials: 'include' | ||
}; | ||
r = syncFetch(_url, requestOptions); | ||
} | ||
const emptyResult: Response = { content: '', body: '', headers: {} }; | ||
|
||
const formatHeaders: { [key: string]: string } = {}; | ||
|
||
// 遍历 Headers 对象 | ||
for (const [key, value] of r.headers.entries()) { | ||
if (key.toLowerCase() === 'custom-set-cookie') { | ||
formatHeaders['set-cookie'] = value; | ||
|
@@ -103,12 +102,10 @@ const baseRequest = (_url: string, _object: RequestOptions, _js_type: number = 0 | |
} else if (_js_type === 1) { | ||
let content; | ||
if (bufferType === 2) { | ||
// content = Buffer.from(r.arrayBuffer(), 'binary').toString('base64'); | ||
const uint8Array = new Uint8Array(r.arrayBuffer()); // 将 ArrayBuffer 转换为一个 Uint8Array | ||
const buffer = Buffer.from(uint8Array); // 使用 Buffer.from 将 Uint8Array 转换为 Buffer | ||
const base64String = buffer.toString('base64'); // 将 Buffer 转换为 Base64 字符串 | ||
content = base64String; | ||
console.log(base64String); | ||
} else content = r.text(); | ||
return { content, headers: formatHeaders } || emptyResult; | ||
} else { | ||
|
@@ -181,6 +178,9 @@ const local_get = (_id: string, key: string, value: string = '') => { | |
const local_set = (_id, key, value) => { | ||
const headers = { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
data: { | ||
key: `${_id}${key}`, | ||
value | ||
|