mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-11-29 08:37:00 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
792d7210a7 |
No files matched your search
@@ -423,6 +423,38 @@ public class LzTool extends PanBase {
|
|||||||
return "/" + ajax.group(1);
|
return "/" + ajax.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 分享页 / iframe 里的文件 ajax 表单;提取不到时返回 null。 */
|
||||||
|
static Map<String, String> fileAjaxForm(String html, String pwd) {
|
||||||
|
AjaxCall call = extractAjaxFromHtml(html, pwd);
|
||||||
|
return call == null ? null : call.form();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件 ajax 头。官方页把下载 POST 打到 apifile / apifile2 等跨站主机,
|
||||||
|
* 浏览器会带 Origin 且 Sec-Fetch-Site=cross-site;写 same-origin 与 Referer 矛盾,部分出口会被 ESA 拦。
|
||||||
|
*/
|
||||||
|
static MultiMap fileAjaxHeaders(String pageUrl, String ajaxTarget) {
|
||||||
|
MultiMap headers = HeaderUtils.parseHeaders(DOWN_AJAX_HEADERS);
|
||||||
|
String page = pageUrl == null ? "" : pageUrl.trim();
|
||||||
|
if (!page.isEmpty()) {
|
||||||
|
headers.set("referer", page);
|
||||||
|
}
|
||||||
|
String pageOrigin = normalizeOrigin(originOf(page, ""));
|
||||||
|
String ajaxOrigin = originFromAjaxTarget(ajaxTarget);
|
||||||
|
if (ajaxOrigin.isEmpty()) {
|
||||||
|
ajaxOrigin = pageOrigin;
|
||||||
|
}
|
||||||
|
if (!pageOrigin.isEmpty()) {
|
||||||
|
headers.set("origin", pageOrigin);
|
||||||
|
}
|
||||||
|
if (!ajaxOrigin.isEmpty() && !ajaxOrigin.equalsIgnoreCase(pageOrigin)) {
|
||||||
|
headers.set("Sec-Fetch-Site", "cross-site");
|
||||||
|
} else {
|
||||||
|
headers.set("Sec-Fetch-Site", "same-origin");
|
||||||
|
}
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
private static void addAjaxOrigin(List<String> origins, String origin) {
|
private static void addAjaxOrigin(List<String> origins, String origin) {
|
||||||
if (origin != null && origin.contains("://") && !origins.contains(origin)) {
|
if (origin != null && origin.contains("://") && !origins.contains(origin)) {
|
||||||
origins.add(origin);
|
origins.add(origin);
|
||||||
@@ -814,13 +846,12 @@ public class LzTool extends PanBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getDownURL(String referer, AjaxCall call) {
|
private void getDownURL(String referer, AjaxCall call) {
|
||||||
MultiMap headers = HeaderUtils.parseHeaders(DOWN_AJAX_HEADERS);
|
// 文件 ajax 优先用页面里的绝对地址(常见 apifile / apifile2)。
|
||||||
// 文件 ajax 优先用页面里的绝对地址(常见 apifile.lanzouw.com)。
|
|
||||||
// 页面源站空响应再换 FILE_AJAX_FALLBACK_ORIGINS,wwww 仍在最后。
|
// 页面源站空响应再换 FILE_AJAX_FALLBACK_ORIGINS,wwww 仍在最后。
|
||||||
// iframe / 分享页的 Referer 保持原主机,不把页面 GET 改写到 wwww。
|
// iframe / 分享页的 Referer 保持原主机,不把页面 GET 改写到 wwww。
|
||||||
String page = referer != null && !referer.isBlank() ? referer : resolveShareUrl();
|
String page = referer != null && !referer.isBlank() ? referer : resolveShareUrl();
|
||||||
headers.set("referer", page);
|
|
||||||
String target = call.absoluteUrl() != null ? call.absoluteUrl() : call.path();
|
String target = call.absoluteUrl() != null ? call.absoluteUrl() : call.path();
|
||||||
|
MultiMap headers = fileAjaxHeaders(page, target);
|
||||||
postAjaxAt(fileAjaxOrigins(page, target), 0, call, headers, this::handleAjaxDownResponse, null);
|
postAjaxAt(fileAjaxOrigins(page, target), 0, call, headers, this::handleAjaxDownResponse, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,17 @@ public class HttpResponseHelper {
|
|||||||
|
|
||||||
// -------------------- Buffer 转换 --------------------
|
// -------------------- Buffer 转换 --------------------
|
||||||
private static Buffer toBuffer(HttpResponse<?> res) {
|
private static Buffer toBuffer(HttpResponse<?> res) {
|
||||||
return res.body() instanceof Buffer ? (Buffer) res.body() : Buffer.buffer(res.bodyAsString());
|
Object raw = res.body();
|
||||||
|
if (raw instanceof Buffer buf) {
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
// 407/空 body 时 body() 与 bodyAsString() 都可能是 null,Buffer.buffer(null) 会 NPE,
|
||||||
|
// 最终被当成「ajax 返回非JSON: 空响应」。
|
||||||
|
if (raw == null) {
|
||||||
|
return Buffer.buffer();
|
||||||
|
}
|
||||||
|
String text = res.bodyAsString();
|
||||||
|
return text == null ? Buffer.buffer() : Buffer.buffer(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ensureBodyLimit(Buffer body) {
|
private static void ensureBodyLimit(Buffer body) {
|
||||||
|
|||||||
@@ -237,4 +237,51 @@ public class LzToolShareUrlTest {
|
|||||||
assertEquals("https://wwww.lanzoux.com", origins.get(origins.size() - 1));
|
assertEquals("https://wwww.lanzoux.com", origins.get(origins.size() - 1));
|
||||||
assertFalse(origins.get(0).contains("wwww"));
|
assertFalse(origins.get(0).contains("wwww"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void passwordPageUsesApifile2AndIsngisSign() {
|
||||||
|
String html = """
|
||||||
|
<div class="passwddiv-btn" onclick="down_p();"></div>
|
||||||
|
<input id="pwd" />
|
||||||
|
<script type="text/javascript">
|
||||||
|
function down_p(){
|
||||||
|
var kdns =1;
|
||||||
|
var isngis = '';
|
||||||
|
var isngis = 'SIGNVALUEFROMISNGIS';
|
||||||
|
var pwd =document.getElementById('pwd').value;
|
||||||
|
$.ajax({
|
||||||
|
type : 'post',
|
||||||
|
url : 'https://apifile2.woozooo.com/ajaxfile.php?file=333149117',
|
||||||
|
data : { 'action':'downprocess','sign':isngis,'kd':kdns,'p':pwd, },
|
||||||
|
dataType : 'json'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
""";
|
||||||
|
String target = LzTool.fileAjaxTarget(html);
|
||||||
|
assertEquals("https://apifile2.woozooo.com/ajaxfile.php?file=333149117", target);
|
||||||
|
Map<String, String> form = LzTool.fileAjaxForm(html, "1t54");
|
||||||
|
assertEquals("downprocess", form.get("action"));
|
||||||
|
assertEquals("SIGNVALUEFROMISNGIS", form.get("sign"));
|
||||||
|
assertEquals("1", form.get("kd"));
|
||||||
|
assertEquals("1t54", form.get("p"));
|
||||||
|
List<String> origins = LzTool.fileAjaxOrigins("https://wwaov.lanzouw.com/iNUOu4hbih4h", target);
|
||||||
|
assertEquals("https://apifile2.woozooo.com", origins.get(0));
|
||||||
|
|
||||||
|
io.vertx.core.MultiMap headers = LzTool.fileAjaxHeaders(
|
||||||
|
"https://wwaov.lanzouw.com/iNUOu4hbih4h", target);
|
||||||
|
assertEquals("https://wwaov.lanzouw.com/iNUOu4hbih4h", headers.get("referer"));
|
||||||
|
assertEquals("https://wwaov.lanzouw.com", headers.get("origin"));
|
||||||
|
assertEquals("cross-site", headers.get("Sec-Fetch-Site"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sameOriginFileAjaxKeepsSameSiteFetchMetadata() {
|
||||||
|
io.vertx.core.MultiMap headers = LzTool.fileAjaxHeaders(
|
||||||
|
"https://apifile.lanzouw.com/fn?x", "/ajaxfile.php?file=1");
|
||||||
|
assertEquals("same-origin", headers.get("Sec-Fetch-Site"));
|
||||||
|
assertEquals("https://apifile.lanzouw.com", headers.get("origin"));
|
||||||
|
assertEquals("https://apifile.lanzouw.com/fn?x", headers.get("referer"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user