Compare commits

...

8 Commits

Author SHA1 Message Date
copilot-swe-agent[bot]
803e0a1cb3 feat: add Feishu cloud drive share parsing support (FS)
- Add FsTool.java parser implementation for Feishu cloud drive
- Add FS entry to PanDomainTemplate with regex for file/folder URLs
- Add feishu-dl.py Python reference implementation
- Add FsToolTest.java with 8 test cases for regex and parser flow
- Update README.md to include Feishu in supported disk list

Agent-Logs-Url: https://github.com/qaiu/netdisk-fast-download/sessions/10b5c877-4690-4e35-aab8-bfd26a0810d1

Co-authored-by: qaiu <29825328+qaiu@users.noreply.github.com>
2026-04-18 08:52:24 +00:00
copilot-swe-agent[bot]
51b2d3119b Initial plan 2026-04-18 08:40:30 +00:00
qaiu
cc9d0a4b30 更新 README.md 2026-04-15 05:16:47 +08:00
qaiu
696ef832f8 更新 README.md 2026-04-13 08:03:04 +08:00
qaiu
442f9d1d2e Merge pull request #176 from qaiu/copilot/optimize-pandomain-template
fix(PanDomainTemplate): 修复现有网盘域名模板正则表达式中的多处缺陷
2026-04-12 19:45:06 +08:00
copilot-swe-agent[bot]
49ec54a3b5 refactor(tests): 改善测试注释说明,增强可读性
Agent-Logs-Url: https://github.com/qaiu/netdisk-fast-download/sessions/5523822b-ffe2-4e95-ac13-fd3f0dc41970

Co-authored-by: qaiu <29825328+qaiu@users.noreply.github.com>
2026-04-12 11:19:51 +00:00
copilot-swe-agent[bot]
d815cc1010 fix(PanDomainTemplate): 优化现有网盘域名模板正则表达式
Agent-Logs-Url: https://github.com/qaiu/netdisk-fast-download/sessions/5523822b-ffe2-4e95-ac13-fd3f0dc41970

Co-authored-by: qaiu <29825328+qaiu@users.noreply.github.com>
2026-04-12 11:17:06 +00:00
copilot-swe-agent[bot]
fd84ff1200 Initial plan 2026-04-12 11:05:17 +00:00
6 changed files with 507 additions and 31 deletions

View File

