1. 添加缓存

2. 优化解析架构
3. 优化核心模块
This commit is contained in:
qaiu
2024-09-15 06:53:11 +08:00
parent 5fce02e623
commit f886f7e366
40 changed files with 1056 additions and 409 deletions

View File

@@ -0,0 +1,37 @@
package cn.qaiu.parser;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FCURLParser {// 定义前缀
public static final String SHARE_URL_PREFIX0 = "https://v2.fangcloud.com/s";
public static final String SHARE_URL_PREFIX = "https://v2.fangcloud.com/sharing/";
public static final String SHARE_URL_PREFIX2 = "https://v2.fangcloud.cn/sharing/";
// 定义正则表达式,适用于所有前缀
private static final String SHARING_REGEX = "https://www\\.ecpan\\.cn/web(/%23|/#)?/yunpanProxy\\?path=.*&data=" +
"([^&]+)&isShare=1";
public static void main(String[] args) {
// 测试 URL
String[] urls = {
"https://www.ecpan.cn/web/#/yunpanProxy?path=%2F%23%2Fdrive%2Foutside&data=4b3d786755688b85c6eb0c04b9124f4dalzdaJpXHx&isShare=1",
"https://www.ecpan.cn/web/yunpanProxy?path=%2F%23%2Fdrive%2Foutside&data=4b3d786755688b85c6eb0c04b9124f4dalzdaJpXHx&isShare=1",
"https://v2.fangcloud.cn/sharing/xyz789"
};
// 编译正则表达式
Pattern pattern = Pattern.compile(SHARING_REGEX);
for (String url : urls) {
Matcher matcher = pattern.matcher(url);
if (matcher.find()) {
System.out.println(matcher.groupCount());
String shareKey = matcher.group(matcher.groupCount()); // 捕捉组 3
System.out.println("Captured part: " + shareKey);
} else {
System.out.println("No match found.");
}
}
}
}

View File

@@ -0,0 +1,73 @@
package cn.qaiu.parser;
import cn.qaiu.entity.ShareLinkInfo;
import org.junit.Test;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author <a href="https://qaiu.top">QAIU</a>
* @date 2024/8/8 2:39
*/
public class PanDomainTemplateTest {
@Test
public void normalizeShareLink() {
// 准备测试数据
String testShareUrl = "https://test.lanzoux.com/s/someShareKey";
PanDomainTemplate template = PanDomainTemplate.fromShareUrl(testShareUrl); // 假设使用LZ网盘模板
// 调用normalizeShareLink方法
ShareLinkInfo result = template.getShareLinkInfo();
System.out.println(result);
// 断言结果是否符合预期
assertNotNull("Result should not be null", result);
assertEquals("Share key should match", "someShareKey", result.getShareKey());
assertEquals("Standard URL should be generated correctly", template.getStandardUrlTemplate().replace("{shareKey}", "someShareKey"), result.getStandardUrl());
// 可以添加更多的断言来验证其他字段
}
@Test
public void fromShareUrl() throws InterruptedException {
// 准备测试数据
String lzUrl = "https://wwn.lanzouy.com/ihLkw1gezutg";
String cowUrl = "https://cowtransfer.com/s/9a644fe3e3a748";
String ceUrl = "https://pan.huang1111.cn/s/g31PcQ";
String wsUrl = "https://f.ws59.cn/f/f25625rv6p6";
PanDomainTemplate.fromShareUrl(wsUrl).createTool()
.parse().onSuccess(System.out::println);
PanDomainTemplate.fromShareUrl(lzUrl).createTool()
.parse().onSuccess(System.out::println);
PanDomainTemplate.fromShareUrl(cowUrl).createTool()
.parse().onSuccess(System.out::println);
PanDomainTemplate.fromShareUrl(lzUrl).createTool()
.parse().onSuccess(System.out::println);
// PanDomainTemplate.fromShortName("lz").generateShareLink("ihLkw1gezutg")
// .createTool().parse().onSuccess(System.out::println);
// PanDomainTemplate.LZ.generateShareLink("ihLkw1gezutg")
// .createTool().parse().onSuccess(System.out::println);
// 调用fromShareUrl方法
// PanDomainTemplate resultTemplate = PanDomainTemplate.fromShareUrl(testShareUrl);
// System.out.println(resultTemplate.normalizeShareLink(testShareUrl));
// System.out.println(resultTemplate.generateShareLink("xxx"));
// System.out.println(resultTemplate.createTool("xxx",null).parse()
// .onSuccess(System.out::println));
// System.out.println(resultTemplate.getDisplayName());
// System.out.println(resultTemplate.getStandardUrlTemplate());
// System.out.println(resultTemplate.getRegexPattern());
//
// // 断言结果是否符合预期
// assertNotNull("Result should not be null", resultTemplate);
// assertEquals("Should return the correct template", PanDomainTemplate.LZ, resultTemplate);
// // 可以添加更多的断言来验证正则表达式匹配逻辑
// new Scanner(System.in).nextLine();
TimeUnit.SECONDS.sleep(5);
}
}