Add files via upload

This commit is contained in:
潇洒 2024-10-15 07:35:23 +08:00 committed by GitHub
parent d9d1703015
commit 0d678cba92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6827 additions and 6538 deletions

File diff suppressed because one or more lines are too long

145
JS/drpy2.min.js vendored
View File

@ -18,6 +18,8 @@ cheerio.jinja2 = function(template, obj) {
return _jinja2(template, obj)
}
};
let vercode = typeof pdfl === "function" ? "drpy2.1" : "drpy2";
const VERSION = vercode + " 3.9.51beta5 20241014";
function init_test() {
console.log("init_test_start");
@ -204,8 +206,6 @@ function pre() {
}
}
let rule = {};
let vercode = typeof pdfl === "function" ? "drpy2.1" : "drpy2";
const VERSION = vercode + " 3.9.51beta2 20240711";
const MOBILE_UA = "Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.91 Mobile Safari/537.36";
const PC_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36";
const UA = "Mozilla/5.0";
@ -1284,6 +1284,38 @@ function keysToLowerCase(obj) {
}, {})
}
function parseQueryString(query) {
const params = {};
query.split("&").forEach(function(part) {
const regex = /^(.*?)=(.*)/;
const match = part.match(regex);
if (match) {
const key = decodeURIComponent(match[1]);
const value = decodeURIComponent(match[2]);
params[key] = value
}
});
return params
}
function encodeIfContainsSpecialChars(value) {
const specialChars = ":/?#[]@!$'()*+,;=%";
if (specialChars.split("").some(char => value.includes(char))) {
return encodeURIComponent(value)
}
return value
}
function objectToQueryString(obj) {
const encoded = [];
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
encoded.push(encodeURIComponent(key) + "=" + encodeIfContainsSpecialChars(obj[key]))
}
}
return encoded.join("&")
}
function request(url, obj, ocr_flag) {
ocr_flag = ocr_flag || false;
if (typeof obj === "undefined" || !obj || obj === {}) {
@ -1343,6 +1375,14 @@ function request(url, obj, ocr_flag) {
if (obj.redirect === false) {
obj.redirect = 0
}
if (obj.headers.hasOwnProperty("Content-Type") || obj.headers.hasOwnProperty("content-type")) {
if (obj.headers["Content-Type"].includes("application/x-www-form-urlencoded")) {
log("body");
if (typeof obj.body == "string") {
let temp_obj = parseQueryString(obj.body)
}
}
}
console.log(JSON.stringify(obj.headers));
console.log("request:" + url + `|method:${obj.method||"GET"}|body:${obj.body||""}`);
let res = req(url, obj);
@ -2551,8 +2591,12 @@ function init(ext) {
if (typeof ext == "object") {
rule = ext
} else if (typeof ext == "string") {
if (ext.startsWith("http") || ext.startsWith("file://")) {
let is_file = ext.startsWith("file://");
if (ext.startsWith("http") || is_file) {
let query = getQuery(ext);
if (is_file) {
ext = ext.split("?")[0]
}
let js = request(ext, {
method: "GET"
});
@ -2561,7 +2605,11 @@ function init(ext) {
eval("(function(){" + js.replace("var rule", "rule") + "})()")
}
if (query.type === "url" && query.params) {
rule.params = urljoin(ext, query.params)
if (is_file && /^http/.test(query.params)) {
rule.params = query.params
} else {
rule.params = urljoin(ext, query.params)
}
} else if (query.params) {
rule.params = query.params
}
@ -2699,13 +2747,15 @@ function init(ext) {
} catch (e) {
console.log(`处理headers发生错误:${e.message}`)
}
} else {
rule.headers = {}
}
oheaders = deepCopy(rule.headers);
rule_fetch_params = {
headers: rule.headers || false,
headers: rule.headers,
timeout: rule.timeout,
encoding: rule.encoding
};
oheaders = rule.headers || {};
RKEY = typeof key !== "undefined" && key ? key : "drpy_" + (rule.title || rule.host);
pre();
init_test()
@ -2867,6 +2917,89 @@ function getRule(key) {
return key ? rule[key] || "" : rule
}
function deepCopy(_obj) {
return JSON.parse(JSON.stringify(_obj))
}
function matchesAll(str, pattern, flatten) {
if (!pattern.global) {
pattern = new RegExp(pattern.source, "g" + (pattern.ignoreCase ? "i" : "") + (pattern.multiline ? "m" : ""))
}
var matches = [];
var match;
while ((match = pattern.exec(str)) !== null) {
matches.push(match)
}
return flatten ? matches.flat() : matches
}
function stringUtils() {
Object.defineProperties(String.prototype, {
replaceX: {
value: function(regex, replacement) {
let matches = matchesAll(this, regex, true);
if (matches && matches.length > 1) {
const hasCaptureGroup = /\$\d/.test(replacement);
if (hasCaptureGroup) {
return this.replace(regex, m => m.replace(regex, replacement))
} else {
return this.replace(regex, (m, p1) => m.replace(p1, replacement))
}
}
return this.replace(regex, replacement)
},
configurable: true,
enumerable: false,
writable: true
},
parseX: {
get: function() {
try {
return JSON.parse(this)
} catch (e) {
console.log(e.message);
return this.startsWith("[") ? [] : {}
}
},
configurable: true,
enumerable: false
}
})
}
function cut(text, start, end, method, All) {
let result = "";
let c = (t, s, e) => {
let result = "";
let rs = [];
let results = [];
try {
let lr = new RegExp(String.raw`${s}`.toString());
let rr = new RegExp(String.raw`${e}`.toString());
const segments = t.split(lr);
if (segments.length < 2) return "";
let cutSegments = segments.slice(1).map(segment => {
let splitSegment = segment.split(rr);
return splitSegment.length < 2 ? undefined : splitSegment[0] + e
}).filter(f => f);
if (All) {
return `[${cutSegments.join(",")}]`
} else {
return cutSegments[0]
}
} catch (e) {
console.log(`Error cutting text:${e.message}`)
}
return result
};
result = c(text, start, end);
stringUtils();
if (method && typeof method === "function") {
result = method(result)
}
return result
}
function DRPY() {
return {
runMain: runMain,