@@ -1,3 +1,15 @@
# 一款网盘分享链接云解析快速下载服务
QQ交流群1017480890
<p align="center">
<a href="https://github.com/qaiu/netdisk-fast-download/actions/workflows/maven.yml"><img src="https://img.shields.io/github/actions/workflow/status/qaiu/netdisk-fast-download/maven.yml?branch=v0.1.9b8a&style=flat"></a>
<a href="https://www.oracle.com/cn/java/technologies/downloads"><img src="https://img.shields.io/badge/jdk-%3E%3D17-blue"></a>
<a href="https://vertx-china.github.io"><img src="https://img.shields.io/badge/vert.x-4.5.22-blue?style=flat"></a>
<a href="https://raw.githubusercontent.com/qaiu/netdisk-fast-download/master/LICENSE"><img src="https://img.shields.io/github/license/qaiu/netdisk-fast-download?style=flat"></a>
<a href="https://github.com/qaiu/netdisk-fast-download/releases/"><img src="https://img.shields.io/github/v/release/qaiu/netdisk-fast-download?style=flat"></a>
<p align="center">
<a href="https://trendshift.io/repositories/12101" target="_blank"><img src="https://trendshift.io/api/badge/repositories/12101" alt="qaiu%2Fnetdisk-fast-download | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
</p>
<div align="center" style="display:flex; justify-content:center; gap:10px; align-items:flex-start;">
<img
src="https://github.com/user-attachments/assets/bf266d0a-aaf8-4772-9231-e38a4b7bb6cb"
@@ -10,26 +22,13 @@
style="width:300px; max-width:300px; flex:none;"
>
</div>
<p align="center">
<a href="https://trendshift.io/repositories/12101" target="_blank"><img src="https://trendshift.io/api/badge/repositories/12101" alt="qaiu%2Fnetdisk-fast-download | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
</p>
<p align="center">
<a href="https://github.com/qaiu/netdisk-fast-download/actions/workflows/maven.yml"><img src="https://img.shields.io/github/actions/workflow/status/qaiu/netdisk-fast-download/maven.yml?branch=v0.1.9b8a&style=flat"></a>
<a href="https://www.oracle.com/cn/java/technologies/downloads"><img src="https://img.shields.io/badge/jdk-%3E%3D17-blue"></a>
<a href="https://vertx-china.github.io"><img src="https://img.shields.io/badge/vert.x-4.5.22-blue?style=flat"></a>
<a href="https://raw.githubusercontent.com/qaiu/netdisk-fast-download/master/LICENSE"><img src="https://img.shields.io/github/license/qaiu/netdisk-fast-download?style=flat"></a>
<a href="https://github.com/qaiu/netdisk-fast-download/releases/"><img src="https://img.shields.io/github/v/release/qaiu/netdisk-fast-download?style=flat"></a>
# netdisk-fast-download 网盘分享链接云解析服务
QQ交流群1017480890
> netdisk-fast-download网盘直链解析可以把云盘分享链接转为直链可广泛应用于各类下载站资源站个人博客图床APP下载更新视频点播等领域。支持市面各大主流云盘的文件分享以及文件夹分享链接已支持蓝奏云/蓝奏云优享/奶牛快传/移动云云空间/小飞机盘/亿方云/123云盘/Cloudreve等支持加密分享以及部分网盘文件夹分享。
[官方文档](https://nfd-parser.github.io/)
[API接入](https://nfdparser.apifox.cn/)
[公益解析lz站](https://lz.qaiu.top)
[公益解析lz0m](https://lz0.qaiu.top)
[公益解析lz0站](https://lz0.qaiu.top)
[专业版189站注册体验](https://189.qaiu.top)
## 快速开始
@@ -88,6 +87,7 @@ https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.
- ~[微雨云存储-pvvy](https://www.vyuyun.com/)~
- [超星云盘(需要referer: https://pan-yz.chaoxing.com)-pcx](https://pan-yz.chaoxing.com)
- [WPS云文档-pwps](https://www.kdocs.cn/)
- [飞书云盘-fs](https://www.feishu.cn/)
- [汽水音乐-qishui_music](https://music.douyin.com/qishui/)
- [咪咕音乐-migu](https://music.migu.cn/)
- [一刻相册-baidu_photo](https://photo.baidu.com/)

View File

@@ -68,8 +68,8 @@ public enum PanDomainTemplate {
t-is.cn
*/
LZ("蓝奏云",
compile("https://(?:[a-zA-Z\\d-]+\\.)?(" +
"lanzoul|" +
compile("https://(?:[a-zA-Z\\d-]+\\.)?(?:" +
"(?:lanzoul|" +
"lanzouh|" +
"lanosso|" +
"lanpv|" +
@@ -95,14 +95,16 @@ public enum PanDomainTemplate {
"lanzv|" +
"dmpdmp|" +
"lanrar|" +
"webgetstore|" +
"lanzb|" +
"lanzoux|" +
"lanzout|" +
"lanzouc|" +
"lanzoui|" +
"lanzoug|" +
"lanzoum" +
")\\.com/(?<KEY>.+)"),
"lanzoum)\\.com" +
"|t-is\\.cn" +
")/(?<KEY>.+)"),
"https://w1.lanzn.com/{shareKey}",
LzTool.class),
@@ -115,7 +117,7 @@ public enum PanDomainTemplate {
// https://lecloud.lenovo.com/share/
LE("联想乐云",
compile("https://lecloud?\\.lenovo\\.com/share/(?<KEY>.+)"),
compile("https://lecloud\\.lenovo\\.com/share/(?<KEY>.+)"),
"https://lecloud.lenovo.com/share/{shareKey}",
LeTool.class),
@@ -241,7 +243,7 @@ public enum PanDomainTemplate {
EcTool.class),
// https://cowtransfer.com/s/
COW("奶牛快传",
compile("https://(.*)cowtransfer\\.com/s/(?<KEY>.+)"),
compile("https://(?:[a-zA-Z\\d-]+\\.)?cowtransfer\\.com/s/(?<KEY>.+)"),
"https://cowtransfer.com/s/{shareKey}",
CowTool.class),
CT("城通网盘",
@@ -264,7 +266,7 @@ public enum PanDomainTemplate {
PodTool.class),
// 404网盘 https://drive.google.com/file/d/xxx/view?usp=sharing
PGD("GoogleDrive",
compile("https://drive\\.google\\.com/file/d/(?<KEY>.+)/view(\\?usp=(sharing|drive_link))?"),
compile("https://(?:[a-zA-Z\\d-]+\\.)?drive\\.google\\.com/file/d/(?<KEY>.+)/view(\\?usp=(sharing|drive_link))?"),
"https://drive.google.com/file/d/{shareKey}/view?usp=sharing",
PgdTool.class),
// iCloud https://www.icloud.com.cn/iclouddrive/xxx#fonts
@@ -274,11 +276,11 @@ public enum PanDomainTemplate {
PicTool.class),
// https://www.dropbox.com/scl/fi/cwnbms1yn8u6rcatzyta7/emqx-5.0.26-el7-amd64.tar.gz?rlkey=3uoi4bxz5mv93jmlaws0nlol1&e=8&st=fe0lclc2&dl=0
PDB("dropbox",
compile("https://www.dropbox.com/scl/fi/(?<KEY>\\w+)/.+?rlkey=(?<PWD>\\w+).*"),
compile("https://www\\.dropbox\\.com/scl/fi/(?<KEY>\\w+)/.+?rlkey=(?<PWD>\\w+).*"),
"https://www.dropbox.com/scl/fi/{shareKey}/?rlkey={pwd}&dl=0",
PdbTool.class),
P115("115网盘",
compile("https://(115|anxia).com/s/(?<KEY>\\w+)(\\?password=(?<PWD>\\w+))?([&#].*)?"),
compile("https://(115|anxia)\\.com/s/(?<KEY>\\w+)(\\?password=(?<PWD>\\w+))?([&#].*)?"),
"https://115.com/s/{shareKey}?password={pwd}",
P115Tool.class),
// 链接https://www.yunpan.com/surl_yD7wz4VgU9v提取码fc70
@@ -310,6 +312,13 @@ public enum PanDomainTemplate {
compile("https://pan\\.quark\\.cn/s/(?<KEY>\\w+)([&#].*)?"),
"https://pan.quark.cn/s/{shareKey}",
QkTool.class),
// https://kcncuknojm60.feishu.cn/file/VnCxbt35KoowKoxldO3c3C7VnMc?from=from_copylink
// https://kcncuknojm60.feishu.cn/drive/folder/RQSKf8EQ4l7dMedqzHucpMbancg?from=from_copylink
FS("飞书云盘",
compile("https://[a-zA-Z\\d]+\\.feishu\\.cn/(file|drive/folder)/(?<KEY>[a-zA-Z\\d_-]+)(\\?.*)?"),
"https://feishu.cn/file/{shareKey}",
"https://www.feishu.cn/",
FsTool.class),
// =====================音乐类解析 分享链接标志->MxxS (单歌曲/普通音质)==========================
// http://163cn.tv/xxx
@@ -319,7 +328,7 @@ public enum PanDomainTemplate {
MnesTool.class),
// https://music.163.com/#/song?id=xxx
MNE("网易云音乐歌曲详情",
compile("https://(y.)?music\\.163\\.com/(#|m/)?song\\?id=(?<KEY>.+)(&.*)?"),
compile("https://(y\\.)?music\\.163\\.com/(?:#/|m/)?song\\?id=(?<KEY>.+)(&.*)?"),
"https://music.163.com/#/song?id={shareKey}",
MnesTool.MneTool.class),
// https://c6.y.qq.com/base/fcgi-bin/u?__=xxx
@@ -340,7 +349,7 @@ public enum PanDomainTemplate {
MkgsTool.class),
// https://www.kugou.com/share/2bi8Fe9CSV3.html?id=2bi8Fe9CSV3#6ed9gna4"
MKGS2("酷狗音乐分享2",
compile("https://(?:[a-zA-Z\\d-]+\\.)?kugou\\.com/share/(?<KEY>.+).html.*"),
compile("https://(?:[a-zA-Z\\d-]+\\.)?kugou\\.com/share/(?<KEY>.+)\\.html.*"),
"https://www.kugou.com/share/{shareKey}.html",
MkgsTool.Mkgs2Tool.class),
// https://www.kugou.com/mixsong/2bi8Fe9CSV3

View File

@@ -0,0 +1,100 @@
package cn.qaiu.parser.impl;
import cn.qaiu.entity.ShareLinkInfo;
import cn.qaiu.parser.PanBase;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
import java.net.URL;
/**
* <a href="https://www.feishu.cn/">飞书云盘(fs)</a>
* 分享格式:
* <ul>
* <li>文件: https://xxx.feishu.cn/file/TOKEN?from=from_copylink</li>
* <li>文件夹: https://xxx.feishu.cn/drive/folder/TOKEN?from=from_copylink</li>
* </ul>
* ?from=from_copylink 是可选参数,没有分享密码
*/
public class FsTool extends PanBase {
private static final String DOWNLOAD_API_PATH = "/space/api/box/stream/download/all/";
private static final String UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " +
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";
public FsTool(ShareLinkInfo shareLinkInfo) {
super(shareLinkInfo);
}
@Override
public Future<String> parse() {
String shareUrl = shareLinkInfo.getShareUrl();
try {
// 去除查询参数以获取干净的URL
String cleanUrl = shareUrl.contains("?") ? shareUrl.substring(0, shareUrl.indexOf("?")) : shareUrl;
URL url = new URL(cleanUrl);
String host = url.getHost();
String path = url.getPath();
String token = shareLinkInfo.getShareKey();
if (path.contains("/file/")) {
// 文件分享 - 获取下载直链
getDownloadUrl(host, token);
} else if (path.contains("/drive/folder/")) {
fail("飞书文件夹分享暂不支持直接下载,请使用文件分享链接");
} else {
fail("不支持的飞书链接格式: {}", path);
}
} catch (Exception e) {
fail(e, "解析飞书分享链接失败");
}
return promise.future();
}
/**
* 通过飞书下载API获取文件直链
*
* @param host 飞书域名 (如 kcncuknojm60.feishu.cn)
* @param token 文件token
*/
private void getDownloadUrl(String host, String token) {
String downloadApiUrl = "https://" + host + DOWNLOAD_API_PATH + token + "?mount_point=explorer";
clientNoRedirects.getAbs(downloadApiUrl)
.putHeader("User-Agent", UA)
.putHeader("Referer", "https://" + host + "/")
.send()
.onSuccess(res -> {
int statusCode = res.statusCode();
if (statusCode == 302 || statusCode == 301) {
String location = res.getHeader("Location");
if (location != null && !location.isEmpty()) {
log.info("飞书文件解析成功: token={}", token);
complete(location);
} else {
fail("飞书下载API返回{}但没有Location头", statusCode);
}
} else if (statusCode == 200) {
// 部分情况下API返回JSON格式的下载链接
try {
JsonObject json = asJson(res);
if (json.containsKey("code") && json.getInteger("code") == 0) {
String downloadUrl = json.getString("url");
if (downloadUrl != null && !downloadUrl.isEmpty()) {
log.info("飞书文件解析成功(JSON): token={}", token);
complete(downloadUrl);
return;
}
}
} catch (Exception ignored) {
}
// 如果返回200且不是JSON则API地址本身可能就是下载地址
complete(downloadApiUrl);
} else {
fail("飞书下载API返回非预期状态码: {}, body: {}", statusCode,
res.bodyAsString());
}
})
.onFailure(handleFail("请求飞书下载API"));
}
}

View File

@@ -0,0 +1,117 @@
"""
飞书云盘分享链接解析工具
支持格式:
文件: https://xxx.feishu.cn/file/TOKEN?from=from_copylink
文件夹: https://xxx.feishu.cn/drive/folder/TOKEN?from=from_copylink
?from=from_copylink 是可选参数,没有分享密码
用法: python feishu-dl.py <飞书分享链接>
"""
import requests
import sys
import re
def download_feishu_file(share_url):
"""
解析飞书云盘文件分享链接,获取直链下载地址
:param share_url: 飞书分享链接
:return: 下载直链 或 None
"""
# 提取域名和文件token
match = re.match(
r'https://([a-zA-Z\d]+)\.feishu\.cn/(file|drive/folder)/([a-zA-Z\d_-]+)',
share_url
)
if not match:
print(f"无法解析链接: {share_url}")
return None
tenant = match.group(1)
link_type = match.group(2)
token = match.group(3)
host = f"{tenant}.feishu.cn"
print(f"租户: {tenant}")
print(f"类型: {'文件' if link_type == 'file' else '文件夹'}")
print(f"Token: {token}")
if link_type == "drive/folder":
print("文件夹分享暂不支持直接下载")
return None
# 构建下载API URL
download_api_url = (
f"https://{host}/space/api/box/stream/download/all/{token}"
f"?mount_point=explorer"
)
headers = {
'User-Agent': (
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/120.0.0.0 Safari/537.36'
),
'Referer': f'https://{host}/',
}
print(f"\n请求下载API: {download_api_url}")
try:
response = requests.get(
download_api_url,
headers=headers,
allow_redirects=False,
timeout=30
)
if response.status_code in (301, 302):
download_url = response.headers.get('Location')
if download_url:
print(f"解析成功!")
print(f"下载链接: {download_url}")
return download_url
else:
print("重定向但没有Location头")
elif response.status_code == 200:
# 尝试解析JSON响应
try:
data = response.json()
if data.get('code') == 0 and data.get('url'):
print(f"解析成功(JSON)!")
print(f"下载链接: {data['url']}")
return data['url']
except ValueError:
pass
# 如果返回200且不是JSON, API地址本身可能就是下载地址
return download_api_url
else:
print(f"非预期状态码: {response.status_code}")
print(f"响应: {response.text[:500]}")
except Exception as e:
print(f"请求失败: {e}")
return None
def main():
if len(sys.argv) < 2:
print("=" * 60)
print(" 飞书云盘分享链接解析工具")
print("=" * 60)
print("\n用法: python feishu-dl.py <飞书分享链接>")
print("\n示例:")
print(" python feishu-dl.py "
"https://xxx.feishu.cn/file/TOKEN")
print(" python feishu-dl.py "
"https://xxx.feishu.cn/file/TOKEN?from=from_copylink")
sys.exit(1)
url = sys.argv[1]
download_feishu_file(url)
if __name__ == "__main__":
main()

View File

@@ -129,15 +129,130 @@ public class PanDomainTemplateTest {
wsPattern.matcher("https://www.evil.com/f/abc123").matches());
}
@Test
public void testLzPatternWebgetstore() {
Pattern lzPattern = PanDomainTemplate.LZ.getPattern();
// webgetstore.com 以前遗漏,现已补入
Matcher m1 = lzPattern.matcher("https://webgetstore.com/somekey");
assertTrue("LZ should match webgetstore.com", m1.find());
assertEquals("somekey", m1.group("KEY"));
Matcher m2 = lzPattern.matcher("https://www.webgetstore.com/somekey");
assertTrue("LZ should match www.webgetstore.com", m2.find());
assertEquals("somekey", m2.group("KEY"));
// t-is.cn 以前遗漏,现已补入
Matcher m3 = lzPattern.matcher("https://t-is.cn/somekey");
assertTrue("LZ should match t-is.cn", m3.find());
assertEquals("somekey", m3.group("KEY"));
Matcher m4 = lzPattern.matcher("https://www.t-is.cn/somekey");
assertTrue("LZ should match www.t-is.cn", m4.find());
assertEquals("somekey", m4.group("KEY"));
// 已有域名仍然正常匹配
Matcher m5 = lzPattern.matcher("https://www.lanzoul.com/somekey");
assertTrue("LZ should match existing domain lanzoul.com", m5.find());
assertEquals("somekey", m5.group("KEY"));
}
@Test
public void testLePatternFix() {
Pattern lePattern = PanDomainTemplate.LE.getPattern();
// lecloud.lenovo.com 应匹配
Matcher m1 = lePattern.matcher("https://lecloud.lenovo.com/share/abc123");
assertTrue("LE should match lecloud.lenovo.com", m1.find());
assertEquals("abc123", m1.group("KEY"));
// leclou.lenovo.com (去掉'd') 不应匹配(原 lecloud? 的 bug
assertFalse("LE should NOT match leclou.lenovo.com",
lePattern.matcher("https://leclou.lenovo.com/share/abc123").find());
}
@Test
public void testCowPatternFix() {
Pattern cowPattern = PanDomainTemplate.COW.getPattern();
// 正常域名
Matcher m1 = cowPattern.matcher("https://cowtransfer.com/s/abc123");
assertTrue("COW should match cowtransfer.com", m1.find());
assertEquals("abc123", m1.group("KEY"));
Matcher m2 = cowPattern.matcher("https://share.cowtransfer.com/s/abc123");
assertTrue("COW should match share.cowtransfer.com", m2.find());
assertEquals("abc123", m2.group("KEY"));
// 潜在的URL注入`(.*)` 是贪婪捕获组,可匹配 `evil.com/redirect/` 等前缀,
// 使形如 `https://evil.com/redirect/cowtransfer.com/s/key` 的 URL 被误识别。
// 修复后改为 `(?:[a-zA-Z\d-]+\.)?` 仅匹配一级合法子域名(可选),消除误匹配。
assertFalse("COW should NOT match redirect URLs containing cowtransfer.com in path",
cowPattern.matcher("https://evil.com/redirect/cowtransfer.com/s/abc").find());
}
@Test
public void testMnePatternFix() {
Pattern mnePattern = PanDomainTemplate.MNE.getPattern();
// 带 #/ 前缀的完整网页链接(修复前因 (y.) 未转义而存在 bug
Matcher m1 = mnePattern.matcher("https://music.163.com/#/song?id=12345");
assertTrue("MNE should match #/song format", m1.find());
assertEquals("12345", m1.group("KEY"));
// 带 m/ 前缀的移动端链接
Matcher m2 = mnePattern.matcher("https://music.163.com/m/song?id=12345");
assertTrue("MNE should match m/song format", m2.find());
assertEquals("12345", m2.group("KEY"));
// y.music.163.com 子域名
Matcher m3 = mnePattern.matcher("https://y.music.163.com/song?id=12345");
assertTrue("MNE should match y.music.163.com", m3.find());
assertEquals("12345", m3.group("KEY"));
// 原 (y.) 中 `.` 未转义(`.` 匹配任意字符):对于 `yXmusic.163.com`
// `(y.)` 会消费 `yX`y + 任意字符),剩余 `music.163.com` 再被 `music\.163\.com` 匹配,导致误匹配。
// 修复后 `(y\.)` 要求字面 `.``yX` 中 X ≠ `.` 无法匹配,不再误匹配。
assertFalse("MNE should NOT match yXmusic.163.com (old (y.) could erroneously match via backtracking)",
mnePattern.matcher("https://yXmusic.163.com/song?id=12345").find());
}
@Test
public void testP115PatternFix() {
Pattern p115Pattern = PanDomainTemplate.P115.getPattern();
// 正常匹配
Matcher m1 = p115Pattern.matcher("https://115.com/s/abc123");
assertTrue("P115 should match 115.com", m1.find());
assertEquals("abc123", m1.group("KEY"));
Matcher m2 = p115Pattern.matcher("https://anxia.com/s/abc123");
assertTrue("P115 should match anxia.com", m2.find());
assertEquals("abc123", m2.group("KEY"));
// 原 .com 未转义时 115Xcom 会被误匹配(现已修复)
assertFalse("P115 should NOT match 115Xcom",
p115Pattern.matcher("https://115Xcom/s/abc123").find());
}
@Test
public void testPgdSubdomain() {
Pattern pgdPattern = PanDomainTemplate.PGD.getPattern();
// 标准链接
Matcher m1 = pgdPattern.matcher("https://drive.google.com/file/d/abc123/view?usp=sharing");
assertTrue("PGD should match standard drive.google.com", m1.find());
assertEquals("abc123", m1.group("KEY"));
// 带子域名的链接(修复后支持)
Matcher m2 = pgdPattern.matcher("https://adsd.drive.google.com/file/d/151bR-nk-tOBm9QAFaozJIVt2WYyCMkoz/view");
assertTrue("PGD should match subdomain.drive.google.com", m2.find());
assertEquals("151bR-nk-tOBm9QAFaozJIVt2WYyCMkoz", m2.group("KEY"));
}
@Test
public void verifyDuplicates() {
Matcher matcher = compile("https://(?:[a-zA-Z\\d-]+\\.)?drive\\.google\\.com/file/d/(?<KEY>.+)/view(\\?usp=(sharing|drive_link))?")
.matcher("https://adsd.drive.google.com/file/d/151bR-nk-tOBm9QAFaozJIVt2WYyCMkoz/view");
if (matcher.find()) {
System.out.println(matcher.group());
System.out.println(matcher.group("KEY"));
}
// 校验重复
Set<String> collect =
Arrays.stream(PanDomainTemplate.values()).map(PanDomainTemplate::getRegex).collect(Collectors.toSet());

View File

@@ -0,0 +1,135 @@
package cn.qaiu.parser.impl;
import cn.qaiu.entity.ShareLinkInfo;
import cn.qaiu.parser.PanDomainTemplate;
import cn.qaiu.parser.ParserCreate;
import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.junit.Assert.*;
/**
* 飞书云盘解析测试
*/
public class FsToolTest {
@Test
public void testFsPatternMatchFile() {
Pattern fsPattern = PanDomainTemplate.FS.getPattern();
// 文件链接 (带 ?from=from_copylink)
Matcher m1 = fsPattern.matcher(
"https://kcncuknojm60.feishu.cn/file/VnCxbt35KoowKoxldO3c3C7VnMc?from=from_copylink");
assertTrue("FS pattern should match file URL with query params", m1.matches());
assertEquals("VnCxbt35KoowKoxldO3c3C7VnMc", m1.group("KEY"));
// 文件链接 (不带查询参数)
Matcher m2 = fsPattern.matcher(
"https://kcncuknojm60.feishu.cn/file/VnCxbt35KoowKoxldO3c3C7VnMc");
assertTrue("FS pattern should match file URL without query params", m2.matches());
assertEquals("VnCxbt35KoowKoxldO3c3C7VnMc", m2.group("KEY"));
}
@Test
public void testFsPatternMatchFolder() {
Pattern fsPattern = PanDomainTemplate.FS.getPattern();
// 文件夹链接 (带 ?from=from_copylink)
Matcher m1 = fsPattern.matcher(
"https://kcncuknojm60.feishu.cn/drive/folder/RQSKf8EQ4l7dMedqzHucpMbancg?from=from_copylink");
assertTrue("FS pattern should match folder URL with query params", m1.matches());
assertEquals("RQSKf8EQ4l7dMedqzHucpMbancg", m1.group("KEY"));
// 文件夹链接 (不带查询参数)
Matcher m2 = fsPattern.matcher(
"https://kcncuknojm60.feishu.cn/drive/folder/RQSKf8EQ4l7dMedqzHucpMbancg");
assertTrue("FS pattern should match folder URL without query params", m2.matches());
assertEquals("RQSKf8EQ4l7dMedqzHucpMbancg", m2.group("KEY"));
}
@Test
public void testFsPatternDifferentSubdomains() {
Pattern fsPattern = PanDomainTemplate.FS.getPattern();
// 不同的租户子域名
String[] subdomains = {"abc123", "kcncuknojm60", "tenant01", "xyz"};
for (String subdomain : subdomains) {
String url = "https://" + subdomain + ".feishu.cn/file/TestToken123";
Matcher m = fsPattern.matcher(url);
assertTrue("FS pattern should match subdomain: " + subdomain, m.matches());
assertEquals("TestToken123", m.group("KEY"));
}
}
@Test
public void testFsPatternNegativeCases() {
Pattern fsPattern = PanDomainTemplate.FS.getPattern();
// 不匹配: 非feishu.cn域名
assertFalse("Should not match non-feishu domain",
fsPattern.matcher("https://evil.com/file/TOKEN").matches());
// 不匹配: 其他路径
assertFalse("Should not match other paths",
fsPattern.matcher("https://abc.feishu.cn/docs/TOKEN").matches());
// 不匹配: 没有子域名的feishu.cn
assertFalse("Should not match feishu.cn without subdomain",
fsPattern.matcher("https://feishu.cn/file/TOKEN").matches());
}
@Test
public void testFromShareUrlFile() {
String fileUrl = "https://kcncuknojm60.feishu.cn/file/VnCxbt35KoowKoxldO3c3C7VnMc?from=from_copylink";
ParserCreate parserCreate = ParserCreate.fromShareUrl(fileUrl);
ShareLinkInfo info = parserCreate.getShareLinkInfo();
assertNotNull("ShareLinkInfo should not be null", info);
assertEquals("Type should be fs", "fs", info.getType());
assertEquals("Pan name should be 飞书云盘", "飞书云盘", info.getPanName());
assertEquals("Share key should be the token",
"VnCxbt35KoowKoxldO3c3C7VnMc", info.getShareKey());
}
@Test
public void testFromShareUrlFolder() {
String folderUrl = "https://kcncuknojm60.feishu.cn/drive/folder/RQSKf8EQ4l7dMedqzHucpMbancg?from=from_copylink";
ParserCreate parserCreate = ParserCreate.fromShareUrl(folderUrl);
ShareLinkInfo info = parserCreate.getShareLinkInfo();
assertNotNull("ShareLinkInfo should not be null", info);
assertEquals("Type should be fs", "fs", info.getType());
assertEquals("Pan name should be 飞书云盘", "飞书云盘", info.getPanName());
assertEquals("Share key should be the token",
"RQSKf8EQ4l7dMedqzHucpMbancg", info.getShareKey());
}
@Test
public void testFromType() {
ParserCreate parserCreate = ParserCreate.fromType("fs")
.shareKey("VnCxbt35KoowKoxldO3c3C7VnMc");
ShareLinkInfo info = parserCreate.getShareLinkInfo();
assertNotNull("ShareLinkInfo should not be null", info);
assertEquals("Type should be fs", "fs", info.getType());
assertEquals("Pan name should be 飞书云盘", "飞书云盘", info.getPanName());
assertEquals("Share key should match", "VnCxbt35KoowKoxldO3c3C7VnMc", info.getShareKey());
}
@Test
public void testFromShareUrlFileWithoutQueryParams() {
String fileUrl = "https://kcncuknojm60.feishu.cn/file/VnCxbt35KoowKoxldO3c3C7VnMc";
ParserCreate parserCreate = ParserCreate.fromShareUrl(fileUrl);
ShareLinkInfo info = parserCreate.getShareLinkInfo();
assertNotNull("ShareLinkInfo should not be null", info);
assertEquals("fs", info.getType());
assertEquals("VnCxbt35KoowKoxldO3c3C7VnMc", info.getShareKey());
}
}