mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-10-11 09:14:25 +00:00
Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13ccdb8adf | ||
|
|
ac1afcd35f | ||
|
|
0c678a4124 | ||
|
|
f77800602d | ||
|
|
79ab829952 | ||
|
|
2181ef38df | ||
|
|
e09c9f76a7 | ||
|
|
7adb938357 | ||
|
|
efb800d88e | ||
|
|
422d5b845b | ||
|
|
054e9cc1ec | ||
|
|
f3da45bb16 | ||
|
|
273dbae5e7 | ||
|
|
e103003b7a | ||
|
|
e853365fe4 | ||
|
|
b5f7d9694b | ||
|
|
f75d9f687b | ||
|
|
703bfa3061 | ||
|
|
6c709fde65 | ||
|
|
449fd741ac | ||
|
|
c18b8d80e1 | ||
|
|
06ba0aff52 | ||
|
|
74e401d99c | ||
|
|
4995bca901 | ||
|
|
7299fd8762 |
@@ -8,7 +8,7 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- '*'
|
- 'v*'
|
||||||
branches-ignore:
|
branches-ignore:
|
||||||
- '*'
|
- '*'
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
@@ -262,9 +262,27 @@ jobs:
|
|||||||
name: ${{ matrix.artifact-name }}
|
name: ${{ matrix.artifact-name }}
|
||||||
path: ${{ matrix.artifact-name }}.zip
|
path: ${{ matrix.artifact-name }}.zip
|
||||||
|
|
||||||
- name: 上传到 Release
|
# ================================================================
|
||||||
|
# 阶段三:创建 GitHub Release(只跑一次,避免矩阵任务重复拼接更新日志)
|
||||||
|
# ================================================================
|
||||||
|
publish-release:
|
||||||
|
name: 发布 GitHub Release
|
||||||
|
needs: native-package
|
||||||
|
if: github.event_name != 'pull_request' && github.ref_type == 'tag'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 下载原生安装包
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
pattern: netdisk-fast-download-*
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
|
- name: 创建 Release
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
files: ${{ matrix.artifact-name }}.zip
|
files: |
|
||||||
|
netdisk-fast-download-linux-amd64.zip
|
||||||
|
netdisk-fast-download-windows-amd64.zip
|
||||||
tag_name: ${{ github.ref_name }}
|
tag_name: ${{ github.ref_name }}
|
||||||
generate_release_notes: true
|
generate_release_notes: true
|
||||||
|
fail_on_unmatched_files: true
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ QQ交流群:1017480890
|
|||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
> 本平台所有音乐解析工具不再维护,请移步[Sonder播放器](https://sodecode.qaiu.top)
|
||||||
|
> 需要百度,迅雷,UC,夸克的完整支持请使用[专业版](https://189.qaiu.top)
|
||||||
|
|
||||||
## 介绍
|
## 介绍
|
||||||
> netdisk-fast-download网盘直链解析可以把云盘分享链接转为直链,可广泛应用于各类下载站,资源站,个人博客,图床,APP下载更新,视频点播等领域。支持市面各大主流云盘的文件分享以及文件夹分享链接,已支持蓝奏云/蓝奏云优享/移动云云空间/小飞机盘/亿方云/123云盘/永硕E盘/Cloudreve等,支持加密分享,以及部分网盘文件夹分享。
|
> netdisk-fast-download网盘直链解析可以把云盘分享链接转为直链,可广泛应用于各类下载站,资源站,个人博客,图床,APP下载更新,视频点播等领域。支持市面各大主流云盘的文件分享以及文件夹分享链接,已支持蓝奏云/蓝奏云优享/移动云云空间/小飞机盘/亿方云/123云盘/永硕E盘/Cloudreve等,支持加密分享,以及部分网盘文件夹分享。
|
||||||
@@ -28,25 +30,31 @@ QQ交流群:1017480890
|
|||||||
[公益解析,lz0站](https://lz0.qaiu.top)
|
[公益解析,lz0站](https://lz0.qaiu.top)
|
||||||
[专业版](https://189.qaiu.top)
|
[专业版](https://189.qaiu.top)
|
||||||
|
|
||||||
|
|
||||||
## 快速开始
|
## 快速开始
|
||||||
命令行下载分享文件:
|
|
||||||
```shell
|
|
||||||
curl -LOJ "https://lz.qaiu.top/parser?url=https://share.feijipan.com/s/Tk1F2kGQ&pwd=1234"
|
|
||||||
```
|
|
||||||
或者使用wget:
|
|
||||||
```shell
|
|
||||||
wget -O bilibili.mp4 "https://lz.qaiu.top/parser?url=https://share.feijipan.com/s/Tk1F2kGQ&pwd=1234"
|
|
||||||
```
|
|
||||||
或者使用浏览器[直接访问](https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.top%2Fparser%3Furl%3Dhttps%3A%2F%2Fwww.ilanzou.com%2Fs%2FCDx6xKbT&name=bilibili.mp4&ext=mp4):
|
|
||||||
```
|
|
||||||
### 调用演示站下载:
|
|
||||||
https://lz.qaiu.top/parser?url=https://www.ilanzou.com/s/CDx6xKbT&pwd=1234
|
|
||||||
### 调用演示站预览:
|
|
||||||
https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.top%2Fparser%3Furl%3Dhttps%3A%2F%2Fwww.ilanzou.com%2Fs%2FCDx6xKbT&name=bilibili.mp4&ext=mp4
|
|
||||||
|
|
||||||
|
以带提取码的分享链接为例(提取码 `1234`),链接中含 `#`、`&`,作为 `url` 参数传入前必须做 URL 编码:
|
||||||
|
|
||||||
|
`https://www.ecpan.cn/web/#/yunpanProxy?path=%2F%23%2Fdrive%2Foutside&data=70017ece572737b12b30709b7f029308eJD0&isShare=1`
|
||||||
|
|
||||||
|
**命令行下载**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# curl
|
||||||
|
curl -LOJ "https://lz.qaiu.top/parser?url=https%3A%2F%2Fwww.ecpan.cn%2Fweb%2F%23%2FyunpanProxy%3Fpath%3D%252F%2523%252Fdrive%252Foutside%26data%3D70017ece572737b12b30709b7f029308eJD0%26isShare%3D1&pwd=1234"
|
||||||
|
|
||||||
|
# wget
|
||||||
|
wget -O v01 "https://lz.qaiu.top/parser?url=https%3A%2F%2Fwww.ecpan.cn%2Fweb%2F%23%2FyunpanProxy%3Fpath%3D%252F%2523%252Fdrive%252Foutside%26data%3D70017ece572737b12b30709b7f029308eJD0%26isShare%3D1&pwd=1234"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**短链方式**(key 取分享链接的 `data` 参数,提取码用 `@` 拼接)
|
||||||
|
|
||||||
|
| 用途 | 地址 |
|
||||||
|
| --- | --- |
|
||||||
|
| 下载 | `https://lz.qaiu.top/ec/70017ece572737b12b30709b7f029308eJD0@1234` |
|
||||||
|
| 在线预览 | [点击访问](https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.top%2Fec%2F70017ece572737b12b30709b7f029308eJD0%401234&name=v01&ext=mp4) |
|
||||||
|
|
||||||
|
> 无提取码时去掉 `&pwd=1234` / `@1234` 即可;预览页 `src` 需编码(`@` → `%40`),用短链可避免二次编码。
|
||||||
|
|
||||||
**解析器模块文档:** [parser/README.md](parser/README.md)
|
**解析器模块文档:** [parser/README.md](parser/README.md)
|
||||||
|
|
||||||
**JavaScript解析器文档:** [JavaScript解析器开发指南](parser/doc/JAVASCRIPT_PARSER_GUIDE.md) | [自定义解析器扩展指南](parser/doc/CUSTOM_PARSER_GUIDE.md) | [快速开始](parser/doc/CUSTOM_PARSER_QUICKSTART.md)
|
**JavaScript解析器文档:** [JavaScript解析器开发指南](parser/doc/JAVASCRIPT_PARSER_GUIDE.md) | [自定义解析器扩展指南](parser/doc/CUSTOM_PARSER_GUIDE.md) | [快速开始](parser/doc/CUSTOM_PARSER_QUICKSTART.md)
|
||||||
@@ -93,7 +101,9 @@ https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.
|
|||||||
- Dropbox-pdp
|
- Dropbox-pdp
|
||||||
- iCloud-pic
|
- iCloud-pic
|
||||||
### 专业版提供
|
### 专业版提供
|
||||||
- 迅雷网盘-xl
|
- 百度网盘开放平台-bd
|
||||||
|
- 迅雷云盘开放平台-xl
|
||||||
|
- [光鸭云盘开放平台-gy](https://www.guangyapan.com)
|
||||||
- [夸克云盘-qk](https://pan.quark.cn/)
|
- [夸克云盘-qk](https://pan.quark.cn/)
|
||||||
- [UC云盘-uc](https://fast.uc.cn/)
|
- [UC云盘-uc](https://fast.uc.cn/)
|
||||||
- [移动云盘-p139](https://yun.139.com/)
|
- [移动云盘-p139](https://yun.139.com/)
|
||||||
@@ -133,6 +143,7 @@ GET /json/parser?url={分享链接}&pwd={密码}
|
|||||||
```
|
```
|
||||||
GET /json/{网盘标识}/{分享key}@{密码}
|
GET /json/{网盘标识}/{分享key}@{密码}
|
||||||
```
|
```
|
||||||
|
注意: 移动云云空间的 `分享key` 取分享链接中的 `data` 参数值
|
||||||
|
|
||||||
#### 3. 文件夹解析(v0.1.8fixed3+)
|
#### 3. 文件夹解析(v0.1.8fixed3+)
|
||||||
|
|
||||||
@@ -230,11 +241,6 @@ auths:
|
|||||||
|
|
||||||
如果只是临时调用一次,不想改动服务端配置,也可以用上面提到的 `auth` 参数临时传递(`authType` 可选 `password`/`accesstoken`/`authorization`),无需重启服务,仅本次请求生效。
|
如果只是临时调用一次,不想改动服务端配置,也可以用上面提到的 `auth` 参数临时传递(`authType` 可选 `password`/`accesstoken`/`authorization`),无需重启服务,仅本次请求生效。
|
||||||
|
|
||||||
### 特殊说明
|
|
||||||
|
|
||||||
- 移动云云空间的 `分享key` 取分享链接中的 `data` 参数值
|
|
||||||
- 移动云云空间、小飞机网盘的加密分享可忽略密码参数
|
|
||||||
|
|
||||||
### 示例
|
### 示例
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -455,8 +461,8 @@ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtow
|
|||||||
> 注意: netdisk-fast-download.service中的ExecStart的路径改为实际路径
|
> 注意: netdisk-fast-download.service中的ExecStart的路径改为实际路径
|
||||||
```shell
|
```shell
|
||||||
cd ~
|
cd ~
|
||||||
wget -O netdisk-fast-download.zip https://github.com/qaiu/netdisk-fast-download/releases/download/v3.0.2/netdisk-fast-download-bin.zip
|
wget -O netdisk-fast-download.zip https://github.com/qaiu/netdisk-fast-download/releases/download/v0.4.6/netdisk-fast-download-linux-amd64.zip
|
||||||
unzip netdisk-fast-download-bin.zip
|
unzip netdisk-fast-download.zip
|
||||||
cd netdisk-fast-download
|
cd netdisk-fast-download
|
||||||
bash service-install.sh
|
bash service-install.sh
|
||||||
```
|
```
|
||||||
@@ -544,11 +550,22 @@ Core模块集成Vert.x实现类似spring的注解式路由API
|
|||||||
</picture>
|
</picture>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
## **免责声明**
|
|
||||||
- 用户在使用本项目时,应自行承担风险,并确保其行为符合当地法律法规。开发者不对用户因使用本项目而导致的任何后果负责。
|
|
||||||
|
|
||||||
## 支持该项目
|
## **声明**
|
||||||
开源不易,用爱发电,本项目长期维护如果觉得有帮助, 可以请作者喝杯咖啡, 感谢支持
|
|
||||||
|
- 本项目**仅供个人学习与技术交流使用**,请勿用于商业用途或大规模滥用。
|
||||||
|
- 所用接口均来自各网盘**官方开放平台**、官方公开接口及**已知开源项目**,仅解析用户主动提供的分享链接,**不涉及破解或绕过版权保护**。
|
||||||
|
- 本项目**相当于自动化程序代替用户发起请求**,**不会提升或绕过任何会员权限**,也**不会突破网盘的限速策略**;我们**鼓励用户开通官方 VIP/SVIP**以获得更好的下载与加速体验。
|
||||||
|
- 使用者应遵守各网盘服务商的**用户协议与使用条款**,以及所在地区的**法律法规**,违反所产生的后果自行承担。
|
||||||
|
- **高频调用可能触发网盘风控**,导致**账号限流、封禁**或**来源 IP 被屏蔽**,请合理控制请求频率,避免高并发与批量请求。
|
||||||
|
- 网盘接口调整、风控策略变更等因素可能导致功能失效,本项目**不对可用性与稳定性作任何担保**。
|
||||||
|
- 开发者**不对**使用本项目产生的**任何直接或间接损失**(账号封禁、数据丢失、法律纠纷等)**承担责任**。
|
||||||
|
- 开发者保留**随时修改本免责声明**的权利,恕不另行通知。
|
||||||
|
- **下载、部署或使用本项目,即视为您已阅读并接受上述全部条款。**
|
||||||
|
|
||||||
|
|
||||||
|
## 赞助该项目
|
||||||
|
开源不易,用爱发电,本项目长期维护如果觉得有帮助, 可以请开发者[喝杯咖啡](https://blog.qaiu.top/archives/da-shang-zhuan-yong), 感谢支持。
|
||||||
|
|
||||||
本项目的服务器由林枫云提供赞助<br>
|
本项目的服务器由林枫云提供赞助<br>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -162,13 +162,18 @@ public class CommonUtil {
|
|||||||
try (var is = CommonUtil.class.getClassLoader().getResourceAsStream("app.properties")) {
|
try (var is = CommonUtil.class.getClassLoader().getResourceAsStream("app.properties")) {
|
||||||
if (is != null) {
|
if (is != null) {
|
||||||
properties.load(is);
|
properties.load(is);
|
||||||
if (!properties.isEmpty()) {
|
String version = properties.getProperty("app.version");
|
||||||
appVersion = properties.getProperty("app.version") + "build" + properties.getProperty("build");
|
String build = properties.getProperty("build");
|
||||||
|
if (version != null && !version.contains("${")) {
|
||||||
|
appVersion = version + "build" + (build == null || build.contains("${") ? "" : build);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("读取app.properties失败", e);
|
LOGGER.error("读取app.properties失败", e);
|
||||||
}
|
}
|
||||||
|
if (appVersion == null) {
|
||||||
|
appVersion = "unknown";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return appVersion;
|
return appVersion;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -63,7 +63,7 @@
|
|||||||
<lombok.version>1.18.38</lombok.version>
|
<lombok.version>1.18.38</lombok.version>
|
||||||
<slf4j.version>2.0.16</slf4j.version>
|
<slf4j.version>2.0.16</slf4j.version>
|
||||||
<commons-lang3.version>3.18.0</commons-lang3.version>
|
<commons-lang3.version>3.18.0</commons-lang3.version>
|
||||||
<jackson.version>2.18.6</jackson.version>
|
<jackson.version>2.18.9</jackson.version>
|
||||||
<logback.version>1.5.32</logback.version>
|
<logback.version>1.5.32</logback.version>
|
||||||
<junit.version>4.13.2</junit.version>
|
<junit.version>4.13.2</junit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|||||||
@@ -368,9 +368,12 @@ public abstract class PanBase implements IPanTool, Closeable {
|
|||||||
// 检查响应头中的Content-Encoding是否为gzip
|
// 检查响应头中的Content-Encoding是否为gzip
|
||||||
String contentEncoding = res.getHeader("Content-Encoding");
|
String contentEncoding = res.getHeader("Content-Encoding");
|
||||||
try {
|
try {
|
||||||
if ("gzip".equalsIgnoreCase(contentEncoding)) {
|
if ("gzip".equalsIgnoreCase(contentEncoding) && res.body() instanceof Buffer gzipBody
|
||||||
|
&& gzipBody.length() >= 2
|
||||||
|
&& (gzipBody.getByte(0) & 0xff) == 0x1f
|
||||||
|
&& (gzipBody.getByte(1) & 0xff) == 0x8b) {
|
||||||
// 如果是gzip压缩的响应体,解压(只解压一次,缓存结果)
|
// 如果是gzip压缩的响应体,解压(只解压一次,缓存结果)
|
||||||
String decompressed = decompressGzip((Buffer) res.body());
|
String decompressed = decompressGzip(gzipBody);
|
||||||
return new JsonObject(decompressed);
|
return new JsonObject(decompressed);
|
||||||
} else {
|
} else {
|
||||||
return res.bodyAsJsonObject();
|
return res.bodyAsJsonObject();
|
||||||
|
|||||||
@@ -121,9 +121,9 @@ public enum PanDomainTemplate {
|
|||||||
"https://lecloud.lenovo.com/share/{shareKey}",
|
"https://lecloud.lenovo.com/share/{shareKey}",
|
||||||
LeTool.class),
|
LeTool.class),
|
||||||
|
|
||||||
// https://v2.fangcloud.com/s/
|
// https://v2.fangcloud.com/s/ https://v2.fangcloud.cn/h5/share/ (移动端H5落地页)
|
||||||
FC("亿方云",
|
FC("亿方云",
|
||||||
compile("https://v2\\.fangcloud\\.(com|cn)/(s|share|sharing)/(?<KEY>.+)"),
|
compile("https://v2\\.fangcloud\\.(com|cn)/(?:h5/)?(s|share|sharing)/(?<KEY>.+)"),
|
||||||
"https://v2.fangcloud.com/s/{shareKey}",
|
"https://v2.fangcloud.com/s/{shareKey}",
|
||||||
"https://www.fangcloud.com/",
|
"https://www.fangcloud.com/",
|
||||||
FcTool.class),
|
FcTool.class),
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public class FcTool extends PanBase {
|
|||||||
|
|
||||||
public static final String SHARE_URL_PREFIX = "https://v2.fangcloud.com/sharing/";
|
public static final String SHARE_URL_PREFIX = "https://v2.fangcloud.com/sharing/";
|
||||||
public static final String SHARE_URL_PREFIX2 = "https://v2.fangcloud.cn/sharing/";
|
public static final String SHARE_URL_PREFIX2 = "https://v2.fangcloud.cn/sharing/";
|
||||||
|
private static final String SHARE_INFO_URL = "https://v2.fangcloud.cn/apps/share_links/info/";
|
||||||
private static final String DOWN_REQUEST_URL = "https://v2.fangcloud.cn/apps/files/download?file_id={fid}" +
|
private static final String DOWN_REQUEST_URL = "https://v2.fangcloud.cn/apps/files/download?file_id={fid}" +
|
||||||
"&scenario=share&unique_name={uname}";
|
"&scenario=share&unique_name={uname}";
|
||||||
|
|
||||||
@@ -38,6 +39,25 @@ public class FcTool extends PanBase {
|
|||||||
final String dataKey = shareLinkInfo.getShareKey();
|
final String dataKey = shareLinkInfo.getShareKey();
|
||||||
final String pwd = shareLinkInfo.getSharePassword();
|
final String pwd = shareLinkInfo.getSharePassword();
|
||||||
WebClientSession sClient = WebClientSession.create(client);
|
WebClientSession sClient = WebClientSession.create(client);
|
||||||
|
// 先查询分享有效性, 避免分享已失效/已过期时仍去解析HTML, 报出令人困惑的技术错误
|
||||||
|
sClient.getAbs(SHARE_INFO_URL + dataKey).send().onSuccess(infoRes -> {
|
||||||
|
JsonObject infoJson = asJson(infoRes);
|
||||||
|
if (promise.future().isComplete()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JsonObject process = infoJson.getJsonObject("process");
|
||||||
|
boolean isClosed = process != null && Boolean.TRUE.equals(process.getBoolean("is_closed"));
|
||||||
|
boolean isExpired = process != null && Boolean.TRUE.equals(process.getBoolean("is_expired"));
|
||||||
|
if (process == null || isClosed || isExpired) {
|
||||||
|
fail("分享已失效或不存在");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
doParse(dataKey, pwd, sClient);
|
||||||
|
}).onFailure(handleFail(SHARE_INFO_URL + dataKey));
|
||||||
|
return promise.future();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doParse(String dataKey, String pwd, WebClientSession sClient) {
|
||||||
// 第一次请求 自动重定向
|
// 第一次请求 自动重定向
|
||||||
sClient.getAbs(SHARE_URL_PREFIX + dataKey).send().onSuccess(res -> {
|
sClient.getAbs(SHARE_URL_PREFIX + dataKey).send().onSuccess(res -> {
|
||||||
|
|
||||||
@@ -67,7 +87,6 @@ public class FcTool extends PanBase {
|
|||||||
}
|
}
|
||||||
getDownURL(dataKey, promise, res, sClient);
|
getDownURL(dataKey, promise, res, sClient);
|
||||||
}).onFailure(handleFail(SHARE_URL_PREFIX + dataKey));
|
}).onFailure(handleFail(SHARE_URL_PREFIX + dataKey));
|
||||||
return promise.future();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDownURL(String dataKey, Promise<String> promise, HttpResponse<Buffer> res,
|
private void getDownURL(String dataKey, Promise<String> promise, HttpResponse<Buffer> res,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -119,8 +119,18 @@ public class HttpResponseHelper {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean looksLikeGzip(Buffer compressed) {
|
||||||
|
return compressed != null && compressed.length() >= 2
|
||||||
|
&& (compressed.getByte(0) & 0xff) == 0x1f
|
||||||
|
&& (compressed.getByte(1) & 0xff) == 0x8b;
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------- gzip --------------------
|
// -------------------- gzip --------------------
|
||||||
private static String decompressGzip(Buffer compressed) throws IOException {
|
private static String decompressGzip(Buffer compressed) throws IOException {
|
||||||
|
// Vert.x 可能已解压但仍带 Content-Encoding: gzip,再走 GZIPInputStream 会变成 ZipException
|
||||||
|
if (!looksLikeGzip(compressed)) {
|
||||||
|
return compressed.toString(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
try (ByteArrayInputStream bais = new ByteArrayInputStream(compressed.getBytes());
|
try (ByteArrayInputStream bais = new ByteArrayInputStream(compressed.getBytes());
|
||||||
GZIPInputStream gzis = new GZIPInputStream(bais);
|
GZIPInputStream gzis = new GZIPInputStream(bais);
|
||||||
InputStreamReader isr = new InputStreamReader(gzis, StandardCharsets.UTF_8);
|
InputStreamReader isr = new InputStreamReader(gzis, StandardCharsets.UTF_8);
|
||||||
|
|||||||
@@ -101,59 +101,384 @@ public interface JsContent {
|
|||||||
""";
|
""";
|
||||||
String lz = """
|
String lz = """
|
||||||
/**
|
/**
|
||||||
* 蓝奏云解析器js签名获取工具
|
* 蓝奏云解析器 JS 沙箱:伪装 jQuery / document / window。
|
||||||
|
* 新版页面会用 document.cookie、location.reload、querySelector、
|
||||||
|
* $('#pwd').val()、.html()、.css() 等,这里做成可链式的最小实现。
|
||||||
|
* kdns.js 在浏览器里是 `var killdns = true`,需一并注入,否则 kd 会被改成 0。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var signObj;
|
var signObj;
|
||||||
|
var __lzPwd = '';
|
||||||
|
var killdns = true;
|
||||||
|
|
||||||
|
function __lzSetPwd(p) {
|
||||||
|
__lzPwd = p == null ? '' : String(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
function __lzEl(id) {
|
||||||
|
var nid = String(id == null ? '' : id).replace(/^[#.]/, '');
|
||||||
|
var el = {
|
||||||
|
id: nid,
|
||||||
|
_value: nid === 'pwd' ? __lzPwd : '',
|
||||||
|
checked: false,
|
||||||
|
disabled: false,
|
||||||
|
innerHTML: '',
|
||||||
|
innerText: '',
|
||||||
|
textContent: '',
|
||||||
|
className: '',
|
||||||
|
style: { display: '', visibility: '', width: '', height: '' },
|
||||||
|
classList: {
|
||||||
|
add: function () {},
|
||||||
|
remove: function () {},
|
||||||
|
contains: function () { return false; },
|
||||||
|
toggle: function () {}
|
||||||
|
},
|
||||||
|
setAttribute: function () {},
|
||||||
|
getAttribute: function () { return null; },
|
||||||
|
removeAttribute: function () {},
|
||||||
|
addEventListener: function (t, fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeEventListener: function () {},
|
||||||
|
appendChild: function (n) { return n; },
|
||||||
|
removeChild: function (n) { return n; },
|
||||||
|
insertBefore: function (n) { return n; },
|
||||||
|
click: function () {},
|
||||||
|
focus: function () {},
|
||||||
|
blur: function () {},
|
||||||
|
submit: function () {},
|
||||||
|
select: function () {},
|
||||||
|
reset: function () {}
|
||||||
|
};
|
||||||
|
el.parentNode = el;
|
||||||
|
el.parentElement = el;
|
||||||
|
el.children = [];
|
||||||
|
el.childNodes = [];
|
||||||
|
el.firstChild = null;
|
||||||
|
el.lastChild = null;
|
||||||
|
try {
|
||||||
|
Object.defineProperty(el, 'value', {
|
||||||
|
get: function () { return nid === 'pwd' ? __lzPwd : el._value; },
|
||||||
|
set: function (v) {
|
||||||
|
el._value = v;
|
||||||
|
if (nid === 'pwd') {
|
||||||
|
__lzPwd = v == null ? '' : String(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
el.value = el._value;
|
||||||
|
}
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
|
function __lzJq(sel) {
|
||||||
|
var id = '';
|
||||||
|
if (typeof sel === 'string') {
|
||||||
|
id = sel.replace(/^[#.]/, '');
|
||||||
|
} else if (sel && sel.id) {
|
||||||
|
id = String(sel.id);
|
||||||
|
}
|
||||||
|
var el = (sel && sel.style && sel.addEventListener) ? sel : __lzEl(id);
|
||||||
|
var api = {
|
||||||
|
0: el,
|
||||||
|
length: 1,
|
||||||
|
selector: sel,
|
||||||
|
ready: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(jQuery); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
on: function (t, fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
off: function () { return api; },
|
||||||
|
bind: function (t, fn) { return api.on(t, fn); },
|
||||||
|
unbind: function () { return api; },
|
||||||
|
click: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
focus: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
blur: function () { return api; },
|
||||||
|
keyup: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
keydown: function (fn) { return api.keyup(fn); },
|
||||||
|
keypress: function (fn) { return api.keyup(fn); },
|
||||||
|
submit: function (fn) { return api.click(fn); },
|
||||||
|
change: function (fn) { return api.click(fn); },
|
||||||
|
hover: function () { return api; },
|
||||||
|
val: function (v) {
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
if (typeof el.value !== 'undefined') {
|
||||||
|
return el.value;
|
||||||
|
}
|
||||||
|
return (id === 'pwd') ? __lzPwd : '';
|
||||||
|
}
|
||||||
|
el.value = v;
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
html: function (v) {
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
return el.innerHTML;
|
||||||
|
}
|
||||||
|
el.innerHTML = v;
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
text: function (v) {
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
return el.innerText;
|
||||||
|
}
|
||||||
|
el.innerText = v;
|
||||||
|
el.textContent = v;
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
attr: function (k, v) {
|
||||||
|
if (arguments.length < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
prop: function (k, v) {
|
||||||
|
if (arguments.length < 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
css: function () { return api; },
|
||||||
|
addClass: function () { return api; },
|
||||||
|
removeClass: function () { return api; },
|
||||||
|
toggleClass: function () { return api; },
|
||||||
|
hasClass: function () { return false; },
|
||||||
|
show: function () {
|
||||||
|
el.style.display = '';
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
hide: function () {
|
||||||
|
el.style.display = 'none';
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
fadeIn: function () { return api; },
|
||||||
|
fadeOut: function () { return api; },
|
||||||
|
animate: function () { return api; },
|
||||||
|
find: function () { return api; },
|
||||||
|
parent: function () { return api; },
|
||||||
|
children: function () { return api; },
|
||||||
|
eq: function () { return api; },
|
||||||
|
first: function () { return api; },
|
||||||
|
last: function () { return api; },
|
||||||
|
each: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn.call(el, 0, el); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
append: function () { return api; },
|
||||||
|
prepend: function () { return api; },
|
||||||
|
remove: function () { return api; },
|
||||||
|
empty: function () { return api; },
|
||||||
|
ajax: function (obj) {
|
||||||
|
signObj = obj;
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
get: function () { return el; }
|
||||||
|
};
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
||||||
var $, jQuery;
|
var $, jQuery;
|
||||||
|
$ = jQuery = function (sel) {
|
||||||
$ = jQuery = function () {
|
if (typeof sel === 'function') {
|
||||||
return new jQuery.fn.init();
|
try { sel(jQuery); } catch (e) {}
|
||||||
}
|
return __lzJq(document);
|
||||||
|
}
|
||||||
|
return __lzJq(sel);
|
||||||
|
};
|
||||||
|
|
||||||
jQuery.fn = jQuery.prototype = {
|
jQuery.fn = jQuery.prototype = {
|
||||||
init: function () {
|
init: function (sel) {
|
||||||
return {
|
return __lzJq(sel);
|
||||||
focus: function (a) {
|
}
|
||||||
|
};
|
||||||
},
|
|
||||||
keyup: function(a) {
|
|
||||||
|
|
||||||
},
|
|
||||||
ajax: function (obj) {
|
|
||||||
signObj = obj
|
|
||||||
},
|
|
||||||
val: function(a) {
|
|
||||||
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
jQuery.fn.init.prototype = jQuery.fn;
|
jQuery.fn.init.prototype = jQuery.fn;
|
||||||
|
$.fn = jQuery.fn;
|
||||||
|
|
||||||
$.ajax = function (obj) {
|
$.ajax = function (obj) {
|
||||||
signObj = obj
|
signObj = obj;
|
||||||
}
|
return {
|
||||||
|
done: function () { return this; },
|
||||||
|
fail: function () { return this; },
|
||||||
|
always: function () { return this; }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
$.get = function () {};
|
||||||
|
$.post = function () {};
|
||||||
|
$.extend = function () {
|
||||||
|
var t = arguments[0] || {};
|
||||||
|
for (var i = 1; i < arguments.length; i++) {
|
||||||
|
var s = arguments[i];
|
||||||
|
if (s) {
|
||||||
|
for (var k in s) {
|
||||||
|
if (s.hasOwnProperty(k)) {
|
||||||
|
t[k] = s[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
$.each = function (obj, fn) {
|
||||||
|
if (!obj || typeof fn !== 'function') {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
if (typeof obj.length === 'number') {
|
||||||
|
for (var i = 0; i < obj.length; i++) {
|
||||||
|
fn.call(obj[i], i, obj[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var k in obj) {
|
||||||
|
if (obj.hasOwnProperty(k)) {
|
||||||
|
fn.call(obj[k], k, obj[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
$.isFunction = function (f) { return typeof f === 'function'; };
|
||||||
|
$.isArray = function (a) {
|
||||||
|
return Object.prototype.toString.call(a) === '[object Array]';
|
||||||
|
};
|
||||||
|
$.trim = function (s) {
|
||||||
|
return s == null ? '' : String(s).replace(/^\\s+|\\s+$/g, '');
|
||||||
|
};
|
||||||
|
|
||||||
|
var __lzLocation = {
|
||||||
|
href: '',
|
||||||
|
search: '',
|
||||||
|
pathname: '/',
|
||||||
|
hash: '',
|
||||||
|
host: '',
|
||||||
|
hostname: '',
|
||||||
|
protocol: 'https:',
|
||||||
|
port: '',
|
||||||
|
origin: '',
|
||||||
|
assign: function () {},
|
||||||
|
replace: function () {},
|
||||||
|
reload: function () {}
|
||||||
|
};
|
||||||
|
|
||||||
var document = {
|
var document = {
|
||||||
getElementById: function (v) {
|
cookie: '',
|
||||||
return {
|
title: '',
|
||||||
value: 'v',
|
domain: '',
|
||||||
style: {
|
referrer: '',
|
||||||
display: ''
|
readyState: 'complete',
|
||||||
},
|
hidden: false,
|
||||||
addEventListener: function() {}
|
visibilityState: 'visible',
|
||||||
|
documentElement: null,
|
||||||
|
body: null,
|
||||||
|
head: null,
|
||||||
|
location: __lzLocation,
|
||||||
|
getElementById: function (id) { return __lzEl(id); },
|
||||||
|
getElementsByClassName: function () { return []; },
|
||||||
|
getElementsByTagName: function (t) {
|
||||||
|
return t === 'script' ? [] : [__lzEl(t)];
|
||||||
|
},
|
||||||
|
getElementsByName: function () { return []; },
|
||||||
|
querySelector: function (s) { return __lzEl(s); },
|
||||||
|
querySelectorAll: function (s) { return [__lzEl(s)]; },
|
||||||
|
createElement: function (t) { return __lzEl(t); },
|
||||||
|
createTextNode: function (t) { return { nodeValue: t, data: t }; },
|
||||||
|
createDocumentFragment: function () { return __lzEl('fragment'); },
|
||||||
|
addEventListener: function (t, fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
removeEventListener: function () {},
|
||||||
|
write: function () {},
|
||||||
|
writeln: function () {},
|
||||||
|
open: function () {},
|
||||||
|
close: function () {}
|
||||||
|
};
|
||||||
|
document.documentElement = __lzEl('html');
|
||||||
|
document.body = __lzEl('body');
|
||||||
|
document.head = __lzEl('head');
|
||||||
|
|
||||||
var window = {location: {}}
|
var navigator = {
|
||||||
|
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
|
||||||
|
platform: 'Win32',
|
||||||
|
language: 'zh-CN',
|
||||||
|
cookieEnabled: true,
|
||||||
|
onLine: true
|
||||||
|
};
|
||||||
|
|
||||||
|
var location = __lzLocation;
|
||||||
|
var console = {
|
||||||
|
log: function () {},
|
||||||
|
warn: function () {},
|
||||||
|
error: function () {},
|
||||||
|
info: function () {},
|
||||||
|
debug: function () {}
|
||||||
|
};
|
||||||
|
|
||||||
|
function setTimeout(fn, delay) {
|
||||||
|
if (typeof fn === 'function' && (!delay || delay <= 0)) {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
function setInterval() { return 0; }
|
||||||
|
function clearTimeout() {}
|
||||||
|
function clearInterval() {}
|
||||||
|
|
||||||
|
var window = {
|
||||||
|
location: __lzLocation,
|
||||||
|
document: document,
|
||||||
|
navigator: navigator,
|
||||||
|
console: console,
|
||||||
|
innerWidth: 1920,
|
||||||
|
innerHeight: 1080,
|
||||||
|
setTimeout: setTimeout,
|
||||||
|
setInterval: setInterval,
|
||||||
|
clearTimeout: clearTimeout,
|
||||||
|
clearInterval: clearInterval,
|
||||||
|
addEventListener: function (t, fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeEventListener: function () {},
|
||||||
|
atob: function (s) { return s; },
|
||||||
|
btoa: function (s) { return s; }
|
||||||
|
};
|
||||||
|
window.window = window;
|
||||||
|
window.top = window;
|
||||||
|
window.self = window;
|
||||||
|
window.parent = window;
|
||||||
|
window.jQuery = jQuery;
|
||||||
|
window.$ = $;
|
||||||
|
|
||||||
|
var top = window;
|
||||||
|
var self = window;
|
||||||
|
var parent = window;
|
||||||
""";
|
""";
|
||||||
|
|
||||||
String kwSignString = """
|
String kwSignString = """
|
||||||
|
|||||||
@@ -50,21 +50,47 @@ public class JsExecUtils {
|
|||||||
*/
|
*/
|
||||||
public static ScriptObjectMirror executeDynamicJs(String jsText, String funName) throws ScriptException,
|
public static ScriptObjectMirror executeDynamicJs(String jsText, String funName) throws ScriptException,
|
||||||
NoSuchMethodException {
|
NoSuchMethodException {
|
||||||
ScriptEngine engine = ENGINE_MANAGER.getEngineByName("JavaScript"); // 得到脚本引擎
|
return executeDynamicJs(jsText, funName, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param pwd 分享密码,写入伪 DOM(#pwd / getElementById('pwd')),供新版页面取值
|
||||||
|
*/
|
||||||
|
public static ScriptObjectMirror executeDynamicJs(String jsText, String funName, String pwd) throws ScriptException,
|
||||||
|
NoSuchMethodException {
|
||||||
|
ScriptEngine engine = ENGINE_MANAGER.getEngineByName("JavaScript");
|
||||||
try {
|
try {
|
||||||
engine.eval(JsContent.lz + "\n" + jsText);
|
engine.eval(JsContent.lz);
|
||||||
Invocable inv = (Invocable) engine;
|
Invocable inv = (Invocable) engine;
|
||||||
//调用js中的函数
|
if (pwd != null) {
|
||||||
if (StringUtils.isNotEmpty(funName)) {
|
inv.invokeFunction("__lzSetPwd", pwd);
|
||||||
inv.invokeFunction(funName);
|
|
||||||
}
|
}
|
||||||
return (ScriptObjectMirror) engine.get("signObj");
|
try {
|
||||||
|
engine.eval(jsText);
|
||||||
|
if (StringUtils.isNotEmpty(funName)) {
|
||||||
|
inv.invokeFunction(funName);
|
||||||
|
}
|
||||||
|
} catch (ScriptException | NoSuchMethodException | RuntimeException e) {
|
||||||
|
ScriptObjectMirror captured = asSignObj(engine.get("signObj"));
|
||||||
|
if (captured != null) {
|
||||||
|
return captured;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return asSignObj(engine.get("signObj"));
|
||||||
} finally {
|
} finally {
|
||||||
// 清理引擎持有的引用,帮助 GC 回收
|
|
||||||
clearEngineBindings(engine);
|
clearEngineBindings(engine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ScriptObjectMirror asSignObj(Object sign) {
|
||||||
|
if (sign instanceof ScriptObjectMirror mirror
|
||||||
|
&& (mirror.get("url") != null || mirror.get("data") != null)) {
|
||||||
|
return mirror;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用执行js文件(使用缓存的 ScriptEngineManager 创建新引擎实例)
|
* 调用执行js文件(使用缓存的 ScriptEngineManager 创建新引擎实例)
|
||||||
|
|||||||
@@ -1,46 +1,379 @@
|
|||||||
/**
|
/**
|
||||||
* 蓝奏云解析器js签名获取工具
|
* 蓝奏云解析器 JS 沙箱:伪装 jQuery / document / window。
|
||||||
|
* 新版页面会用 document.cookie、location.reload、querySelector、
|
||||||
|
* $('#pwd').val()、.html()、.css() 等,这里做成可链式的最小实现。
|
||||||
|
* kdns.js 在浏览器里是 `var killdns = true`,需一并注入,否则 kd 会被改成 0。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var signObj;
|
var signObj;
|
||||||
|
var __lzPwd = '';
|
||||||
|
var killdns = true;
|
||||||
|
|
||||||
|
function __lzSetPwd(p) {
|
||||||
|
__lzPwd = p == null ? '' : String(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
function __lzEl(id) {
|
||||||
|
var nid = String(id == null ? '' : id).replace(/^[#.]/, '');
|
||||||
|
var el = {
|
||||||
|
id: nid,
|
||||||
|
_value: nid === 'pwd' ? __lzPwd : '',
|
||||||
|
checked: false,
|
||||||
|
disabled: false,
|
||||||
|
innerHTML: '',
|
||||||
|
innerText: '',
|
||||||
|
textContent: '',
|
||||||
|
className: '',
|
||||||
|
style: { display: '', visibility: '', width: '', height: '' },
|
||||||
|
classList: {
|
||||||
|
add: function () {},
|
||||||
|
remove: function () {},
|
||||||
|
contains: function () { return false; },
|
||||||
|
toggle: function () {}
|
||||||
|
},
|
||||||
|
setAttribute: function () {},
|
||||||
|
getAttribute: function () { return null; },
|
||||||
|
removeAttribute: function () {},
|
||||||
|
addEventListener: function (t, fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeEventListener: function () {},
|
||||||
|
appendChild: function (n) { return n; },
|
||||||
|
removeChild: function (n) { return n; },
|
||||||
|
insertBefore: function (n) { return n; },
|
||||||
|
click: function () {},
|
||||||
|
focus: function () {},
|
||||||
|
blur: function () {},
|
||||||
|
submit: function () {},
|
||||||
|
select: function () {},
|
||||||
|
reset: function () {}
|
||||||
|
};
|
||||||
|
el.parentNode = el;
|
||||||
|
el.parentElement = el;
|
||||||
|
el.children = [];
|
||||||
|
el.childNodes = [];
|
||||||
|
el.firstChild = null;
|
||||||
|
el.lastChild = null;
|
||||||
|
try {
|
||||||
|
Object.defineProperty(el, 'value', {
|
||||||
|
get: function () { return nid === 'pwd' ? __lzPwd : el._value; },
|
||||||
|
set: function (v) {
|
||||||
|
el._value = v;
|
||||||
|
if (nid === 'pwd') {
|
||||||
|
__lzPwd = v == null ? '' : String(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
el.value = el._value;
|
||||||
|
}
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
|
function __lzJq(sel) {
|
||||||
|
var id = '';
|
||||||
|
if (typeof sel === 'string') {
|
||||||
|
id = sel.replace(/^[#.]/, '');
|
||||||
|
} else if (sel && sel.id) {
|
||||||
|
id = String(sel.id);
|
||||||
|
}
|
||||||
|
var el = (sel && sel.style && sel.addEventListener) ? sel : __lzEl(id);
|
||||||
|
var api = {
|
||||||
|
0: el,
|
||||||
|
length: 1,
|
||||||
|
selector: sel,
|
||||||
|
ready: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(jQuery); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
on: function (t, fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
off: function () { return api; },
|
||||||
|
bind: function (t, fn) { return api.on(t, fn); },
|
||||||
|
unbind: function () { return api; },
|
||||||
|
click: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
focus: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
blur: function () { return api; },
|
||||||
|
keyup: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
keydown: function (fn) { return api.keyup(fn); },
|
||||||
|
keypress: function (fn) { return api.keyup(fn); },
|
||||||
|
submit: function (fn) { return api.click(fn); },
|
||||||
|
change: function (fn) { return api.click(fn); },
|
||||||
|
hover: function () { return api; },
|
||||||
|
val: function (v) {
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
if (typeof el.value !== 'undefined') {
|
||||||
|
return el.value;
|
||||||
|
}
|
||||||
|
return (id === 'pwd') ? __lzPwd : '';
|
||||||
|
}
|
||||||
|
el.value = v;
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
html: function (v) {
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
return el.innerHTML;
|
||||||
|
}
|
||||||
|
el.innerHTML = v;
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
text: function (v) {
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
return el.innerText;
|
||||||
|
}
|
||||||
|
el.innerText = v;
|
||||||
|
el.textContent = v;
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
attr: function (k, v) {
|
||||||
|
if (arguments.length < 2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
prop: function (k, v) {
|
||||||
|
if (arguments.length < 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
css: function () { return api; },
|
||||||
|
addClass: function () { return api; },
|
||||||
|
removeClass: function () { return api; },
|
||||||
|
toggleClass: function () { return api; },
|
||||||
|
hasClass: function () { return false; },
|
||||||
|
show: function () {
|
||||||
|
el.style.display = '';
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
hide: function () {
|
||||||
|
el.style.display = 'none';
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
fadeIn: function () { return api; },
|
||||||
|
fadeOut: function () { return api; },
|
||||||
|
animate: function () { return api; },
|
||||||
|
find: function () { return api; },
|
||||||
|
parent: function () { return api; },
|
||||||
|
children: function () { return api; },
|
||||||
|
eq: function () { return api; },
|
||||||
|
first: function () { return api; },
|
||||||
|
last: function () { return api; },
|
||||||
|
each: function (fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn.call(el, 0, el); } catch (e) {}
|
||||||
|
}
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
append: function () { return api; },
|
||||||
|
prepend: function () { return api; },
|
||||||
|
remove: function () { return api; },
|
||||||
|
empty: function () { return api; },
|
||||||
|
ajax: function (obj) {
|
||||||
|
signObj = obj;
|
||||||
|
return api;
|
||||||
|
},
|
||||||
|
get: function () { return el; }
|
||||||
|
};
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
||||||
var $, jQuery;
|
var $, jQuery;
|
||||||
|
$ = jQuery = function (sel) {
|
||||||
$ = jQuery = function () {
|
if (typeof sel === 'function') {
|
||||||
return new jQuery.fn.init();
|
try { sel(jQuery); } catch (e) {}
|
||||||
}
|
return __lzJq(document);
|
||||||
|
}
|
||||||
|
return __lzJq(sel);
|
||||||
|
};
|
||||||
|
|
||||||
jQuery.fn = jQuery.prototype = {
|
jQuery.fn = jQuery.prototype = {
|
||||||
init: function () {
|
init: function (sel) {
|
||||||
return {
|
return __lzJq(sel);
|
||||||
focus: function (a) {
|
}
|
||||||
|
};
|
||||||
},
|
|
||||||
keyup: function(a) {
|
|
||||||
|
|
||||||
},
|
|
||||||
ajax: function (obj) {
|
|
||||||
signObj = obj
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
jQuery.fn.init.prototype = jQuery.fn;
|
jQuery.fn.init.prototype = jQuery.fn;
|
||||||
|
$.fn = jQuery.fn;
|
||||||
|
|
||||||
|
|
||||||
// 伪装jquery.ajax函数获取关键数据
|
|
||||||
$.ajax = function (obj) {
|
$.ajax = function (obj) {
|
||||||
signObj = obj
|
signObj = obj;
|
||||||
}
|
return {
|
||||||
|
done: function () { return this; },
|
||||||
|
fail: function () { return this; },
|
||||||
|
always: function () { return this; }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
$.get = function () {};
|
||||||
|
$.post = function () {};
|
||||||
|
$.extend = function () {
|
||||||
|
var t = arguments[0] || {};
|
||||||
|
for (var i = 1; i < arguments.length; i++) {
|
||||||
|
var s = arguments[i];
|
||||||
|
if (s) {
|
||||||
|
for (var k in s) {
|
||||||
|
if (s.hasOwnProperty(k)) {
|
||||||
|
t[k] = s[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
};
|
||||||
|
$.each = function (obj, fn) {
|
||||||
|
if (!obj || typeof fn !== 'function') {
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
if (typeof obj.length === 'number') {
|
||||||
|
for (var i = 0; i < obj.length; i++) {
|
||||||
|
fn.call(obj[i], i, obj[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (var k in obj) {
|
||||||
|
if (obj.hasOwnProperty(k)) {
|
||||||
|
fn.call(obj[k], k, obj[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
$.isFunction = function (f) { return typeof f === 'function'; };
|
||||||
|
$.isArray = function (a) {
|
||||||
|
return Object.prototype.toString.call(a) === '[object Array]';
|
||||||
|
};
|
||||||
|
$.trim = function (s) {
|
||||||
|
return s == null ? '' : String(s).replace(/^\s+|\s+$/g, '');
|
||||||
|
};
|
||||||
|
|
||||||
|
var __lzLocation = {
|
||||||
|
href: '',
|
||||||
|
search: '',
|
||||||
|
pathname: '/',
|
||||||
|
hash: '',
|
||||||
|
host: '',
|
||||||
|
hostname: '',
|
||||||
|
protocol: 'https:',
|
||||||
|
port: '',
|
||||||
|
origin: '',
|
||||||
|
assign: function () {},
|
||||||
|
replace: function () {},
|
||||||
|
reload: function () {}
|
||||||
|
};
|
||||||
|
|
||||||
var document = {
|
var document = {
|
||||||
getElementById: function (v) {
|
cookie: '',
|
||||||
return {
|
title: '',
|
||||||
value: 'v'
|
domain: '',
|
||||||
|
referrer: '',
|
||||||
|
readyState: 'complete',
|
||||||
|
hidden: false,
|
||||||
|
visibilityState: 'visible',
|
||||||
|
documentElement: null,
|
||||||
|
body: null,
|
||||||
|
head: null,
|
||||||
|
location: __lzLocation,
|
||||||
|
getElementById: function (id) { return __lzEl(id); },
|
||||||
|
getElementsByClassName: function () { return []; },
|
||||||
|
getElementsByTagName: function (t) {
|
||||||
|
return t === 'script' ? [] : [__lzEl(t)];
|
||||||
|
},
|
||||||
|
getElementsByName: function () { return []; },
|
||||||
|
querySelector: function (s) { return __lzEl(s); },
|
||||||
|
querySelectorAll: function (s) { return [__lzEl(s)]; },
|
||||||
|
createElement: function (t) { return __lzEl(t); },
|
||||||
|
createTextNode: function (t) { return { nodeValue: t, data: t }; },
|
||||||
|
createDocumentFragment: function () { return __lzEl('fragment'); },
|
||||||
|
addEventListener: function (t, fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
removeEventListener: function () {},
|
||||||
|
write: function () {},
|
||||||
|
writeln: function () {},
|
||||||
|
open: function () {},
|
||||||
|
close: function () {}
|
||||||
|
};
|
||||||
|
document.documentElement = __lzEl('html');
|
||||||
|
document.body = __lzEl('body');
|
||||||
|
document.head = __lzEl('head');
|
||||||
|
|
||||||
|
var navigator = {
|
||||||
|
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36',
|
||||||
|
platform: 'Win32',
|
||||||
|
language: 'zh-CN',
|
||||||
|
cookieEnabled: true,
|
||||||
|
onLine: true
|
||||||
|
};
|
||||||
|
|
||||||
|
var location = __lzLocation;
|
||||||
|
var console = {
|
||||||
|
log: function () {},
|
||||||
|
warn: function () {},
|
||||||
|
error: function () {},
|
||||||
|
info: function () {},
|
||||||
|
debug: function () {}
|
||||||
|
};
|
||||||
|
|
||||||
|
function setTimeout(fn, delay) {
|
||||||
|
if (typeof fn === 'function' && (!delay || delay <= 0)) {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
function setInterval() { return 0; }
|
||||||
|
function clearTimeout() {}
|
||||||
|
function clearInterval() {}
|
||||||
|
|
||||||
|
var window = {
|
||||||
|
location: __lzLocation,
|
||||||
|
document: document,
|
||||||
|
navigator: navigator,
|
||||||
|
console: console,
|
||||||
|
innerWidth: 1920,
|
||||||
|
innerHeight: 1080,
|
||||||
|
setTimeout: setTimeout,
|
||||||
|
setInterval: setInterval,
|
||||||
|
clearTimeout: clearTimeout,
|
||||||
|
clearInterval: clearInterval,
|
||||||
|
addEventListener: function (t, fn) {
|
||||||
|
if (typeof fn === 'function') {
|
||||||
|
try { fn(); } catch (e) {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
removeEventListener: function () {},
|
||||||
|
atob: function (s) { return s; },
|
||||||
|
btoa: function (s) { return s; }
|
||||||
|
};
|
||||||
|
window.window = window;
|
||||||
|
window.top = window;
|
||||||
|
window.self = window;
|
||||||
|
window.parent = window;
|
||||||
|
window.jQuery = jQuery;
|
||||||
|
window.$ = $;
|
||||||
|
|
||||||
|
var top = window;
|
||||||
|
var self = window;
|
||||||
|
var parent = window;
|
||||||
|
|||||||
@@ -170,6 +170,10 @@ public class PanDomainTemplateTest {
|
|||||||
assertTrue("YE should match redirected mshare URL", redirectedUrl.find());
|
assertTrue("YE should match redirected mshare URL", redirectedUrl.find());
|
||||||
assertEquals("lN7UVv-pbYJ", redirectedUrl.group("KEY"));
|
assertEquals("lN7UVv-pbYJ", redirectedUrl.group("KEY"));
|
||||||
|
|
||||||
|
Matcher shareUrl = yePattern.matcher("https://1815268665.share.123pan.cn/123pan/iaKtVv-r4aCd");
|
||||||
|
assertTrue("YE should match uid.share.123pan.cn URL", shareUrl.find());
|
||||||
|
assertEquals("iaKtVv-r4aCd", shareUrl.group("KEY"));
|
||||||
|
|
||||||
Matcher htmlUrl = yePattern.matcher("https://www.123278.com/s/lN7UVv-pbYJ.html?pwd=abcd");
|
Matcher htmlUrl = yePattern.matcher("https://www.123278.com/s/lN7UVv-pbYJ.html?pwd=abcd");
|
||||||
assertTrue("YE should match html URL with query", htmlUrl.find());
|
assertTrue("YE should match html URL with query", htmlUrl.find());
|
||||||
assertEquals("lN7UVv-pbYJ", htmlUrl.group("KEY"));
|
assertEquals("lN7UVv-pbYJ", htmlUrl.group("KEY"));
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package cn.qaiu.util;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.openjdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新版蓝奏页面会调用更多 document / jQuery API,沙箱必须能跑完并抓住 $.ajax。
|
||||||
|
*/
|
||||||
|
public class JsExecUtilsLzTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNewIframeAjaxWithDomApis() throws Exception {
|
||||||
|
String js = """
|
||||||
|
var lanosso = '';
|
||||||
|
var down_1 = '';
|
||||||
|
var wsk_sign = 'c20230908';
|
||||||
|
var wp_sign = 'SIGN_ABC';
|
||||||
|
var ajaxdata = 'MrBR';
|
||||||
|
var kdns = 1;
|
||||||
|
if (typeof(killdns)=='undefined'){
|
||||||
|
var kdns = 0;
|
||||||
|
}
|
||||||
|
document.cookie = 'x=1';
|
||||||
|
document.location.reload();
|
||||||
|
document.querySelector('#tourl');
|
||||||
|
document.createElement('div');
|
||||||
|
$.ajax({
|
||||||
|
type : 'post',
|
||||||
|
url : '/ajaxfile.php?file=150233466',
|
||||||
|
data : { 'action':'downprocess','websignkey':ajaxdata,'signs':ajaxdata,'sign':wp_sign,'websign':'','kd':kdns,'ves':1 },
|
||||||
|
dataType : 'json',
|
||||||
|
success:function(msg){
|
||||||
|
$("#tourl").html("ok");
|
||||||
|
$("#outime").css("display","block");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
ScriptObjectMirror sign = JsExecUtils.executeDynamicJs(js, null);
|
||||||
|
assertNotNull(sign);
|
||||||
|
assertEquals("/ajaxfile.php?file=150233466", String.valueOf(sign.get("url")));
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> data = (Map<String, Object>) sign.get("data");
|
||||||
|
assertEquals("downprocess", String.valueOf(data.get("action")));
|
||||||
|
assertEquals("SIGN_ABC", String.valueOf(data.get("sign")));
|
||||||
|
assertEquals("MrBR", String.valueOf(data.get("websignkey")));
|
||||||
|
assertEquals("1", String.valueOf(data.get("kd")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPwdViaJqueryValAndDocument() throws Exception {
|
||||||
|
String js = """
|
||||||
|
function down_p(){
|
||||||
|
var pwd = $('#pwd').val();
|
||||||
|
var pwd2 = document.getElementById('pwd').value;
|
||||||
|
var pwd3 = document.querySelector('#pwd').value;
|
||||||
|
$(".passwdinput").focus();
|
||||||
|
$.ajax({
|
||||||
|
type : 'post',
|
||||||
|
url : '/ajaxm.php',
|
||||||
|
data : { 'action':'downprocess','sign':'S1','p':pwd,'p2':pwd2,'p3':pwd3 }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
ScriptObjectMirror sign = JsExecUtils.executeDynamicJs(js, "down_p", "e4k4");
|
||||||
|
assertNotNull(sign);
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
Map<String, Object> data = (Map<String, Object>) sign.get("data");
|
||||||
|
assertEquals("e4k4", String.valueOf(data.get("p")));
|
||||||
|
assertEquals("e4k4", String.valueOf(data.get("p2")));
|
||||||
|
assertEquals("e4k4", String.valueOf(data.get("p3")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReadyAndSuccessCallbackDoNotDropAjax() throws Exception {
|
||||||
|
String js = """
|
||||||
|
$(function(){
|
||||||
|
document.getElementById('rpt').style.display = 'none';
|
||||||
|
$.ajax({ url: '/ajaxm.php?file=1', data: { a: 1 } });
|
||||||
|
$("#tourl").html("x");
|
||||||
|
});
|
||||||
|
""";
|
||||||
|
ScriptObjectMirror sign = JsExecUtils.executeDynamicJs(js, null);
|
||||||
|
assertNotNull(sign);
|
||||||
|
assertTrue(String.valueOf(sign.get("url")).contains("ajaxm.php"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<revision>0.4.2</revision>
|
<revision>0.4.6</revision>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<maven.compiler.source>17</maven.compiler.source>
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
|||||||
@@ -0,0 +1,169 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
亿方云 (FangCloud) 分享链接有效性验证脚本
|
||||||
|
|
||||||
|
用法: 直接 `python3 verify_fangcloud_share.py` 运行, 分享链接已写死在 SHARE_URL
|
||||||
|
里 (不走命令行传参), 要换链接就直接改这个常量。
|
||||||
|
|
||||||
|
根因(已用真实分享链接验证确认)
|
||||||
|
--------------------------------
|
||||||
|
GET https://v2.fangcloud.cn/apps/share_links/info/{uname}
|
||||||
|
返回的是 200 + JSON, 结构形如:
|
||||||
|
|
||||||
|
{
|
||||||
|
"process": {
|
||||||
|
"is_closed": false,
|
||||||
|
"is_expired": false,
|
||||||
|
"item": {"type": "file", "id": 45006535173, "name": "..."},
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FcTool.java 原来的实现判断有效性时读的是响应体**顶层**的 "is_valid" 字段
|
||||||
|
(`json.getBoolean("is_valid")`), 但这个字段根本不存在于该接口的实际响应里
|
||||||
|
(有效性信息实际上是 process.is_closed / process.is_expired, 且没有任何
|
||||||
|
名叫 "is_valid" 的字段) —— 所以旧的判断逻辑其实从未真正读取过这个接口的
|
||||||
|
有效性判断, 而是走的另一套 HTML 抓取 typed_id 的流程, 分享失效时会得到一个
|
||||||
|
"未匹配到文件id(typed_id)" 这种令人困惑的技术报错, 而不是清晰的"分享已失效"。
|
||||||
|
|
||||||
|
修复方案(已同步到 FcTool.java): 解析前先请求一次
|
||||||
|
https://v2.fangcloud.cn/apps/share_links/info/{uname}, 用
|
||||||
|
process.is_closed / process.is_expired 判断分享是否有效, 无效则直接返回
|
||||||
|
"分享已失效或不存在", 有效再继续走原来的 HTML + files/download 流程。
|
||||||
|
|
||||||
|
本脚本用于本地复现/回归验证这条判断逻辑, 并顺带跑一遍完整的取直链流程。
|
||||||
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import requests
|
||||||
|
|
||||||
|
# 直接写死分享链接, 不通过命令行参数传入
|
||||||
|
SHARE_URL = "https://v2.fangcloud.cn/h5/share/ded6dc6b9c3672b40b769804bf"
|
||||||
|
|
||||||
|
# 如果分享有密码, 在这里填上, 没有就留空字符串
|
||||||
|
SHARE_PASSWORD = ""
|
||||||
|
|
||||||
|
HEADERS = {
|
||||||
|
"User-Agent": (
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
||||||
|
"(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
|
||||||
|
),
|
||||||
|
"Accept": "application/json, text/html;q=0.9, */*;q=0.8",
|
||||||
|
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
|
||||||
|
}
|
||||||
|
|
||||||
|
# 修复后的正则, 额外兼容 /h5/share/ 移动端落地页路径 (对齐 PanDomainTemplate.FC)
|
||||||
|
FC_REGEX = re.compile(r"https://v2\.fangcloud\.(com|cn)/(?:h5/)?(s|share|sharing)/(?P<KEY>.+)")
|
||||||
|
|
||||||
|
SHARE_INFO_URL = "https://v2.fangcloud.cn/apps/share_links/info/{key}"
|
||||||
|
SHARE_URL_PREFIX = "https://v2.fangcloud.com/sharing/{key}"
|
||||||
|
DOWN_REQUEST_URL = "https://v2.fangcloud.cn/apps/files/download"
|
||||||
|
|
||||||
|
TYPED_ID_RE = re.compile(r'id="typed_id"\s+value="file_(\d+)"')
|
||||||
|
|
||||||
|
|
||||||
|
def extract_share_key(url: str) -> str:
|
||||||
|
m = FC_REGEX.search(url)
|
||||||
|
if not m:
|
||||||
|
raise ValueError(f"无法从链接中提取 shareKey (正则不匹配): {url}")
|
||||||
|
return m.group("KEY")
|
||||||
|
|
||||||
|
|
||||||
|
def check_is_valid(share_key: str, session: requests.Session) -> bool:
|
||||||
|
print("=" * 70)
|
||||||
|
print("Step 1. 请求 share_links/info 判断分享有效性 (对齐 FcTool.java 修复后的逻辑)")
|
||||||
|
print("=" * 70)
|
||||||
|
url = SHARE_INFO_URL.format(key=share_key)
|
||||||
|
r = session.get(url, timeout=15)
|
||||||
|
print(f"GET {url}")
|
||||||
|
print(f"状态码: {r.status_code}")
|
||||||
|
try:
|
||||||
|
data = r.json()
|
||||||
|
except Exception:
|
||||||
|
print("响应不是合法JSON => 判定分享已失效或不存在\n")
|
||||||
|
return False
|
||||||
|
|
||||||
|
process = data.get("process")
|
||||||
|
if not process:
|
||||||
|
print("响应中没有 process 字段 => 判定分享已失效或不存在\n")
|
||||||
|
return False
|
||||||
|
|
||||||
|
is_closed = bool(process.get("is_closed"))
|
||||||
|
is_expired = bool(process.get("is_expired"))
|
||||||
|
item = process.get("item")
|
||||||
|
print(f"is_closed = {is_closed}, is_expired = {is_expired}, item = {item}")
|
||||||
|
|
||||||
|
if is_closed or is_expired:
|
||||||
|
print("=> 分享已失效或不存在\n")
|
||||||
|
return False
|
||||||
|
|
||||||
|
print("=> 分享有效\n")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def get_download_url(share_key: str, pwd: str, session: requests.Session) -> str:
|
||||||
|
print("=" * 70)
|
||||||
|
print("Step 2. 走原有 HTML + files/download 流程取直链")
|
||||||
|
print("=" * 70)
|
||||||
|
r = session.get(SHARE_URL_PREFIX.format(key=share_key), timeout=15)
|
||||||
|
print(f"GET {SHARE_URL_PREFIX.format(key=share_key)} -> {r.status_code}, 最终URL: {r.url}")
|
||||||
|
|
||||||
|
html = r.text
|
||||||
|
if pwd:
|
||||||
|
# 加密分享: 提交密码换取跳转后的落地页 (此处仅示意, 具体见 FcTool.java)
|
||||||
|
m = re.search(r'name="requesttoken"\s+value="([a-zA-Z0-9_+=]+)"', html)
|
||||||
|
if not m:
|
||||||
|
raise RuntimeError("未匹配到加密分享的密码输入页面的 requesttoken")
|
||||||
|
token = m.group(1)
|
||||||
|
r2 = session.post(
|
||||||
|
"https://v2.fangcloud.cn/sharing/" + share_key,
|
||||||
|
data={"requesttoken": token, "password": pwd},
|
||||||
|
timeout=15,
|
||||||
|
)
|
||||||
|
html = r2.text
|
||||||
|
|
||||||
|
m = TYPED_ID_RE.search(html)
|
||||||
|
if not m:
|
||||||
|
raise RuntimeError("未匹配到文件id(typed_id), 分享可能是文件夹或页面结构有变化")
|
||||||
|
fid = m.group(1)
|
||||||
|
print(f"提取到 file_id = {fid}")
|
||||||
|
|
||||||
|
r3 = session.get(
|
||||||
|
DOWN_REQUEST_URL,
|
||||||
|
params={"file_id": fid, "scenario": "share", "unique_name": share_key},
|
||||||
|
timeout=15,
|
||||||
|
allow_redirects=False,
|
||||||
|
)
|
||||||
|
print(f"GET {DOWN_REQUEST_URL} -> {r3.status_code}")
|
||||||
|
if r3.status_code in (301, 302) and r3.headers.get("Location"):
|
||||||
|
return r3.headers["Location"]
|
||||||
|
data = r3.json()
|
||||||
|
if not data.get("success"):
|
||||||
|
raise RuntimeError(f"取直链失败: {data}")
|
||||||
|
return data["download_url"]
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
share_key = extract_share_key(SHARE_URL)
|
||||||
|
print(f"分享链接: {SHARE_URL}")
|
||||||
|
print(f"提取到的 shareKey: {share_key}\n")
|
||||||
|
|
||||||
|
session = requests.Session()
|
||||||
|
session.headers.update(HEADERS)
|
||||||
|
|
||||||
|
if not check_is_valid(share_key, session):
|
||||||
|
print("结论: 分享无效, 不再继续取直链。")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
url = get_download_url(share_key, SHARE_PASSWORD, session)
|
||||||
|
print(f"\n>>> 直链: {url}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\n取直链失败: {e}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "nfd-web",
|
"name": "nfd-web",
|
||||||
"version": "0.4.2",
|
"version": "0.4.6",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
"dev": "vue-cli-service serve",
|
"dev": "vue-cli-service serve",
|
||||||
"build": "node scripts/sync-version.js && vue-cli-service build && node scripts/compress-vs.js",
|
"build": "node scripts/sync-version.js && vue-cli-service build && node scripts/compress-vs.js",
|
||||||
"build:no-compress": "node scripts/sync-version.js && vue-cli-service build",
|
"build:no-compress": "node scripts/sync-version.js && vue-cli-service build",
|
||||||
"lint": "vue-cli-service lint"
|
"lint": "vue-cli-service lint",
|
||||||
|
"test": "node --test src/utils/batchTreeCollect.spec.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@element-plus/icons-vue": "^2.3.1",
|
"@element-plus/icons-vue": "^2.3.1",
|
||||||
|
|||||||
@@ -103,7 +103,23 @@
|
|||||||
<splitpanes v-if="!isMobile" class="split-theme custom-splitpanes" style="height:100%;">
|
<splitpanes v-if="!isMobile" class="split-theme custom-splitpanes" style="height:100%;">
|
||||||
<pane>
|
<pane>
|
||||||
<div class="tree-sidebar">
|
<div class="tree-sidebar">
|
||||||
<div class="tree-scroll-wrap">
|
<div class="tree-toolbar">
|
||||||
|
<span class="tree-toolbar-title">
|
||||||
|
<i class="fas fa-sitemap" aria-hidden="true"></i> 文件树
|
||||||
|
</span>
|
||||||
|
<el-button
|
||||||
|
v-if="!batchMode"
|
||||||
|
type="warning"
|
||||||
|
size="small"
|
||||||
|
@click="toggleBatchMode"
|
||||||
|
>
|
||||||
|
<i class="fas fa-check-double"></i> 批量下载
|
||||||
|
</el-button>
|
||||||
|
<span v-else class="tree-toolbar-hint">
|
||||||
|
{{ treeExpanding ? '正在展开并收集文件…' : `勾选文件夹将自动展开(最多 ${effectiveBatchMaxDepth} 层)` }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="tree-scroll-wrap" v-loading="treeExpanding">
|
||||||
<el-tree
|
<el-tree
|
||||||
ref="fileTree"
|
ref="fileTree"
|
||||||
:data="treeData"
|
:data="treeData"
|
||||||
@@ -115,6 +131,7 @@
|
|||||||
:show-checkbox="batchMode"
|
:show-checkbox="batchMode"
|
||||||
:check-strictly="false"
|
:check-strictly="false"
|
||||||
@node-click="onNodeClick"
|
@node-click="onNodeClick"
|
||||||
|
@check="onTreeCheck"
|
||||||
@check-change="onTreeCheckChange"
|
@check-change="onTreeCheckChange"
|
||||||
:default-expand-all="false"
|
:default-expand-all="false"
|
||||||
:default-expanded-keys="['root']"
|
:default-expanded-keys="['root']"
|
||||||
@@ -128,7 +145,7 @@
|
|||||||
<el-button
|
<el-button
|
||||||
type="primary"
|
type="primary"
|
||||||
size="small"
|
size="small"
|
||||||
:disabled="selectedFiles.length === 0 || batchDownloading || batchBrowserDownloadDisabled"
|
:disabled="selectedFiles.length === 0 || batchDownloading || treeExpanding || batchBrowserDownloadDisabled"
|
||||||
:loading="batchDownloading"
|
:loading="batchDownloading"
|
||||||
@click="batchBrowserDownload"
|
@click="batchBrowserDownload"
|
||||||
:title="batchBrowserDownloadDisabled ? '所选文件需使用下载器下载' : ''"
|
:title="batchBrowserDownloadDisabled ? '所选文件需使用下载器下载' : ''"
|
||||||
@@ -138,7 +155,7 @@
|
|||||||
<el-button
|
<el-button
|
||||||
type="success"
|
type="success"
|
||||||
size="small"
|
size="small"
|
||||||
:disabled="selectedFiles.length === 0 || batchDownloading"
|
:disabled="selectedFiles.length === 0 || batchDownloading || treeExpanding"
|
||||||
:loading="batchDownloading"
|
:loading="batchDownloading"
|
||||||
@click="batchSendToDownloader"
|
@click="batchSendToDownloader"
|
||||||
>
|
>
|
||||||
@@ -236,7 +253,23 @@
|
|||||||
<!-- 移动端:上下布局 -->
|
<!-- 移动端:上下布局 -->
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div class="mobile-tree-top">
|
<div class="mobile-tree-top">
|
||||||
<div class="tree-scroll-wrap">
|
<div class="tree-toolbar">
|
||||||
|
<span class="tree-toolbar-title">
|
||||||
|
<i class="fas fa-sitemap" aria-hidden="true"></i> 文件树
|
||||||
|
</span>
|
||||||
|
<el-button
|
||||||
|
v-if="!batchMode"
|
||||||
|
type="warning"
|
||||||
|
size="small"
|
||||||
|
@click="toggleBatchMode"
|
||||||
|
>
|
||||||
|
<i class="fas fa-check-double"></i> 批量下载
|
||||||
|
</el-button>
|
||||||
|
<span v-else class="tree-toolbar-hint">
|
||||||
|
{{ treeExpanding ? '正在展开并收集文件…' : `勾选文件夹将自动展开(最多 ${effectiveBatchMaxDepth} 层)` }}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div class="tree-scroll-wrap" v-loading="treeExpanding">
|
||||||
<el-tree
|
<el-tree
|
||||||
ref="fileTree"
|
ref="fileTree"
|
||||||
:data="treeData"
|
:data="treeData"
|
||||||
@@ -248,6 +281,7 @@
|
|||||||
:show-checkbox="batchMode"
|
:show-checkbox="batchMode"
|
||||||
:check-strictly="false"
|
:check-strictly="false"
|
||||||
@node-click="onNodeClick"
|
@node-click="onNodeClick"
|
||||||
|
@check="onTreeCheck"
|
||||||
@check-change="onTreeCheckChange"
|
@check-change="onTreeCheckChange"
|
||||||
:default-expand-all="false"
|
:default-expand-all="false"
|
||||||
:default-expanded-keys="['root']"
|
:default-expanded-keys="['root']"
|
||||||
@@ -328,8 +362,8 @@
|
|||||||
<div v-if="batchMode" class="mobile-batch-footer">
|
<div v-if="batchMode" class="mobile-batch-footer">
|
||||||
<span class="tree-sidebar-count">已勾选 {{ selectedFiles.length }} 个文件</span>
|
<span class="tree-sidebar-count">已勾选 {{ selectedFiles.length }} 个文件</span>
|
||||||
<div class="tree-sidebar-actions">
|
<div class="tree-sidebar-actions">
|
||||||
<el-button type="primary" size="small" :disabled="selectedFiles.length === 0 || batchDownloading || batchBrowserDownloadDisabled" :loading="batchDownloading" @click="batchBrowserDownload" :title="batchBrowserDownloadDisabled ? '所选文件需使用下载器下载' : ''">浏览器下载</el-button>
|
<el-button type="primary" size="small" :disabled="selectedFiles.length === 0 || batchDownloading || treeExpanding || batchBrowserDownloadDisabled" :loading="batchDownloading" @click="batchBrowserDownload" :title="batchBrowserDownloadDisabled ? '所选文件需使用下载器下载' : ''">浏览器下载</el-button>
|
||||||
<el-button type="success" size="small" :disabled="selectedFiles.length === 0 || batchDownloading" :loading="batchDownloading" @click="batchSendToDownloader">发送到下载器</el-button>
|
<el-button type="success" size="small" :disabled="selectedFiles.length === 0 || batchDownloading || treeExpanding" :loading="batchDownloading" @click="batchSendToDownloader">发送到下载器</el-button>
|
||||||
<el-button size="small" @click="toggleBatchMode">取消</el-button>
|
<el-button size="small" @click="toggleBatchMode">取消</el-button>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="batchDownloading" class="batch-progress-info">
|
<div v-if="batchDownloading" class="batch-progress-info">
|
||||||
@@ -420,6 +454,15 @@ import 'splitpanes/dist/splitpanes.css'
|
|||||||
import fileTypeUtils from '@/utils/fileTypeUtils'
|
import fileTypeUtils from '@/utils/fileTypeUtils'
|
||||||
import DownloadDialog from '@/components/DownloadDialog.vue'
|
import DownloadDialog from '@/components/DownloadDialog.vue'
|
||||||
import { testConnection, autoDetect, addDownload, batchAddDownload, getConfig, saveConfig } from '@/utils/downloaderService'
|
import { testConnection, autoDetect, addDownload, batchAddDownload, getConfig, saveConfig } from '@/utils/downloaderService'
|
||||||
|
import batchTreeCollect from '@/utils/batchTreeCollect'
|
||||||
|
|
||||||
|
const {
|
||||||
|
DEFAULT_BATCH_MAX_DEPTH,
|
||||||
|
getTreeNodeId,
|
||||||
|
normalizeTreeItem,
|
||||||
|
uniqueFiles,
|
||||||
|
collectFolderFiles
|
||||||
|
} = batchTreeCollect
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'DirectoryTree',
|
name: 'DirectoryTree',
|
||||||
@@ -445,6 +488,11 @@ export default {
|
|||||||
viewMode: {
|
viewMode: {
|
||||||
type: String,
|
type: String,
|
||||||
default: 'pane' // 'pane' or 'tree'
|
default: 'pane' // 'pane' or 'tree'
|
||||||
|
},
|
||||||
|
// 树批量勾选文件夹时的最大展开深度;用户勾选的文件夹为第 0 层,默认 5
|
||||||
|
batchMaxDepth: {
|
||||||
|
type: Number,
|
||||||
|
default: DEFAULT_BATCH_MAX_DEPTH
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
@@ -477,7 +525,8 @@ export default {
|
|||||||
batchMode: false,
|
batchMode: false,
|
||||||
selectedFiles: [],
|
selectedFiles: [],
|
||||||
batchDownloading: false,
|
batchDownloading: false,
|
||||||
batchProgress: { current: 0, total: 0, failed: 0 }
|
batchProgress: { current: 0, total: 0, failed: 0 },
|
||||||
|
treeExpanding: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -513,6 +562,10 @@ export default {
|
|||||||
batchBrowserDownloadDisabled() {
|
batchBrowserDownloadDisabled() {
|
||||||
return this.selectedFiles.length > 0
|
return this.selectedFiles.length > 0
|
||||||
&& this.selectedFiles.every(f => this.needsDownloader(f))
|
&& this.selectedFiles.every(f => this.needsDownloader(f))
|
||||||
|
},
|
||||||
|
effectiveBatchMaxDepth() {
|
||||||
|
const depth = Number(this.batchMaxDepth)
|
||||||
|
return Number.isFinite(depth) && depth >= 0 ? depth : DEFAULT_BATCH_MAX_DEPTH
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@@ -525,10 +578,7 @@ export default {
|
|||||||
id: 'root',
|
id: 'root',
|
||||||
fileName: '全部文件',
|
fileName: '全部文件',
|
||||||
fileType: 'folder',
|
fileType: 'folder',
|
||||||
children: (newList || []).map(item => ({
|
children: (newList || []).map(item => normalizeTreeItem(item)),
|
||||||
...item,
|
|
||||||
isLeaf: item.fileType !== 'folder'
|
|
||||||
})),
|
|
||||||
isLeaf: false
|
isLeaf: false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -536,6 +586,9 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
created() {
|
||||||
|
this.resetTreeCollectState()
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...fileTypeUtils,
|
...fileTypeUtils,
|
||||||
apiKeyHeaders() {
|
apiKeyHeaders() {
|
||||||
@@ -563,17 +616,14 @@ export default {
|
|||||||
}
|
}
|
||||||
return this.withAuth(`${baseUrl}?${params.toString()}`)
|
return this.withAuth(`${baseUrl}?${params.toString()}`)
|
||||||
},
|
},
|
||||||
// 懒加载子节点
|
// 懒加载子节点(批量勾选文件夹时会通过 node.expand → store.load 复用此方法)
|
||||||
loadNode(node, resolve) {
|
loadNode(node, resolve) {
|
||||||
if (node.level === 0) {
|
if (node.level === 0) {
|
||||||
resolve(this.treeData[0].children)
|
resolve((this.treeData[0]?.children || []).map(item => normalizeTreeItem(item)))
|
||||||
} else if (node.data.fileType === 'folder' && node.data.parserUrl) {
|
} else if (node.data.fileType === 'folder' && node.data.parserUrl) {
|
||||||
axios.get(this.withAuth(node.data.parserUrl), { headers: this.apiKeyHeaders() }).then(res => {
|
axios.get(this.withAuth(node.data.parserUrl), { headers: this.apiKeyHeaders() }).then(res => {
|
||||||
if (res.data.code === 200) {
|
if (res.data.code === 200) {
|
||||||
const children = (res.data.data || []).map(item => ({
|
const children = (res.data.data || []).map(item => normalizeTreeItem(item))
|
||||||
...item,
|
|
||||||
isLeaf: item.fileType !== 'folder'
|
|
||||||
}))
|
|
||||||
resolve(children)
|
resolve(children)
|
||||||
} else {
|
} else {
|
||||||
this.$message.error(res.data.msg || '获取子节点失败')
|
this.$message.error(res.data.msg || '获取子节点失败')
|
||||||
@@ -970,9 +1020,156 @@ export default {
|
|||||||
this.selectedFiles = []
|
this.selectedFiles = []
|
||||||
this.batchDownloading = false
|
this.batchDownloading = false
|
||||||
this.batchProgress = { current: 0, total: 0, failed: 0 }
|
this.batchProgress = { current: 0, total: 0, failed: 0 }
|
||||||
// tree 模式下清除勾选
|
this.treeExpanding = false
|
||||||
if (this.$refs.fileTree) {
|
this.resetTreeCollectState()
|
||||||
this.$refs.fileTree.setCheckedKeys([])
|
const tree = this.getFileTree()
|
||||||
|
if (tree) {
|
||||||
|
tree.setCheckedKeys([])
|
||||||
|
}
|
||||||
|
},
|
||||||
|
resetTreeCollectState() {
|
||||||
|
this._folderCheckQueue = []
|
||||||
|
this._queuedFolderKeys = new Set()
|
||||||
|
this._visitedInCollect = new Set()
|
||||||
|
this._folderLoadPromises = new Map()
|
||||||
|
this._treeCollecting = false
|
||||||
|
},
|
||||||
|
getFileTree() {
|
||||||
|
const ref = this.$refs.fileTree
|
||||||
|
if (!ref) return null
|
||||||
|
return Array.isArray(ref) ? ref[0] : ref
|
||||||
|
},
|
||||||
|
findTreeNode(data) {
|
||||||
|
const tree = this.getFileTree()
|
||||||
|
if (!tree || !data) return null
|
||||||
|
const key = getTreeNodeId(data)
|
||||||
|
if (key) {
|
||||||
|
const byKey = tree.getNode(key)
|
||||||
|
if (byKey) return byKey
|
||||||
|
}
|
||||||
|
const byData = tree.getNode(data)
|
||||||
|
if (byData) return byData
|
||||||
|
const nodesMap = tree.store?.nodesMap
|
||||||
|
if (nodesMap) {
|
||||||
|
return Object.values(nodesMap).find(node => getTreeNodeId(node.data) === key) || null
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
ensureTreeNodeLoaded(node) {
|
||||||
|
if (!node) return Promise.resolve(null)
|
||||||
|
const key = getTreeNodeId(node.data)
|
||||||
|
if (key && this._folderLoadPromises.has(key)) {
|
||||||
|
return this._folderLoadPromises.get(key)
|
||||||
|
}
|
||||||
|
const promise = new Promise((resolve) => {
|
||||||
|
if (node.loaded && node.expanded) {
|
||||||
|
resolve(node)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let settled = false
|
||||||
|
const finish = () => {
|
||||||
|
if (settled) return
|
||||||
|
settled = true
|
||||||
|
resolve(node)
|
||||||
|
}
|
||||||
|
const timer = setTimeout(finish, 20000)
|
||||||
|
const expandNow = () => {
|
||||||
|
if (node.loaded && node.expanded) {
|
||||||
|
clearTimeout(timer)
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
node.expand(() => {
|
||||||
|
clearTimeout(timer)
|
||||||
|
finish()
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
clearTimeout(timer)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (node.loading) {
|
||||||
|
const started = Date.now()
|
||||||
|
const poll = () => {
|
||||||
|
if (!node.loading || Date.now() - started > 20000) {
|
||||||
|
expandNow()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
setTimeout(poll, 50)
|
||||||
|
}
|
||||||
|
poll()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
expandNow()
|
||||||
|
})
|
||||||
|
if (key) this._folderLoadPromises.set(key, promise)
|
||||||
|
return promise
|
||||||
|
},
|
||||||
|
isCheckedInInfo(data, info) {
|
||||||
|
if (!info) return false
|
||||||
|
const key = getTreeNodeId(data)
|
||||||
|
if (key && (info.checkedKeys || []).map(String).includes(key)) return true
|
||||||
|
return (info.checkedNodes || []).some(n => getTreeNodeId(n) === key)
|
||||||
|
},
|
||||||
|
syncSelectedFilesFromTree(extraFiles = []) {
|
||||||
|
const tree = this.getFileTree()
|
||||||
|
const fromTree = tree
|
||||||
|
? tree.getCheckedNodes().filter(n => this.isDownloadableFile(n))
|
||||||
|
: []
|
||||||
|
this.selectedFiles = uniqueFiles([...fromTree, ...extraFiles])
|
||||||
|
},
|
||||||
|
enqueueFolderCollect(folderData) {
|
||||||
|
const key = getTreeNodeId(folderData)
|
||||||
|
if (!key || this._queuedFolderKeys.has(key) || this._visitedInCollect.has(key)) return
|
||||||
|
this._queuedFolderKeys.add(key)
|
||||||
|
this._folderCheckQueue.push(folderData)
|
||||||
|
this.drainFolderCollectQueue()
|
||||||
|
},
|
||||||
|
async drainFolderCollectQueue() {
|
||||||
|
if (this._treeCollecting) return
|
||||||
|
this._treeCollecting = true
|
||||||
|
this.treeExpanding = true
|
||||||
|
try {
|
||||||
|
while (this._folderCheckQueue.length) {
|
||||||
|
const next = this._folderCheckQueue.shift()
|
||||||
|
this._queuedFolderKeys.delete(getTreeNodeId(next))
|
||||||
|
await this.handleFolderCheck(next)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this._treeCollecting = false
|
||||||
|
this.treeExpanding = false
|
||||||
|
this._visitedInCollect.clear()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async handleFolderCheck(folderData) {
|
||||||
|
try {
|
||||||
|
const ctx = await collectFolderFiles({
|
||||||
|
folderData,
|
||||||
|
depth: 0,
|
||||||
|
maxDepth: this.effectiveBatchMaxDepth,
|
||||||
|
getNode: (data) => this.findTreeNode(data),
|
||||||
|
ensureLoaded: (node) => this.ensureTreeNodeLoaded(node),
|
||||||
|
isDownloadable: (data) => this.isDownloadableFile(data),
|
||||||
|
visitedKeys: this._visitedInCollect
|
||||||
|
})
|
||||||
|
this.syncSelectedFilesFromTree(ctx.files)
|
||||||
|
if (ctx.depthExceeded) {
|
||||||
|
this.$message.warning(
|
||||||
|
`已达到最大展开深度(${this.effectiveBatchMaxDepth} 层),部分深层文件未勾选`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('批量展开文件夹失败:', e)
|
||||||
|
this.$message.error('展开文件夹失败,已跳过部分内容')
|
||||||
|
this.syncSelectedFilesFromTree()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// 用户点击复选框(不含级联),文件夹勾选时触发递归展开
|
||||||
|
onTreeCheck(data, info) {
|
||||||
|
if (!this.batchMode || !data || data.fileType !== 'folder') return
|
||||||
|
if (this.isCheckedInInfo(data, info)) {
|
||||||
|
this.enqueueFolderCollect(data)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
isFileSelected(file) {
|
isFileSelected(file) {
|
||||||
@@ -988,6 +1185,8 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onBatchClick(file) {
|
onBatchClick(file) {
|
||||||
|
// 窗格批量:点击文件夹仍进入该目录(避免破坏现有导航)。
|
||||||
|
// 仅收集当前目录文件;递归展开只在树模式勾选文件夹时进行。
|
||||||
if (file.fileType === 'folder') {
|
if (file.fileType === 'folder') {
|
||||||
this.enterFolder(file)
|
this.enterFolder(file)
|
||||||
return
|
return
|
||||||
@@ -1001,9 +1200,8 @@ export default {
|
|||||||
this.selectedFiles = []
|
this.selectedFiles = []
|
||||||
},
|
},
|
||||||
onTreeCheckChange() {
|
onTreeCheckChange() {
|
||||||
if (!this.$refs.fileTree) return
|
if (!this.batchMode || this._treeCollecting) return
|
||||||
const checked = this.$refs.fileTree.getCheckedNodes()
|
this.syncSelectedFilesFromTree()
|
||||||
this.selectedFiles = checked.filter(n => this.isDownloadableFile(n))
|
|
||||||
},
|
},
|
||||||
extractTypeParam(file) {
|
extractTypeParam(file) {
|
||||||
if (!file.parserUrl) return null
|
if (!file.parserUrl) return null
|
||||||
@@ -1762,6 +1960,48 @@ html, body, #app, .main-container, .directory-tree, .content-card {
|
|||||||
border-right: 1px solid #eaeaea;
|
border-right: 1px solid #eaeaea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.tree-toolbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
flex-shrink: 0;
|
||||||
|
padding: 8px 10px;
|
||||||
|
border-bottom: 1px solid #eaeaea;
|
||||||
|
background: #f8f9fa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark-theme .tree-toolbar {
|
||||||
|
border-bottom-color: #404040;
|
||||||
|
background: #232323;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-toolbar-title {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #303133;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark-theme .tree-toolbar-title {
|
||||||
|
color: #e1e1e1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tree-toolbar-hint {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #909399;
|
||||||
|
line-height: 1.4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark-theme .tree-toolbar-hint {
|
||||||
|
color: #bdc3c7;
|
||||||
|
}
|
||||||
|
|
||||||
.tree-content {
|
.tree-content {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<template>
|
||||||
|
<el-radio-group
|
||||||
|
:model-value="modelValue"
|
||||||
|
size="small"
|
||||||
|
class="view-mode-switch"
|
||||||
|
@update:model-value="$emit('update:modelValue', $event)"
|
||||||
|
>
|
||||||
|
<el-radio-button label="pane" title="窗格视图">
|
||||||
|
<i class="fas fa-th" aria-hidden="true"></i>
|
||||||
|
<span class="view-mode-text">{{ paneLabel }}</span>
|
||||||
|
</el-radio-button>
|
||||||
|
<el-radio-button label="tree" title="文件树视图">
|
||||||
|
<i class="fas fa-sitemap" aria-hidden="true"></i>
|
||||||
|
<span class="view-mode-text">{{ treeLabel }}</span>
|
||||||
|
</el-radio-button>
|
||||||
|
</el-radio-group>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'ViewModeSwitch',
|
||||||
|
props: {
|
||||||
|
modelValue: {
|
||||||
|
type: String,
|
||||||
|
default: 'pane'
|
||||||
|
},
|
||||||
|
paneLabel: {
|
||||||
|
type: String,
|
||||||
|
default: '窗格'
|
||||||
|
},
|
||||||
|
treeLabel: {
|
||||||
|
type: String,
|
||||||
|
default: '文件树'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['update:modelValue']
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.view-mode-switch :deep(.el-radio-button__inner) {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 6px;
|
||||||
|
min-height: 36px;
|
||||||
|
min-width: 76px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
}
|
||||||
|
.view-mode-switch i {
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
.view-mode-text {
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 480px) {
|
||||||
|
.view-mode-switch :deep(.el-radio-button__inner) {
|
||||||
|
min-width: 68px;
|
||||||
|
min-height: 40px;
|
||||||
|
padding: 10px 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -246,8 +246,8 @@
|
|||||||
storage: 'hash'
|
storage: 'hash'
|
||||||
},
|
},
|
||||||
'123pan': {
|
'123pan': {
|
||||||
reg: /((?:https?:\/\/)?www\.(123pan|123865|123684)\.com\/s\/[\w-]{6,})/,
|
reg: /((?:https?:\/\/)?(?:[a-zA-Z\d-]+\.(?:m?share)\.123pan\.cn\/123pan\/[\w-]+|(?:www\.)?(?:123panpay|123pan|123\d{3})\.(?:com|cn)\/s\/[\w-]{6,}(?:\.html)?)(?:\?[^#\s]*)?)/i,
|
||||||
host: /www\.123pan\.com/,
|
host: /(?:[a-zA-Z\d-]+\.(?:m?share)\.123pan\.cn|(?:www\.)?(?:123panpay|123pan|123\d{3})\.(?:com|cn))/i,
|
||||||
input: ['.ca-fot input', ".appinput .appinput"],
|
input: ['.ca-fot input', ".appinput .appinput"],
|
||||||
button: ['.ca-fot button', ".appinput button"],
|
button: ['.ca-fot button', ".appinput button"],
|
||||||
name: '123云盘',
|
name: '123云盘',
|
||||||
@@ -377,6 +377,7 @@
|
|||||||
parseLink(text = '') {
|
parseLink(text = '') {
|
||||||
let obj = {name: '', link: '', storage: '', storagePwdName: ''};
|
let obj = {name: '', link: '', storage: '', storagePwdName: ''};
|
||||||
if (text) {
|
if (text) {
|
||||||
|
text = String(text).trim();
|
||||||
try {
|
try {
|
||||||
text = decodeURIComponent(text);
|
text = decodeURIComponent(text);
|
||||||
} catch {
|
} catch {
|
||||||
@@ -390,6 +391,9 @@
|
|||||||
let matches = text.match(val.reg);
|
let matches = text.match(val.reg);
|
||||||
obj.name = val.name;
|
obj.name = val.name;
|
||||||
obj.link = matches[0];
|
obj.link = matches[0];
|
||||||
|
if (obj.link && !/^https?:\/\//i.test(obj.link)) {
|
||||||
|
obj.link = 'https://' + obj.link.replace(/^\/\//, '');
|
||||||
|
}
|
||||||
obj.storage = val.storage;
|
obj.storage = val.storage;
|
||||||
obj.storagePwdName = val.storagePwdName || null;
|
obj.storagePwdName = val.storagePwdName || null;
|
||||||
if (val.replaceHost) {
|
if (val.replaceHost) {
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
/**
|
||||||
|
* 文件树批量勾选:按深度递归展开并收集可下载文件。
|
||||||
|
*
|
||||||
|
* Depth convention (checked folder = depth 0):
|
||||||
|
* - 用户勾选的文件夹为第 0 层。
|
||||||
|
* - 其直接子项为第 1 层。
|
||||||
|
* - 当 depth < maxDepth 时继续展开子文件夹;默认 maxDepth = 5,
|
||||||
|
* 即最多再向下展开 5 层(第 0/1/2/3/4 层会 load,第 5 层文件夹不再展开)。
|
||||||
|
* - 触及上限时若仍有未加载/剩余子文件夹,标记 depthExceeded,由 UI 提示跳过。
|
||||||
|
*/
|
||||||
|
|
||||||
|
const DEFAULT_BATCH_MAX_DEPTH = 5
|
||||||
|
|
||||||
|
function getTreeNodeId(item) {
|
||||||
|
if (!item) return ''
|
||||||
|
if (item.id) return String(item.id)
|
||||||
|
if (item.fileId) return `fid:${item.fileId}`
|
||||||
|
if (item.parserUrl) return `url:${item.parserUrl}`
|
||||||
|
return `name:${item.fileName || ''}:${item.fileType || ''}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeTreeItem(item) {
|
||||||
|
if (!item || typeof item !== 'object') return item
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
id: getTreeNodeId(item),
|
||||||
|
isLeaf: item.fileType !== 'folder'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function fileIdentity(file) {
|
||||||
|
return `${file?.parserUrl || ''}::${file?.fileName || ''}::${file?.fileId || file?.id || ''}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function uniqueFiles(files) {
|
||||||
|
const seen = new Set()
|
||||||
|
const out = []
|
||||||
|
for (const file of files || []) {
|
||||||
|
const key = fileIdentity(file)
|
||||||
|
if (!key || seen.has(key)) continue
|
||||||
|
seen.add(key)
|
||||||
|
out.push(file)
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
function isFolderNode(data) {
|
||||||
|
return !!(data && data.fileType === 'folder')
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectAlreadyLoadedFiles(node, isDownloadable, ctx) {
|
||||||
|
for (const child of node.childNodes || []) {
|
||||||
|
if (isDownloadable(child.data)) {
|
||||||
|
ctx.files.push(child.data)
|
||||||
|
} else if (isFolderNode(child.data) && child.loaded) {
|
||||||
|
collectAlreadyLoadedFiles(child, isDownloadable, ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasUnexploredFolders(node) {
|
||||||
|
if (!node) return false
|
||||||
|
if (isFolderNode(node.data) && !node.loaded) return true
|
||||||
|
return (node.childNodes || []).some((child) => {
|
||||||
|
if (!isFolderNode(child.data)) return false
|
||||||
|
if (!child.loaded) return true
|
||||||
|
return hasUnexploredFolders(child)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归展开文件夹并收集可下载文件(对接 el-tree node / loadNode)。
|
||||||
|
*
|
||||||
|
* @param {object} opts
|
||||||
|
* @param {object} opts.folderData 勾选的文件夹 data(depth 从 0 计)
|
||||||
|
* @param {number} [opts.depth=0]
|
||||||
|
* @param {number} opts.maxDepth
|
||||||
|
* @param {(data: object) => any} opts.getNode el-tree getNode
|
||||||
|
* @param {(node: any) => Promise<any>} opts.ensureLoaded 展开并触发懒加载
|
||||||
|
* @param {(data: object) => boolean} opts.isDownloadable
|
||||||
|
* @param {Set<string>} [opts.visitedKeys]
|
||||||
|
* @param {(data: object) => string} [opts.getKey]
|
||||||
|
* @param {{ files: object[], depthExceeded: boolean }} [opts.ctx]
|
||||||
|
*/
|
||||||
|
async function collectFolderFiles(opts) {
|
||||||
|
const {
|
||||||
|
folderData,
|
||||||
|
depth = 0,
|
||||||
|
maxDepth,
|
||||||
|
getNode,
|
||||||
|
ensureLoaded,
|
||||||
|
isDownloadable,
|
||||||
|
getKey = getTreeNodeId,
|
||||||
|
visitedKeys = new Set(),
|
||||||
|
ctx = { files: [], depthExceeded: false }
|
||||||
|
} = opts
|
||||||
|
|
||||||
|
if (!folderData || typeof maxDepth !== 'number') return ctx
|
||||||
|
|
||||||
|
const key = getKey(folderData)
|
||||||
|
if (key) visitedKeys.add(key)
|
||||||
|
|
||||||
|
const node = getNode(folderData)
|
||||||
|
if (!node) return ctx
|
||||||
|
|
||||||
|
if (depth >= maxDepth) {
|
||||||
|
// 未 load 的节点在真实 el-tree 中没有 childNodes,不能把预置子项算进去
|
||||||
|
if (node.loaded) {
|
||||||
|
collectAlreadyLoadedFiles(node, isDownloadable, ctx)
|
||||||
|
if (hasUnexploredFolders(node)) {
|
||||||
|
ctx.depthExceeded = true
|
||||||
|
}
|
||||||
|
} else if (isFolderNode(node.data)) {
|
||||||
|
ctx.depthExceeded = true
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await ensureLoaded(node)
|
||||||
|
} catch {
|
||||||
|
// 单层加载失败:跳过该分支,不中断整次收集
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const child of node.childNodes || []) {
|
||||||
|
const data = child.data
|
||||||
|
if (!data) continue
|
||||||
|
if (isDownloadable(data)) {
|
||||||
|
ctx.files.push(data)
|
||||||
|
} else if (isFolderNode(data)) {
|
||||||
|
await collectFolderFiles({
|
||||||
|
...opts,
|
||||||
|
folderData: data,
|
||||||
|
depth: depth + 1,
|
||||||
|
visitedKeys,
|
||||||
|
ctx
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
DEFAULT_BATCH_MAX_DEPTH,
|
||||||
|
getTreeNodeId,
|
||||||
|
normalizeTreeItem,
|
||||||
|
fileIdentity,
|
||||||
|
uniqueFiles,
|
||||||
|
isFolderNode,
|
||||||
|
collectFolderFiles
|
||||||
|
}
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
const { describe, it } = require('node:test')
|
||||||
|
const assert = require('node:assert/strict')
|
||||||
|
|
||||||
|
const {
|
||||||
|
DEFAULT_BATCH_MAX_DEPTH,
|
||||||
|
getTreeNodeId,
|
||||||
|
normalizeTreeItem,
|
||||||
|
fileIdentity,
|
||||||
|
uniqueFiles,
|
||||||
|
collectFolderFiles
|
||||||
|
} = require('./batchTreeCollect.js')
|
||||||
|
|
||||||
|
function file(name, extra = {}) {
|
||||||
|
return {
|
||||||
|
fileName: name,
|
||||||
|
fileType: 'file',
|
||||||
|
parserUrl: `/v2/redirectUrl/demo/${name}`,
|
||||||
|
...extra
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function folder(name, extra = {}) {
|
||||||
|
return {
|
||||||
|
fileName: name,
|
||||||
|
fileType: 'folder',
|
||||||
|
parserUrl: `/v2/getFileList?dir=${name}`,
|
||||||
|
...extra
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeNode(data, children = [], { loaded = true, expanded = true, failLoad = false } = {}) {
|
||||||
|
const node = {
|
||||||
|
data,
|
||||||
|
loaded,
|
||||||
|
expanded,
|
||||||
|
childNodes: [],
|
||||||
|
expand(cb) {
|
||||||
|
if (failLoad) throw new Error('load failed')
|
||||||
|
this.loaded = true
|
||||||
|
this.expanded = true
|
||||||
|
if (cb) cb()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
node.childNodes = children.map((child) => (child.data ? child : makeNode(child)))
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
function createStore(rootNode) {
|
||||||
|
const map = new Map()
|
||||||
|
const walk = (node) => {
|
||||||
|
map.set(getTreeNodeId(node.data), node)
|
||||||
|
for (const child of node.childNodes || []) walk(child)
|
||||||
|
}
|
||||||
|
walk(rootNode)
|
||||||
|
return {
|
||||||
|
getNode(data) {
|
||||||
|
return map.get(getTreeNodeId(data)) || null
|
||||||
|
},
|
||||||
|
async ensureLoaded(node) {
|
||||||
|
if (node.loaded && node.expanded) return node
|
||||||
|
await new Promise((resolve) => node.expand(resolve))
|
||||||
|
for (const child of node.childNodes || []) {
|
||||||
|
map.set(getTreeNodeId(child.data), child)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
},
|
||||||
|
isDownloadable(data) {
|
||||||
|
return !!(data && data.parserUrl && data.fileType !== 'folder' && data.fileType !== 'url')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('batchTreeCollect helpers', () => {
|
||||||
|
it('uses checked folder as depth 0 and defaults max depth to 5', () => {
|
||||||
|
assert.equal(DEFAULT_BATCH_MAX_DEPTH, 5)
|
||||||
|
assert.equal(getTreeNodeId({ id: 'root' }), 'root')
|
||||||
|
assert.equal(normalizeTreeItem({ fileId: 'abc', fileType: 'folder' }).id, 'fid:abc')
|
||||||
|
assert.equal(normalizeTreeItem({ fileId: 'abc', fileType: 'folder' }).isLeaf, false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('deduplicates files by parserUrl + name + id', () => {
|
||||||
|
const a = file('a.txt', { fileId: '1' })
|
||||||
|
const dup = file('a.txt', { fileId: '1' })
|
||||||
|
const b = file('b.txt', { fileId: '2' })
|
||||||
|
assert.equal(fileIdentity(a), fileIdentity(dup))
|
||||||
|
assert.deepEqual(uniqueFiles([a, dup, b]).map((f) => f.fileName), ['a.txt', 'b.txt'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('collects current-level files and recurses into folders', async () => {
|
||||||
|
const leafA = file('a.txt')
|
||||||
|
const leafB = file('b.txt')
|
||||||
|
const nested = folder('nested')
|
||||||
|
const root = folder('root')
|
||||||
|
const store = createStore(makeNode(root, [
|
||||||
|
makeNode(leafA),
|
||||||
|
makeNode(nested, [makeNode(leafB)])
|
||||||
|
]))
|
||||||
|
|
||||||
|
const ctx = await collectFolderFiles({
|
||||||
|
folderData: root,
|
||||||
|
maxDepth: 4,
|
||||||
|
...store
|
||||||
|
})
|
||||||
|
assert.equal(ctx.depthExceeded, false)
|
||||||
|
assert.deepEqual(ctx.files.map((f) => f.fileName).sort(), ['a.txt', 'b.txt'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('default depth 5 expands four descendant folders then stops', async () => {
|
||||||
|
// depth 0 root → 1 d1 → 2 d2 → 3 d3 → 4 d4 → 5 d5 (cap, still has leftover folder)
|
||||||
|
const skipped = file('skipped.txt')
|
||||||
|
const capFile = file('cap.txt')
|
||||||
|
const d5 = folder('d5')
|
||||||
|
const d4 = folder('d4')
|
||||||
|
const d3 = folder('d3')
|
||||||
|
const d2 = folder('d2')
|
||||||
|
const d1 = folder('d1')
|
||||||
|
const root = folder('root')
|
||||||
|
const tree = makeNode(root, [
|
||||||
|
makeNode(d1, [
|
||||||
|
makeNode(d2, [
|
||||||
|
makeNode(d3, [
|
||||||
|
makeNode(d4, [
|
||||||
|
makeNode(d5, [
|
||||||
|
makeNode(capFile),
|
||||||
|
makeNode(folder('d6'), [makeNode(skipped)], { loaded: false, expanded: false })
|
||||||
|
], { loaded: true })
|
||||||
|
])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
const store = createStore(tree)
|
||||||
|
const loadedIds = []
|
||||||
|
const ctx = await collectFolderFiles({
|
||||||
|
folderData: root,
|
||||||
|
maxDepth: DEFAULT_BATCH_MAX_DEPTH,
|
||||||
|
getNode: store.getNode,
|
||||||
|
ensureLoaded: async (node) => {
|
||||||
|
loadedIds.push(node.data.fileName)
|
||||||
|
return store.ensureLoaded(node)
|
||||||
|
},
|
||||||
|
isDownloadable: store.isDownloadable
|
||||||
|
})
|
||||||
|
assert.equal(ctx.depthExceeded, true)
|
||||||
|
assert.deepEqual(ctx.files.map((f) => f.fileName), ['cap.txt'])
|
||||||
|
assert.ok(!ctx.files.some((f) => f.fileName === 'skipped.txt'))
|
||||||
|
assert.ok(loadedIds.includes('d4'))
|
||||||
|
assert.ok(!loadedIds.includes('d5'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('stops expanding at maxDepth and warns when remaining folders exist', async () => {
|
||||||
|
// depth 0: root
|
||||||
|
// depth 1: d1
|
||||||
|
// depth 2: d2
|
||||||
|
// depth 3: d3
|
||||||
|
// depth 4: d4 (cap when maxDepth=4) — still has child folder d5
|
||||||
|
const deepFile = file('deep.txt')
|
||||||
|
const skipped = file('skipped.txt')
|
||||||
|
const d5 = folder('d5')
|
||||||
|
const d4 = folder('d4')
|
||||||
|
const d3 = folder('d3')
|
||||||
|
const d2 = folder('d2')
|
||||||
|
const d1 = folder('d1')
|
||||||
|
const root = folder('root')
|
||||||
|
|
||||||
|
const d5Node = makeNode(d5, [makeNode(skipped)], { loaded: false, expanded: false })
|
||||||
|
const d4Node = makeNode(d4, [makeNode(deepFile), d5Node], { loaded: true })
|
||||||
|
const tree = makeNode(root, [
|
||||||
|
makeNode(d1, [
|
||||||
|
makeNode(d2, [
|
||||||
|
makeNode(d3, [d4Node])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
])
|
||||||
|
const store = createStore(tree)
|
||||||
|
|
||||||
|
let loadedIds = []
|
||||||
|
const ctx = await collectFolderFiles({
|
||||||
|
folderData: root,
|
||||||
|
maxDepth: 4,
|
||||||
|
getNode: store.getNode,
|
||||||
|
ensureLoaded: async (node) => {
|
||||||
|
loadedIds.push(node.data.fileName)
|
||||||
|
return store.ensureLoaded(node)
|
||||||
|
},
|
||||||
|
isDownloadable: store.isDownloadable
|
||||||
|
})
|
||||||
|
|
||||||
|
assert.equal(ctx.depthExceeded, true)
|
||||||
|
assert.deepEqual(ctx.files.map((f) => f.fileName), ['deep.txt'])
|
||||||
|
assert.ok(!ctx.files.some((f) => f.fileName === 'skipped.txt'))
|
||||||
|
assert.ok(!loadedIds.includes('d4'), 'depth-4 folder must not be expanded')
|
||||||
|
assert.ok(loadedIds.includes('root'))
|
||||||
|
assert.ok(loadedIds.includes('d3'))
|
||||||
|
})
|
||||||
|
|
||||||
|
it('collects already-loaded files at the depth cap without expanding further', async () => {
|
||||||
|
const capFile = file('cap.txt')
|
||||||
|
const inner = folder('inner')
|
||||||
|
const cap = folder('cap')
|
||||||
|
const root = folder('root')
|
||||||
|
const tree = makeNode(root, [
|
||||||
|
makeNode(cap, [
|
||||||
|
makeNode(capFile),
|
||||||
|
makeNode(inner, [makeNode(file('too-deep.txt'))], { loaded: false })
|
||||||
|
])
|
||||||
|
])
|
||||||
|
const store = createStore(tree)
|
||||||
|
const ctx = await collectFolderFiles({
|
||||||
|
folderData: root,
|
||||||
|
maxDepth: 1,
|
||||||
|
...store
|
||||||
|
})
|
||||||
|
assert.equal(ctx.depthExceeded, true)
|
||||||
|
assert.deepEqual(ctx.files.map((f) => f.fileName), ['cap.txt'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('skips a branch when ensureLoaded throws', async () => {
|
||||||
|
const ok = file('ok.txt')
|
||||||
|
const badFolder = folder('bad')
|
||||||
|
const root = folder('root')
|
||||||
|
const badNode = makeNode(badFolder, [makeNode(file('lost.txt'))], { loaded: false, failLoad: true })
|
||||||
|
const tree = makeNode(root, [makeNode(ok), badNode])
|
||||||
|
const store = createStore(tree)
|
||||||
|
const ctx = await collectFolderFiles({
|
||||||
|
folderData: root,
|
||||||
|
maxDepth: 4,
|
||||||
|
getNode: store.getNode,
|
||||||
|
ensureLoaded: async (node) => {
|
||||||
|
if (node.data.fileName === 'bad') throw new Error('network')
|
||||||
|
return store.ensureLoaded(node)
|
||||||
|
},
|
||||||
|
isDownloadable: store.isDownloadable
|
||||||
|
})
|
||||||
|
assert.deepEqual(ctx.files.map((f) => f.fileName), ['ok.txt'])
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
<!-- 开关按钮,控制是否自动读取剪切板 -->
|
<!-- 开关按钮,控制是否自动读取剪切板 -->
|
||||||
<el-switch v-model="autoReadClipboard" active-text="自动识别剪切板"></el-switch>
|
<el-switch v-model="autoReadClipboard" active-text="自动识别剪切板"></el-switch>
|
||||||
|
|
||||||
<el-input placeholder="请粘贴分享链接(http://或https://)" v-model="link" id="url" @paste="onPaste">
|
<el-input placeholder="请粘贴分享链接(http://或https://)" v-model="link" id="url" @paste="onPaste" @blur="normalizeShortcutInput">
|
||||||
<template #prepend>分享链接</template>
|
<template #prepend>分享链接</template>
|
||||||
<template #append v-if="!autoReadClipboard">
|
<template #append v-if="!autoReadClipboard">
|
||||||
<el-button @click="getPaste(true)">读取剪切板</el-button>
|
<el-button @click="getPaste(true)">读取剪切板</el-button>
|
||||||
@@ -417,10 +417,7 @@
|
|||||||
<!-- 目录树组件 -->
|
<!-- 目录树组件 -->
|
||||||
<div v-if="showDirectoryTree" class="directory-tree-container">
|
<div v-if="showDirectoryTree" class="directory-tree-container">
|
||||||
<div style="margin-bottom: 10px; text-align: right;">
|
<div style="margin-bottom: 10px; text-align: right;">
|
||||||
<el-radio-group v-model="directoryViewMode" size="small">
|
<ViewModeSwitch v-model="directoryViewMode" pane-label="窗格" tree-label="文件树" />
|
||||||
<el-radio-button label="pane">窗格</el-radio-button>
|
|
||||||
<el-radio-button label="tree">文件树</el-radio-button>
|
|
||||||
</el-radio-group>
|
|
||||||
</div>
|
</div>
|
||||||
<DirectoryTree
|
<DirectoryTree
|
||||||
:file-list="directoryData"
|
:file-list="directoryData"
|
||||||
@@ -619,6 +616,7 @@ import axios from 'axios'
|
|||||||
import QRCode from 'qrcode'
|
import QRCode from 'qrcode'
|
||||||
import DarkMode from '@/components/DarkMode'
|
import DarkMode from '@/components/DarkMode'
|
||||||
import DirectoryTree from '@/components/DirectoryTree'
|
import DirectoryTree from '@/components/DirectoryTree'
|
||||||
|
import ViewModeSwitch from '@/components/ViewModeSwitch'
|
||||||
import DownloadDialog from '@/components/DownloadDialog'
|
import DownloadDialog from '@/components/DownloadDialog'
|
||||||
import parserUrl from '../parserUrl1'
|
import parserUrl from '../parserUrl1'
|
||||||
import fileTypeUtils from '@/utils/fileTypeUtils'
|
import fileTypeUtils from '@/utils/fileTypeUtils'
|
||||||
@@ -629,7 +627,7 @@ import { PREVIEW_BASE_URL } from '@/utils/constants'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Home',
|
name: 'Home',
|
||||||
components: { DarkMode, DirectoryTree, DownloadDialog },
|
components: { DarkMode, DirectoryTree, ViewModeSwitch, DownloadDialog },
|
||||||
mixins: [fileTypeUtils],
|
mixins: [fileTypeUtils],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@@ -1143,10 +1141,24 @@ export default {
|
|||||||
normalizeShortcutInput() {
|
normalizeShortcutInput() {
|
||||||
if (!this.link) return
|
if (!this.link) return
|
||||||
const trimmed = this.link.trim()
|
const trimmed = this.link.trim()
|
||||||
if (!trimmed) return
|
if (!trimmed) {
|
||||||
|
this.link = ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.link = trimmed
|
||||||
|
|
||||||
// 已经是直接链接,跳过
|
// 已经是直接链接:仍尝试从整段文本中抽出标准分享地址
|
||||||
if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) return
|
if (trimmed.startsWith('http://') || trimmed.startsWith('https://')) {
|
||||||
|
const linkInfo = parserUrl.parseLink(trimmed)
|
||||||
|
if (linkInfo.link) {
|
||||||
|
this.link = linkInfo.link
|
||||||
|
const pwd = parserUrl.parsePwd(trimmed)
|
||||||
|
if (!this.password && pwd) {
|
||||||
|
this.password = pwd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 尝试短格式
|
// 尝试短格式
|
||||||
const shortInfo = this.expandShortFormat(trimmed)
|
const shortInfo = this.expandShortFormat(trimmed)
|
||||||
@@ -1420,7 +1432,7 @@ export default {
|
|||||||
// 获取剪切板内容
|
// 获取剪切板内容
|
||||||
async getPaste(isManual = false) {
|
async getPaste(isManual = false) {
|
||||||
try {
|
try {
|
||||||
const text = await navigator.clipboard.readText()
|
const text = (await navigator.clipboard.readText() || '').trim()
|
||||||
|
|
||||||
const shortInfo = this.expandShortFormat(text)
|
const shortInfo = this.expandShortFormat(text)
|
||||||
if (shortInfo) {
|
if (shortInfo) {
|
||||||
|
|||||||
@@ -8,10 +8,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div style="text-align:right;margin-bottom:12px;">
|
<div style="text-align:right;margin-bottom:12px;">
|
||||||
<DarkMode @theme-change="toggleTheme" style="float: left;"/>
|
<DarkMode @theme-change="toggleTheme" style="float: left;"/>
|
||||||
<el-radio-group v-model="viewMode" size="small" style="margin-left:20px;">
|
<ViewModeSwitch
|
||||||
<el-radio-button label="pane">窗格</el-radio-button>
|
v-model="viewMode"
|
||||||
<el-radio-button label="tree">目录树</el-radio-button>
|
pane-label="窗格"
|
||||||
</el-radio-group>
|
tree-label="目录树"
|
||||||
|
style="margin-left:20px;"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="loading" style="text-align:center;margin-top:40px;">加载中...</div>
|
<div v-if="loading" style="text-align:center;margin-top:40px;">加载中...</div>
|
||||||
<div v-else-if="error" style="color:red;text-align:center;margin-top:40px;">{{ error }}</div>
|
<div v-else-if="error" style="color:red;text-align:center;margin-top:40px;">{{ error }}</div>
|
||||||
@@ -29,11 +31,12 @@
|
|||||||
<script>
|
<script>
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import DirectoryTree from '@/components/DirectoryTree'
|
import DirectoryTree from '@/components/DirectoryTree'
|
||||||
|
import ViewModeSwitch from '@/components/ViewModeSwitch'
|
||||||
import DarkMode from '@/components/DarkMode'
|
import DarkMode from '@/components/DarkMode'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ShowList',
|
name: 'ShowList',
|
||||||
components: { DirectoryTree, DarkMode },
|
components: { DirectoryTree, ViewModeSwitch, DarkMode },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
loading: true,
|
loading: true,
|
||||||
|
|||||||
+12
-1
@@ -30,6 +30,16 @@
|
|||||||
<groupId>cn.qaiu</groupId>
|
<groupId>cn.qaiu</groupId>
|
||||||
<artifactId>parser</artifactId>
|
<artifactId>parser</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@@ -81,7 +91,8 @@
|
|||||||
${project.basedir}/src/main/generated
|
${project.basedir}/src/main/generated
|
||||||
</generatedSourcesDirectory>
|
</generatedSourcesDirectory>
|
||||||
<compilerArgs>
|
<compilerArgs>
|
||||||
<arg>-AoutputDirectory=${project.basedir}/src/main -Xlint:unchecked</arg>
|
<arg>-AoutputDirectory=${project.basedir}/src/main</arg>
|
||||||
|
<arg>-Xlint:unchecked</arg>
|
||||||
</compilerArgs>
|
</compilerArgs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
@@ -463,11 +463,14 @@ public class ParserApi {
|
|||||||
// 获取版本号
|
// 获取版本号
|
||||||
@RouteMapping("/build-version")
|
@RouteMapping("/build-version")
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return CommonUtil.getAppVersion()
|
String version = CommonUtil.getAppVersion();
|
||||||
|
if (version == null || version.isBlank()) {
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
return version
|
||||||
.replace("-", "")
|
.replace("-", "")
|
||||||
.replace("Z", "")
|
.replace("Z", "")
|
||||||
.replace("T", "_")
|
.replace("T", "_")
|
||||||
.replace("-", "")
|
|
||||||
.replace(":", "");
|
.replace(":", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user