mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2025-12-16 04:13:03 +00:00
Compare commits
430 Commits
0.1.5-rele
...
v0.1.9b9l
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6647fc5371 | ||
|
|
b67544f0cd | ||
|
|
ef5826a73b | ||
|
|
a48adbd0df | ||
|
|
5c60493a24 | ||
|
|
55e6227de0 | ||
|
|
24a7395004 | ||
|
|
b2a7187fc5 | ||
|
|
ace7cdc88e | ||
|
|
2e909b5868 | ||
|
|
de78bcbc98 | ||
|
|
c560f0e902 | ||
|
|
88860c9302 | ||
|
|
ef65d0e095 | ||
|
|
6438505f4a | ||
|
|
1be5030dd1 | ||
|
|
421b2f4a42 | ||
|
|
a66bf84381 | ||
|
|
0c4d366d6d | ||
|
|
a1d0a921fa | ||
|
|
2092230a61 | ||
|
|
6e5ae6eff3 | ||
|
|
4f8259d772 | ||
|
|
8b987d9824 | ||
|
|
e8ba451d18 | ||
|
|
77758db463 | ||
|
|
6c58598a8e | ||
|
|
3ac35230a3 | ||
|
|
ca91302d28 | ||
|
|
e07272a5dc | ||
|
|
461305e1df | ||
|
|
8e8ab10a0f | ||
|
|
e754326925 | ||
|
|
4c92994c6f | ||
|
|
66c57f47ac | ||
|
|
ec689eadd8 | ||
|
|
c1e15709a7 | ||
|
|
2848937ce7 | ||
|
|
42ff0c21b2 | ||
|
|
3ed7e547e6 | ||
|
|
fad8e688df | ||
|
|
b2f2dcac4c | ||
|
|
fcba78e977 | ||
|
|
77c9d777a1 | ||
|
|
4460659210 | ||
|
|
8631524107 | ||
|
|
0579588814 | ||
|
|
df2bfb6ac7 | ||
|
|
517b6f8910 | ||
|
|
94a46d2833 | ||
|
|
1631a0faa1 | ||
|
|
06d5943cb6 | ||
|
|
3095e13676 | ||
|
|
482cbce7e8 | ||
|
|
ef2fc3ab98 | ||
|
|
5b57b05eae | ||
|
|
093579c6f5 | ||
|
|
c2d4990d7f | ||
|
|
40e8380738 | ||
|
|
b716e1e861 | ||
|
|
8432d4952c | ||
|
|
dd8f085f63 | ||
|
|
161ff8d8a3 | ||
|
|
1390cd0104 | ||
|
|
7a02b1e97f | ||
|
|
036f107c90 | ||
|
|
5652383450 | ||
|
|
9a047a5da0 | ||
|
|
8975743a37 | ||
|
|
0e30eafe49 | ||
|
|
7facb62f21 | ||
|
|
30d43cb961 | ||
|
|
c505b17e35 | ||
|
|
080c4c753d | ||
|
|
ade0d34d91 | ||
|
|
56d082eb0b | ||
|
|
795c4529ba | ||
|
|
0f5cfe22ea | ||
|
|
925ad2c3a5 | ||
|
|
f3e96907fe | ||
|
|
75a1e58a7d | ||
|
|
379e889f71 | ||
|
|
40c06f397b | ||
|
|
9e9302436e | ||
|
|
6d816d4193 | ||
|
|
438eda9c08 | ||
|
|
ace39e4633 | ||
|
|
7712391f29 | ||
|
|
65f08dcb02 | ||
|
|
1d332aa6f4 | ||
|
|
ba81641517 | ||
|
|
fb30bdb879 | ||
|
|
fc451d3b41 | ||
|
|
ffee1f3462 | ||
|
|
f30027dd13 | ||
|
|
8b6aad17f4 | ||
|
|
b77930adfb | ||
|
|
aff8f88076 | ||
|
|
4e6582e24c | ||
|
|
fa9acaccfd | ||
|
|
0414f85f12 | ||
|
|
527dd0eeb4 | ||
|
|
74ed7475c9 | ||
|
|
54dc3dba96 | ||
|
|
9980159090 | ||
|
|
0b193ebb00 | ||
|
|
f5fc9843b2 | ||
|
|
df1f67dd26 | ||
|
|
b069a5f576 | ||
|
|
7686763a03 | ||
|
|
635a6eac37 | ||
|
|
877edc535f | ||
|
|
01d59e3c1e | ||
|
|
fece2799e3 | ||
|
|
de9756ee86 | ||
|
|
51f047a51b | ||
|
|
04b66e82b7 | ||
|
|
df89253647 | ||
|
|
45dbca794e | ||
|
|
857bf28f99 | ||
|
|
e07ce15228 | ||
|
|
0637bcfd8e | ||
|
|
23db0563ac | ||
|
|
ccba71aa4e | ||
|
|
fee4bf2ad6 | ||
|
|
5052fea9ef | ||
|
|
e85215fca1 | ||
|
|
e42fe45329 | ||
|
|
4240815bd1 | ||
|
|
6f0c5305e2 | ||
|
|
757005cad8 | ||
|
|
81651ad97c | ||
|
|
f3763b6058 | ||
|
|
82478dc485 | ||
|
|
703fd05d43 | ||
|
|
ff868b6e2a | ||
|
|
051a74b37b | ||
|
|
a0a1085623 | ||
|
|
2612d3919c | ||
|
|
6f123a236f | ||
|
|
71e57e6a08 | ||
|
|
7cb18d8186 | ||
|
|
cdbf670ece | ||
|
|
e0dafee617 | ||
|
|
c37bce1563 | ||
|
|
0b3c77d644 | ||
|
|
2cf85caf86 | ||
|
|
594010ba88 | ||
|
|
d91460d2e2 | ||
|
|
89713e6ac9 | ||
|
|
17c9b2538c | ||
|
|
d337b003cb | ||
|
|
8f1485656b | ||
|
|
f0c4ec3031 | ||
|
|
458be84aca | ||
|
|
c7716aad34 | ||
|
|
4a3e734408 | ||
|
|
54cc212753 | ||
|
|
f4ae1eaa51 | ||
|
|
d2537282c9 | ||
|
|
87527688c3 | ||
|
|
2be0b6505a | ||
|
|
672f100c7c | ||
|
|
5af402c0c5 | ||
|
|
693a4f0f63 | ||
|
|
f8d2426ff6 | ||
|
|
973a9bedcd | ||
|
|
a583733400 | ||
|
|
78eb51b3ca | ||
|
|
a2606be9d8 | ||
|
|
a4975c72ce | ||
|
|
58f96822a4 | ||
|
|
96b0d94986 | ||
|
|
70b38db8c5 | ||
|
|
b6a9c2d3a0 | ||
|
|
a01df6c7db | ||
|
|
4455bee570 | ||
|
|
cd0adef2ed | ||
|
|
4aa24a65fb | ||
|
|
760dca8772 | ||
|
|
8269673619 | ||
|
|
82ec586554 | ||
|
|
ca98cc8708 | ||
|
|
f07800985d | ||
|
|
b042df93b7 | ||
|
|
ecf4441946 | ||
|
|
39b2612840 | ||
|
|
218f486e6b | ||
|
|
cfcc25f175 | ||
|
|
155e88223c | ||
|
|
05039ece51 | ||
|
|
1c673f2b46 | ||
|
|
2232a70228 | ||
|
|
e661b1d817 | ||
|
|
5a6a65f580 | ||
|
|
5cdd3bcd30 | ||
|
|
1233a885b8 | ||
|
|
adf56cd768 | ||
|
|
cd4b208be9 | ||
|
|
502de1a5d0 | ||
|
|
4158f869a3 | ||
|
|
ff569d339c | ||
|
|
10eec323dd | ||
|
|
0a3db51c7d | ||
|
|
229aee0b30 | ||
|
|
44714aa981 | ||
|
|
2b6138a889 | ||
|
|
5e424f7bf4 | ||
|
|
294e47deed | ||
|
|
dc42547b73 | ||
|
|
7ef7f0706b | ||
|
|
a59b98a7c9 | ||
|
|
088fee9a4d | ||
|
|
d8666acfe8 | ||
|
|
209e9c2866 | ||
|
|
6c3195dea4 | ||
|
|
7d774a7433 | ||
|
|
f1ec4433cf | ||
|
|
1f825db261 | ||
|
|
1019f24f1d | ||
|
|
f5c5b99579 | ||
|
|
e002d19f1b | ||
|
|
0d5c9651f0 | ||
|
|
53fc13b95c | ||
|
|
694c3b0ddc | ||
|
|
9b3d4577cc | ||
|
|
77783915dd | ||
|
|
b67ac21a79 | ||
|
|
603afed2f2 | ||
|
|
c2a7c34496 | ||
|
|
edd40f48ba | ||
|
|
cca3d6b8b9 | ||
|
|
f004512903 | ||
|
|
6407bb6730 | ||
|
|
b914eeadec | ||
|
|
dcadc6783e | ||
|
|
bc9f43634f | ||
|
|
4778f0164c | ||
|
|
9904754a07 | ||
|
|
1b79077c9e | ||
|
|
c13afb05b3 | ||
|
|
03e320efb8 | ||
|
|
7846332476 | ||
|
|
2d5d3b86e0 | ||
|
|
7c9ba890af | ||
|
|
0d609daffa | ||
|
|
c12e56d402 | ||
|
|
c7b38c07d5 | ||
|
|
dc51066cea | ||
|
|
59d2fb3010 | ||
|
|
a0fe702c10 | ||
|
|
f886f7e366 | ||
|
|
1d475d88ed | ||
|
|
e64c901912 | ||
|
|
5fce02e623 | ||
|
|
13997bc543 | ||
|
|
3e05b0d6f9 | ||
|
|
966417f867 | ||
|
|
601a0d1b91 | ||
|
|
ae91ce773e | ||
|
|
d428380f79 | ||
|
|
b0b8b61688 | ||
|
|
7663320a55 | ||
|
|
aaae7ab9a6 | ||
|
|
db7aa2f442 | ||
|
|
d7349cbf05 | ||
|
|
3a5474c9d8 | ||
|
|
4e6ed0f936 | ||
|
|
11ae57856e | ||
|
|
66e67f3e1d | ||
|
|
8913221b97 | ||
|
|
4f4133b98c | ||
|
|
5768ba48e8 | ||
|
|
9780d09e28 | ||
|
|
8358d8d1f8 | ||
|
|
d2a7bf4417 | ||
|
|
24c5495e75 | ||
|
|
4158200ba5 | ||
|
|
2a75f9d34d | ||
|
|
441e69e5f8 | ||
|
|
0a3d91ee52 | ||
|
|
00b3af1c4c | ||
|
|
6d4e0fb56e | ||
|
|
0a296cc937 | ||
|
|
257063bae3 | ||
|
|
e21325a5d0 | ||
|
|
32284c6da0 | ||
|
|
56c68bcce6 | ||
|
|
2ef7efdc42 | ||
|
|
7f00413756 | ||
|
|
d26696d3fa | ||
|
|
595f301748 | ||
|
|
c33b0aa12c | ||
|
|
b21189b7d7 | ||
|
|
618f43da8e | ||
|
|
d28b54f694 | ||
|
|
093d651f2f | ||
|
|
ccc05c13b2 | ||
|
|
1dfcbcc132 | ||
|
|
e9770c8eb3 | ||
|
|
cb14be12e1 | ||
|
|
b0ca6aa4dd | ||
|
|
c958229960 | ||
|
|
8aa10f6f27 | ||
|
|
db073beeb5 | ||
|
|
3d46bcb5c8 | ||
|
|
66e62aead0 | ||
|
|
497a96a1df | ||
|
|
c6e0bed331 | ||
|
|
d678a5f4f0 | ||
|
|
8fcf3d225d | ||
|
|
4858461946 | ||
|
|
7afe52918b | ||
|
|
1a0064fc43 | ||
|
|
7216c84282 | ||
|
|
94a58e2174 | ||
|
|
aa2fae868c | ||
|
|
1b80f49079 | ||
|
|
135632309d | ||
|
|
4c366b7d84 | ||
|
|
e3efdc83e6 | ||
|
|
595575381b | ||
|
|
5cd1ef8bbf | ||
|
|
1aeb838fd9 | ||
|
|
ce414e80b0 | ||
|
|
c47c9bfc68 | ||
|
|
7b2c493cf7 | ||
|
|
b38291b6b2 | ||
|
|
66de667fc3 | ||
|
|
a1e9be0133 | ||
|
|
bf70a7c83d | ||
|
|
6706380558 | ||
|
|
b0d150319d | ||
|
|
03185d0592 | ||
|
|
46f092f2ed | ||
|
|
aea97caed1 | ||
|
|
6d3335d086 | ||
|
|
945e5a74e6 | ||
|
|
1f38201555 | ||
|
|
cfc5afc029 | ||
|
|
0526569d64 | ||
|
|
1c94f4ef8b | ||
|
|
26aabf19db | ||
|
|
2e14d8d345 | ||
|
|
09140d56a3 | ||
|
|
1eec14831c | ||
|
|
aafbf05d34 | ||
|
|
8ffd35f2f0 | ||
|
|
6808381292 | ||
|
|
72cc68e9ad | ||
|
|
7917870c6b | ||
|
|
facf9b645e | ||
|
|
46b4c524f0 | ||
|
|
804c6d96ec | ||
|
|
91c3b0c612 | ||
|
|
400952e33b | ||
|
|
c39f748a51 | ||
|
|
2464693288 | ||
|
|
cfce8c1aef | ||
|
|
258a7cb1cc | ||
|
|
049cfa3676 | ||
|
|
7591aa4336 | ||
|
|
2aef15c670 | ||
|
|
23f29be4b3 | ||
|
|
daea6bea68 | ||
|
|
a71028c665 | ||
|
|
afb997f516 | ||
|
|
940d73a132 | ||
|
|
214eaed56a | ||
|
|
3dab818dcb | ||
|
|
61db1af83d | ||
|
|
7d1cb5b5c1 | ||
|
|
878f61d349 | ||
|
|
9a1c9d8ba2 | ||
|
|
ffd4846924 | ||
|
|
3e1f29c12e | ||
|
|
ec9a6dfe6c | ||
|
|
a72ebbb83c | ||
|
|
a8a172c027 | ||
|
|
bcd71a844c | ||
|
|
3608eb0370 | ||
|
|
dbef574cbc | ||
|
|
e2273587a0 | ||
|
|
9f50299943 | ||
|
|
a51097e1ba | ||
|
|
5628d57299 | ||
|
|
774a069c0e | ||
|
|
5756fde338 | ||
|
|
5d6e22405a | ||
|
|
28497e900a | ||
|
|
00723cc2e2 | ||
|
|
91eb62d308 | ||
|
|
c73e614ce7 | ||
|
|
2586092760 | ||
|
|
0d5b771db8 | ||
|
|
67edd5b5d8 | ||
|
|
40eea9b5f4 | ||
|
|
29a993e1fc | ||
|
|
2c9f0d8e83 | ||
|
|
656a43e4b7 | ||
|
|
f0e28e1c37 | ||
|
|
7e5400d43c | ||
|
|
c7c932daf4 | ||
|
|
8ca0eca2ea | ||
|
|
bb925eba35 | ||
|
|
a105a7d864 | ||
|
|
60e4ac6094 | ||
|
|
8d80ff845a | ||
|
|
49c2bbe680 | ||
|
|
3017e8d17c | ||
|
|
f3ae2b79b8 | ||
|
|
c629525029 | ||
|
|
5d9b18ef41 | ||
|
|
bdee797f7e | ||
|
|
a052bcd841 | ||
|
|
616cc9ce6a | ||
|
|
f124c83286 | ||
|
|
d11fcfb282 | ||
|
|
5ec1ec7789 | ||
|
|
8b6075af37 | ||
|
|
5d23c57d0e | ||
|
|
409163ddf5 | ||
|
|
994202587d | ||
|
|
c01d41f9ca | ||
|
|
c42667fe3b | ||
|
|
c782d495ea | ||
|
|
3f4f9fa76b | ||
|
|
635c639bf5 | ||
|
|
a49b9254a4 | ||
|
|
0c91eea711 |
28
.devcontainer/devcontainer.json
Normal file
28
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,28 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/java
|
||||
{
|
||||
"name": "Java",
|
||||
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
||||
"image": "mcr.microsoft.com/devcontainers/java:0-17",
|
||||
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/java:1": {
|
||||
"version": "none",
|
||||
"installMaven": "true",
|
||||
"installGradle": "false"
|
||||
},
|
||||
"ghcr.io/devcontainers-contrib/features/ant-sdkman:2": {}
|
||||
}
|
||||
|
||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||
// "forwardPorts": [],
|
||||
|
||||
// Use 'postCreateCommand' to run commands after the container is created.
|
||||
// "postCreateCommand": "java -version",
|
||||
|
||||
// Configure tool-specific properties.
|
||||
// "customizations": {},
|
||||
|
||||
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||
// "remoteUser": "root"
|
||||
}
|
||||
8
.gitattributes
vendored
Normal file
8
.gitattributes
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# 文本文件使用 LF 换行符,适用于 Linux 和 macOS
|
||||
*.sh text eol=lf
|
||||
*.service text eol=lf
|
||||
|
||||
# Windows 执行的文件使用 CRLF 换行符
|
||||
*.bat text eol=crlf
|
||||
*.cmd text eol=crlf
|
||||
bin/nfd-service-template.xml text eol=crlf
|
||||
15
.github/FUNDING.yml
vendored
Normal file
15
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
polar: # Replace with a single Polar username
|
||||
buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
|
||||
thanks_dev: # Replace with a single thanks.dev username
|
||||
custom: https://blog.qaiu.top/archives/da-shang-zhuan-yong # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
62
.github/workflows/maven.yml
vendored
62
.github/workflows/maven.yml
vendored
@@ -11,12 +11,25 @@ name: Java CI with Maven
|
||||
# The API requires write permission on the repository to submit dependencies
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
tags:
|
||||
- '*' # 只有推送tag时才会触发构建
|
||||
branches-ignore:
|
||||
- '*' # 排除所有分支的提交
|
||||
paths-ignore:
|
||||
- 'bin/**'
|
||||
- '.github/**'
|
||||
- '.mvn/**'
|
||||
- '.run/**'
|
||||
- '.vscode/**'
|
||||
- '*.txt'
|
||||
- '*.md'
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
branches:
|
||||
- "main"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -25,19 +38,64 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '18'
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
cache: maven
|
||||
|
||||
- name: Build Frontend
|
||||
run: cd web-front && yarn install && yarn run build
|
||||
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
|
||||
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
|
||||
- name: Update dependency graph
|
||||
uses: advanced-security/maven-dependency-submission-action@v3
|
||||
if: github.event_name != 'pull_request'
|
||||
with:
|
||||
ignore-maven-wrapper: true
|
||||
|
||||
# - uses: release-drafter/release-drafter@v5
|
||||
# env:
|
||||
# GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
|
||||
- name: Upload Artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
path: web-service/target/netdisk-fast-download-bin.zip
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Extract git tag
|
||||
id: tag
|
||||
run: |
|
||||
GIT_TAG=$(git tag --points-at HEAD | head -n 1)
|
||||
echo "tag=$GIT_TAG" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build and push Docker image
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
tags: |
|
||||
ghcr.io/qaiu/netdisk-fast-download:${{ steps.tag.outputs.tag }}
|
||||
ghcr.io/qaiu/netdisk-fast-download:latest
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -38,3 +38,5 @@ gradlew
|
||||
gradlew.bat
|
||||
unused.txt
|
||||
/web-service/src/main/generated/
|
||||
/db
|
||||
/webroot/nfd-front/
|
||||
|
||||
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
117
.mvn/wrapper/MavenWrapperDownloader.java
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2007-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if(mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if(mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if(!outputFile.getParentFile().exists()) {
|
||||
if(!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
|
||||
}
|
||||
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
2
.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
|
||||
15
.run/AppMain.run.xml
Normal file
15
.run/AppMain.run.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="AppMain" type="Application" factoryName="Application" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="cn.qaiu.lz.AppMain" />
|
||||
<module name="web-service" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="cn.qaiu.lz.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
70
.vscode/launch.json
vendored
Normal file
70
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
{
|
||||
// 使用 IntelliSense 了解相关属性。
|
||||
// 悬停以查看现有属性的描述。
|
||||
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "java",
|
||||
"name": "Current File",
|
||||
"request": "launch",
|
||||
"mainClass": "${file}"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "StringCase",
|
||||
"request": "launch",
|
||||
"mainClass": "cn.qaiu.vx.core.util.StringCase",
|
||||
"projectName": "core"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "FCURLParser",
|
||||
"request": "launch",
|
||||
"mainClass": "cn.qaiu.parser.FCURLParser",
|
||||
"projectName": "parser"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "QkTool",
|
||||
"request": "launch",
|
||||
"mainClass": "cn.qaiu.parser.impl.QkTool",
|
||||
"projectName": "parser"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "WebClientExample",
|
||||
"request": "launch",
|
||||
"mainClass": "qaiu.web.test.WebClientExample",
|
||||
"projectName": "parser"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "AppMain",
|
||||
"request": "launch",
|
||||
"mainClass": "cn.qaiu.lz.AppMain",
|
||||
"projectName": "web-service"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "TestJs",
|
||||
"request": "launch",
|
||||
"mainClass": "cn.qaiu.web.test.TestJs",
|
||||
"projectName": "web-service"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "TestOS",
|
||||
"request": "launch",
|
||||
"mainClass": "cn.qaiu.web.test.TestOS",
|
||||
"projectName": "web-service"
|
||||
},
|
||||
{
|
||||
"type": "java",
|
||||
"name": "WebProxyExamples",
|
||||
"request": "launch",
|
||||
"mainClass": "cn.qaiu.web.test.WebProxyExamples",
|
||||
"projectName": "web-service"
|
||||
}
|
||||
]
|
||||
}
|
||||
4
.vscode/settings.json
vendored
Normal file
4
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"java.compile.nullAnalysis.mode": "automatic",
|
||||
"java.configuration.updateBuildConfiguration": "interactive"
|
||||
}
|
||||
17
Dockerfile
Normal file
17
Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
||||
FROM eclipse-temurin:17-jre
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 安装 unzip
|
||||
RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY ./web-service/target/netdisk-fast-download-bin.zip .
|
||||
|
||||
RUN unzip netdisk-fast-download-bin.zip && \
|
||||
mv netdisk-fast-download/* ./ && \
|
||||
rm netdisk-fast-download-bin.zip && \
|
||||
chmod +x run.sh
|
||||
|
||||
EXPOSE 6400 6401
|
||||
|
||||
ENTRYPOINT ["sh", "run.sh"]
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023 qaiu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
454
README.md
454
README.md
@@ -1,73 +1,429 @@
|
||||
# netdisk-fast-download
|
||||
# 网盘快速下载器--直链解析
|
||||
[](https://github.com/qaiu/netdisk-fast-download/actions/workflows/maven.yml)
|
||||
## 网盘支持情况:
|
||||
` 网盘名称(网盘标识): `
|
||||
- 蓝奏云 (lz)
|
||||
- [ ] 登录, 上传, 下载, 分享
|
||||
- [x] 直链解析
|
||||
- 奶牛快传 (cow)
|
||||
- [ ] 登录, 上传, 下载, 分享
|
||||
- [x] 直链解析
|
||||
- 移动云空间 (ec)
|
||||
- [ ] 登录, 上传, 下载, 分享
|
||||
- [x] 直链解析
|
||||
- UC网盘 (uc)
|
||||
- [ ] 登录, 上传, 下载, 分享
|
||||
- [x] 直链解析
|
||||
- 夸克网盘 (qk)
|
||||
- TODO
|
||||
<p align="center">
|
||||
<img src="https://github.com/user-attachments/assets/87401aae-b0b6-4ffb-bbeb-44756404d26f" alt="项目预览图" />
|
||||
</p>
|
||||
|
||||
技术栈:
|
||||
Jdk17+Vert.x4.4.1+Jsoup
|
||||
Core模块集成Vert.x实现类spring的注解式路由API
|
||||
<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.6-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>
|
||||
|
||||
API接口
|
||||
|
||||
|
||||
|
||||
# netdisk-fast-download 网盘分享链接云解析服务
|
||||
QQ群:1017480890
|
||||
|
||||
netdisk-fast-download网盘直链云解析(nfd云解析)能把网盘分享下载链接转化为直链,支持多款云盘,已支持蓝奏云/蓝奏云优享/奶牛快传/移动云云空间/小飞机盘/亿方云/123云盘/Cloudreve等,支持加密分享,以及部分网盘文件夹分享。
|
||||
|
||||
## 快速开始
|
||||
命令行下载分享文件:
|
||||
```shell
|
||||
(括号内表示可选内容)
|
||||
1. 解析并自动302跳转 :
|
||||
http(s)://you_host/parser?url=分享链接
|
||||
http(s)://you_host/网盘标识/分享id(#分享密码)
|
||||
curl -LOJ "https://lz.qaiu.top/parser?url=https://share.feijipan.com/s/nQOaNRPW&pwd=1234"
|
||||
```
|
||||
或者使用wget:
|
||||
```shell
|
||||
wget -O bilibili.mp4 "https://lz.qaiu.top/parser?url=https://share.feijipan.com/s/nQOaNRPW&pwd=1234"
|
||||
```
|
||||
或者使用浏览器[直接访问](https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.top%2Fparser%3Furl%3Dhttps%3A%2F%2Fshare.feijipan.com%2Fs%2FnQOaNRPW&name=bilibili.mp4&ext=mp4):
|
||||
```
|
||||
### 调用演示站下载:
|
||||
https://lz.qaiu.top/parser?url=https://share.feijipan.com/s/nQOaNRPW&pwd=1234
|
||||
### 调用演示站预览:
|
||||
https://nfd-parser.github.io/nfd-preview/preview.html?src=https%3A%2F%2Flz.qaiu.top%2Fparser%3Furl%3Dhttps%3A%2F%2Fshare.feijipan.com%2Fs%2FnQOaNRPW&name=bilibili.mp4&ext=mp4
|
||||
|
||||
```
|
||||
|
||||
## 预览地址
|
||||
[预览地址1](https://lz.qaiu.top)
|
||||
[预览地址2](http://www.722shop.top:6401)
|
||||
[天翼云盘大文件解析限时开放](https://189.qaiu.top)
|
||||
|
||||
main分支依赖JDK17, 提供了JDK11分支[main-jdk11](https://github.com/qaiu/netdisk-fast-download/tree/main-jdk11)
|
||||
**0.1.8及以上版本json接口格式有调整 参考json返回数据格式示例**
|
||||
**小飞机解析有IP限制,多数云服务商的大陆IP会被拦截(可以自行配置代理),和本程序无关**
|
||||
**注意: 请不要过度依赖lz.qaiu.top预览地址服务,建议本地搭建或者云服务器自行搭建。解析次数过多IP会被部分网盘厂商限制,不推荐做公共解析。**
|
||||
|
||||
## 网盘支持情况:
|
||||
> 20230905 奶牛云直链做了防盗链,需加入请求头:Referer: https://cowtransfer.com/
|
||||
> 20230824 123云盘解析大文件(>100MB)失效,需要登录
|
||||
> 20230722 UC网盘解析失效,需要登录
|
||||
|
||||
网盘名称-网盘标识:
|
||||
|
||||
- [蓝奏云-lz](https://pc.woozooo.com/)
|
||||
- [蓝奏云优享-iz](https://www.ilanzou.com/)
|
||||
- [奶牛快传-cow](https://cowtransfer.com/)
|
||||
- [移动云云空间-ec](https://www.ecpan.cn/web)
|
||||
- [小飞机网盘-fj](https://www.feijipan.com/)
|
||||
- [亿方云-fc](https://www.fangcloud.com/)
|
||||
- [123云盘-ye](https://www.123pan.com/)
|
||||
- ~[115网盘(失效)-p115](https://115.com/)~
|
||||
- [118网盘(已停服)-p118](https://www.118pan.com/)
|
||||
- [文叔叔-ws](https://www.wenshushu.cn/)
|
||||
- [联想乐云-le](https://lecloud.lenovo.com/)
|
||||
- [QQ邮箱云盘-qqw](https://mail.qq.com/)
|
||||
- [QQ闪传-qqsc](https://nutty.qq.com/nutty/ssr/26797.html)
|
||||
- [城通网盘-ct](https://www.ctfile.com)
|
||||
- [网易云音乐分享链接-mnes](https://music.163.com)
|
||||
- [酷狗音乐分享链接-mkgs](https://www.kugou.com)
|
||||
- [酷我音乐分享链接-mkws](https://kuwo.cn)
|
||||
- [QQ音乐分享链接-mqqs](https://y.qq.com)
|
||||
- 咪咕音乐分享链接(开发中)
|
||||
- [Cloudreve自建网盘-ce](https://github.com/cloudreve/Cloudreve)
|
||||
- ~[微雨云存储-pvvy](https://www.vyuyun.com/)~
|
||||
- [超星云盘(需要referer: https://pan-yz.chaoxing.com)-pcx](https://pan-yz.chaoxing.com)
|
||||
- Google云盘-pgd
|
||||
- Onedrive-pod
|
||||
- Dropbox-pdp
|
||||
- iCloud-pic
|
||||
### 仅专属版提供
|
||||
- [移动云盘-p139](https://yun.139.com/)
|
||||
- [联通云盘-pwo](https://pan.wo.cn/)
|
||||
- [天翼云盘-p189](https://cloud.189.cn/)
|
||||
|
||||
## API接口说明
|
||||
your_host指的是您的域名或者IP,实际使用时替换为实际域名或者IP,端口默认6400,可以使用nginx代理来做域名访问。
|
||||
解析方式分为两种类型直接跳转下载文件和获取下载链接,
|
||||
每一种都提供了两种接口形式: `通用接口parser?url=`和`网盘标志/分享key拼接的短地址(标志短链)`,所有规则参考示例。
|
||||
- 通用接口: `/parser?url=分享链接&pwd=密码` 没有分享密码去掉&pwd参数;
|
||||
- 标志短链: `/d/网盘标识/分享key@密码` 没有分享密码去掉@密码;
|
||||
- 直链JSON: `/json/网盘标识/分享key@密码`和`/json/parser?url=分享链接&pwd=密码`
|
||||
- 网盘标识参考上面网盘支持情况
|
||||
- 当带有分享密码时需要加上密码参数(pwd)
|
||||
- 移动云云空间,小飞机网盘的加密分享的密码可以忽略
|
||||
- 移动云空间分享key取分享链接中的data参数,比如`&data=xxx`的参数就是xxx
|
||||
|
||||
API规则:
|
||||
> 建议使用UrlEncode编码分享链接
|
||||
|
||||
1. 解析并自动302跳转
|
||||
http://your_host/parser?url=分享链接&pwd=xxx
|
||||
http://your_host/parser?url=UrlEncode(分享链接)&pwd=xxx
|
||||
http://your_host/d/网盘标识/分享key@分享密码
|
||||
2. 获取解析后的直链--JSON格式
|
||||
http(s)://you_host/json/网盘标识/分享id(#分享密码)
|
||||
http://your_host/json/parser?url=分享链接&pwd=xxx
|
||||
http://your_host/json/网盘标识/分享key@分享密码
|
||||
3. 文件夹解析v0.1.8fixed3新增
|
||||
http://your_host/json/getFileList?url=分享链接&pwd=xxx
|
||||
|
||||
|
||||
### json接口说明
|
||||
|
||||
#### 1. 文件解析:/json/parser?url=分享链接&pwd=xxx
|
||||
|
||||
json返回数据格式示例:
|
||||
`shareKey`: 全局分享key
|
||||
`directLink`: 下载链接
|
||||
`cacheHit`: 是否为缓存链接
|
||||
`expires`: 缓存到期时间
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
"success": true,
|
||||
"count": 0,
|
||||
"data": {
|
||||
"shareKey": "lz:xxx",
|
||||
"directLink": "下载直链",
|
||||
"cacheHit": true,
|
||||
"expires": "2024-09-18 01:48:02",
|
||||
"expiration": 1726638482825
|
||||
},
|
||||
"timestamp": 1726637151902
|
||||
}
|
||||
```
|
||||
#### 2. 分享链接详情接口 /v2/linkInfo?url=分享链接
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
"success": true,
|
||||
"count": 0,
|
||||
"data": {
|
||||
"downLink": "https://lz.qaiu.top/d/fj/xx",
|
||||
"apiLink": "https://lz.qaiu.top/json/fj/xx",
|
||||
"cacheHitTotal": 5,
|
||||
"parserTotal": 2,
|
||||
"sumTotal": 7,
|
||||
"shareLinkInfo": {
|
||||
"shareKey": "xx",
|
||||
"panName": "小飞机网盘",
|
||||
"type": "fj",
|
||||
"sharePassword": "",
|
||||
"shareUrl": "https://share.feijipan.com/s/xx",
|
||||
"standardUrl": "https://www.feijix.com/s/xx",
|
||||
"otherParam": {
|
||||
"UA": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0"
|
||||
},
|
||||
"cacheKey": "fj:xx"
|
||||
}
|
||||
},
|
||||
"timestamp": 1736489219402
|
||||
}
|
||||
```
|
||||
#### 3. 文件夹解析(仅支持蓝奏云/蓝奏优享/小飞机网盘)
|
||||
/v2/getFileList?url=分享链接&pwd=分享密码
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"fileName": "xxx",
|
||||
"fileId": "xxx",
|
||||
"fileIcon": null,
|
||||
"size": 999,
|
||||
"sizeStr": "999 M",
|
||||
"fileType": "file/folder",
|
||||
"filePath": null,
|
||||
"createTime": "17 小时前",
|
||||
"updateTime": null,
|
||||
"createBy": null,
|
||||
"description": null,
|
||||
"downloadCount": "下载次数",
|
||||
"panType": "lz",
|
||||
"parserUrl": "下载链接/文件夹链接",
|
||||
"extParameters": null
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
#### 4. 解析次数统计接口 /v2/statisticsInfo
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
"success": true,
|
||||
"count": 0,
|
||||
"data": {
|
||||
"parserTotal": 320508,
|
||||
"cacheTotal": 5957910,
|
||||
"total": 6278418
|
||||
},
|
||||
"timestamp": 1736489378770
|
||||
}
|
||||
```
|
||||
|
||||
IDEA HttpClient示例:
|
||||
|
||||
示例:
|
||||
```
|
||||
// 解析并重定向到直链
|
||||
###
|
||||
# 解析并重定向到直链
|
||||
### 蓝奏云普通分享
|
||||
# @no-redirect
|
||||
GET http://127.0.0.1:6400/parser?url=https://lanzoux.com/ia2cntg
|
||||
###
|
||||
### 奶牛快传普通分享
|
||||
# @no-redirect
|
||||
GET http://127.0.0.1:6400/parser?url=https://cowtransfer.com/s/9a644fe3e3a748
|
||||
### 360亿方云加密分享
|
||||
# @no-redirect
|
||||
GET http://127.0.0.1:6400/parser?url=https://v2.fangcloud.com/sharing/e5079007dc31226096628870c7&pwd=QAIU
|
||||
|
||||
// Rest请求(只提供共享文件Id):
|
||||
###
|
||||
# Rest请求自动302跳转(只提供共享文件Id):
|
||||
### 蓝奏云普通分享
|
||||
# @no-redirect
|
||||
GET http://127.0.0.1:6400/lz/ia2cntg
|
||||
### 奶牛快传普通分享
|
||||
# @no-redirect
|
||||
GET http://127.0.0.1:6400/cow/9a644fe3e3a748
|
||||
### 360亿方云加密分享
|
||||
GET http://127.0.0.1:6400/json/fc/e5079007dc31226096628870c7@QAIU
|
||||
|
||||
// 解析返回json直链
|
||||
###
|
||||
GET http://127.0.0.1:6400/json/cow/9a644fe3e3a748
|
||||
###
|
||||
|
||||
# 解析返回json直链
|
||||
### 蓝奏云普通分享
|
||||
GET http://127.0.0.1:6400/json/lz/ia2cntg
|
||||
### 奶牛快传普通分享
|
||||
GET http://127.0.0.1:6400/json/cow/9a644fe3e3a748
|
||||
### 360亿方云加密分享
|
||||
GET http://127.0.0.1:6400/json/fc/e5079007dc31226096628870c7@QAIU
|
||||
|
||||
|
||||
```
|
||||
|
||||
TODO:
|
||||
解析蓝奏云加密链接
|
||||
|
||||
|
||||
# 网盘对比
|
||||
|
||||
| 网盘名称 | 可直接下载分享 | 加密分享 | 初始网盘空间 | 单文件大小限制 | 登录接口 |
|
||||
|-------|-------------|----------|----------|----------------|------|
|
||||
| 蓝奏云 | √ | √ | 不限空间 | 100M | TODO |
|
||||
| 奶牛快传 | √ | X | 10G | 不限大小 | TODO |
|
||||
| 移动云空间 | √ | √(密码可忽略) | 5G(个人) | 不限大小 | TODO |
|
||||
| UC网盘 | √ | √ | 10G | 不限大小 | TODO |
|
||||
| 夸克网盘 | √(>10M需要登录) | √ | 10G(20G) | 不限大小(>10M需要登录) | X |
|
||||
|
||||
| 网盘名称 | 免登陆下载分享 | 加密分享 | 初始网盘空间 | 单文件大小限制 |
|
||||
|-------------|---------|----------|-----------|-----------------|
|
||||
| 蓝奏云 | √ | √ | 不限空间 | 100M |
|
||||
| 奶牛快传 | √ | X | 10G | 不限大小 |
|
||||
| 移动云云空间(个人版) | √ | √(密码可忽略) | 5G(个人) | 不限大小 |
|
||||
| 小飞机网盘 | √ | √(密码可忽略) | 10G | 不限大小 |
|
||||
| 360亿方云 | √ | √(密码可忽略) | 100G(须实名) | 不限大小 |
|
||||
| 123云盘 | √ | √ | 2T | 100G(>100M需要登录) |
|
||||
| 文叔叔 | √ | √ | 10G | 5GB |
|
||||
| 夸克网盘 | x | √ | 10G | 不限大小 |
|
||||
| UC网盘 | x | √ | 10G | 不限大小 |
|
||||
|
||||
# 打包部署
|
||||
|
||||
## JDK下载(lz.qaiu.top提供直链云解析服务)
|
||||
- [阿里jdk17(Dragonwell17-windows-x86)](https://lz.qaiu.top/ec/e957acef36ce89e1053979672a90d219n)
|
||||
- [阿里jdk17(Dragonwell17-linux-x86)](https://lz.qaiu.top/ec/6ebc9f2e0bbd53b4c4d5b11013f40a80NHvcYU)
|
||||
- [阿里jdk17(Dragonwell17-linux-aarch64)](https://lz.qaiu.top/ec/d14c2d06296f61b52a876b525265e0f8tzxTc5)
|
||||
- [解析有效性测试-移动云云空间-阿里jdk17-linux-x86](https://lz.qaiu.top/json/ec/6ebc9f2e0bbd53b4c4d5b11013f40a80NHvcYU)
|
||||
|
||||
## 开发和打包
|
||||
|
||||
```shell
|
||||
# 环境要求: Jdk17 + maven;
|
||||
mvn clean
|
||||
mvn package
|
||||
|
||||
```
|
||||
打包好的文件位于 web-service/target/netdisk-fast-download-bin.zip
|
||||
## Linux服务部署
|
||||
|
||||
### Docker 部署(Main分支)
|
||||
|
||||
#### 海外服务器Docker部署
|
||||
```shell
|
||||
# 创建目录
|
||||
mkdir -p netdisk-fast-download
|
||||
cd netdisk-fast-download
|
||||
|
||||
# 拉取镜像
|
||||
docker pull ghcr.io/qaiu/netdisk-fast-download:latest
|
||||
|
||||
# 复制配置文件(或下载仓库web-service\src\main\resources)
|
||||
docker create --name netdisk-fast-download ghcr.io/qaiu/netdisk-fast-download:latest
|
||||
docker cp netdisk-fast-download:/app/resources ./resources
|
||||
docker rm netdisk-fast-download
|
||||
|
||||
# 启动容器
|
||||
docker run -d -it --name netdisk-fast-download -p 6401:6401 --restart unless-stopped -e TZ=Asia/Shanghai -v ./resources:/app/resources -v ./db:/app/db -v ./logs:/app/logs ghcr.io/qaiu/netdisk-fast-download:latest
|
||||
|
||||
# 反代6401端口
|
||||
|
||||
# 升级容器
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup --run-once netdisk-fast-download
|
||||
```
|
||||
|
||||
#### 国内Docker部署
|
||||
```shell
|
||||
# 创建目录
|
||||
mkdir -p netdisk-fast-download
|
||||
cd netdisk-fast-download
|
||||
|
||||
# 拉取镜像
|
||||
docker pull ghcr.nju.edu.cn/qaiu/netdisk-fast-download:latest
|
||||
|
||||
# 复制配置文件(或下载仓库web-service\src\main\resources)
|
||||
docker create --name netdisk-fast-download ghcr.nju.edu.cn/qaiu/netdisk-fast-download:latest
|
||||
docker cp netdisk-fast-download:/app/resources ./resources
|
||||
docker rm netdisk-fast-download
|
||||
|
||||
# 启动容器
|
||||
docker run -d -it --name netdisk-fast-download -p 6401:6401 --restart unless-stopped -e TZ=Asia/Shanghai -v ./resources:/app/resources -v ./db:/app/db -v ./logs:/app/logs ghcr.nju.edu.cn/qaiu/netdisk-fast-download:latest
|
||||
|
||||
# 反代6401端口
|
||||
|
||||
# 升级容器
|
||||
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup --run-once netdisk-fast-download
|
||||
```
|
||||
|
||||
### 宝塔部署指引 -> [点击进入宝塔部署教程](https://blog.qaiu.top/archives/netdisk-fast-download-bao-ta-an-zhuang-jiao-cheng)
|
||||
|
||||
### Linux命令行部署
|
||||
> 注意: netdisk-fast-download.service中的ExecStart的路径改为实际路径
|
||||
```shell
|
||||
cd ~
|
||||
wget -O netdisk-fast-download.zip https://github.com/qaiu/netdisk-fast-download/releases/download/0.1.8-release-fixed2/netdisk-fast-download-bin-fixed2.zip
|
||||
unzip netdisk-fast-download-bin.zip
|
||||
cd netdisk-fast-download
|
||||
bash service-install.sh
|
||||
```
|
||||
服务相关命令:
|
||||
|
||||
查看服务状态
|
||||
`systemctl status netdisk-fast-download.service`
|
||||
|
||||
启动服务
|
||||
`systemctl start netdisk-fast-download.service`
|
||||
|
||||
重启服务
|
||||
`systemctl restart netdisk-fast-download.service`
|
||||
|
||||
停止服务
|
||||
`systemctl stop netdisk-fast-download.service`
|
||||
|
||||
开机启动服务
|
||||
`systemctl enable netdisk-fast-download.servic`
|
||||
|
||||
停止开机启动
|
||||
`systemctl disable netdisk-fast-download.servic`
|
||||
|
||||
## Windows服务部署
|
||||
1. 下载并解压releases版本netdisk-fast-download-bin.zip
|
||||
2. 进入netdisk-fast-download下的bin目录
|
||||
3. 使用管理员权限运行nfd-service-install.bat
|
||||
如果不想使用服务运行可以直接运行run.bat
|
||||
> 注意: 如果jdk环境变量的java版本不是17请修改nfd-service-template.xml中的java命令的路径改为实际路径
|
||||
|
||||
## 相关配置说明
|
||||
|
||||
resources目录下包含服务端配置文件 配置文件自带说明,具体请查看配置文件内容,
|
||||
app-dev.yml 可以配置解析服务相关信息, 包括端口,域名,缓存时长等
|
||||
server-proxy.yml 可以配置代理服务运行的相关信息, 包括前端反向代理端口,路径等
|
||||
|
||||
### ip代理配置说明
|
||||
有时候解析量很大,IP容易被ban,这时候可以使用其他服务器搭建nfd-proxy代理服务。
|
||||
|
||||
修改配置文件:
|
||||
app-dev.yml
|
||||
|
||||
```yaml
|
||||
proxy:
|
||||
- panTypes: pgd,pdb,pod # 网盘标识
|
||||
type: http # 支持http/socks4/socks5
|
||||
host: 127.0.0.1 # 代理IP
|
||||
port: 7890 # 端口
|
||||
username: # 用户名
|
||||
password: # 密码
|
||||
```
|
||||
nfd-proxy搭建http代理服务器
|
||||
参考https://github.com/nfd-parser/nfd-proxy
|
||||
|
||||
## 0.1.9 开发计划
|
||||
- 目录解析(专属版)
|
||||
- 带cookie/token参数解析大文件(专属版)
|
||||
|
||||
**技术栈:**
|
||||
Jdk17+Vert.x4
|
||||
Core模块集成Vert.x实现类似spring的注解式路由API
|
||||
|
||||
|
||||
## Star History
|
||||
|
||||
[](https://star-history.com/#qaiu/netdisk-fast-download&Date)
|
||||
|
||||
## **免责声明**
|
||||
- 用户在使用本项目时,应自行承担风险,并确保其行为符合当地法律法规及网盘服务提供商的使用条款。
|
||||
- 开发者不对用户因使用本项目而导致的任何后果负责,包括但不限于数据丢失、隐私泄露、账号封禁或其他任何形式的损害。
|
||||
|
||||
## 支持该项目
|
||||
开源不易,用爱发电,本项目长期维护如果觉得有帮助, 可以请作者喝杯咖啡, 感谢支持
|
||||
|
||||
|
||||
### 关于专属版
|
||||
99元, 提供对小飞机,蓝奏优享大文件解析的支持, 提供天翼云盘,移动云盘,联调云盘的解析支持
|
||||
199元, 包含部署服务和首页定制, 需提供宝塔环境
|
||||
可以提供功能定制开发, 加v价格详谈:
|
||||
<p>qq: 197575894</p>
|
||||
<p>wechat: imcoding_</p>
|
||||
|
||||
<!--
|
||||

|
||||
|
||||
[手机端支付宝打赏跳转链接](https://qr.alipay.com/fkx01882dnoxxtjenhlxt53)
|
||||
-->
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ Wants=network-online.target
|
||||
[Service]
|
||||
Type=simple
|
||||
# User=USER
|
||||
ExecStart=/usr/bin/java -server -Xmx128m -jar /root/java/netdisk-fast-download/netdisk-fast-download-0.0.1.jar
|
||||
# 需要JDK17及以上版本 注意修改为自己的路径
|
||||
ExecStart=/root/java/jdk-17.0.2/bin/java -server -Xmx128m -jar /root/java/netdisk-fast-download/netdisk-fast-download.jar
|
||||
ExecStop=/bin/kill -s QUIT $MAINPID
|
||||
Restart=always
|
||||
StandOutput=syslog
|
||||
|
||||
86
bin/nfd-install.sh
Normal file
86
bin/nfd-install.sh
Normal file
@@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# ----------- 配置区域 ------------
|
||||
# JRE 下载目录
|
||||
JRE_DIR="/opt/custom-jre17"
|
||||
# 使用阿里云镜像下载 JRE(OpenJDK 17)
|
||||
JRE_TARBALL_URL="https://mirrors.tuna.tsinghua.edu.cn/Adoptium/17/jre/x64/linux/OpenJDK17U-jre_x64_linux_hotspot_17.0.15_6.tar.gz"
|
||||
|
||||
# ZIP 文件下载相关
|
||||
ZIP_URL="http://www.722shop.top:6401/parser?url="
|
||||
ZIP_DEST_DIR="/opt/target-zip"
|
||||
ZIP_FILE_NAME="nfd.zip"
|
||||
# --------------------------------
|
||||
|
||||
# 创建目录
|
||||
mkdir -p "$JRE_DIR"
|
||||
mkdir -p "$ZIP_DEST_DIR"
|
||||
|
||||
# -------- 检查 unzip 是否存在 --------
|
||||
if ! command -v unzip >/dev/null 2>&1; then
|
||||
echo "unzip 未安装,正在安装..."
|
||||
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
apt-get update && apt-get install -y unzip
|
||||
elif command -v yum >/dev/null 2>&1; then
|
||||
yum install -y unzip
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
dnf install -y unzip
|
||||
else
|
||||
echo "不支持的包管理器,无法自动安装 unzip,请手动安装后重试。"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "unzip 已安装"
|
||||
fi
|
||||
|
||||
# -------- 下载并解压 JRE --------
|
||||
echo "下载 JRE 17 到 $JRE_DIR..."
|
||||
curl -L "$JRE_TARBALL_URL" -o "$JRE_DIR/jre17.tar.gz"
|
||||
|
||||
echo "解压 JRE..."
|
||||
tar -xzf "$JRE_DIR/jre17.tar.gz" -C "$JRE_DIR" --strip-components=1
|
||||
rm "$JRE_DIR/jre17.tar.gz"
|
||||
echo "JRE 解压完成"
|
||||
|
||||
# -------- 下载 ZIP 文件 --------
|
||||
ZIP_PATH="$ZIP_DEST_DIR/$ZIP_FILE_NAME"
|
||||
echo "下载 ZIP 文件到 $ZIP_PATH..."
|
||||
curl -L "$ZIP_URL" -o "$ZIP_PATH"
|
||||
|
||||
# -------- 解压 ZIP 文件 --------
|
||||
echo "解压 ZIP 文件到 $ZIP_DEST_DIR..."
|
||||
unzip -o "$ZIP_PATH" -d "$ZIP_DEST_DIR"
|
||||
echo "解压完成"
|
||||
|
||||
# -------- 启动 JAR 程序 --------
|
||||
echo "进入 JAR 目录并后台运行程序..."
|
||||
|
||||
JAR_DIR="/opt/target-zip/netdisk-fast-download"
|
||||
JAR_FILE="netdisk-fast-download.jar"
|
||||
JAVA_BIN="$JRE_DIR/bin/java"
|
||||
LOG_FILE="$JAR_DIR/app.log"
|
||||
|
||||
if [ ! -d "$JAR_DIR" ]; then
|
||||
echo "[错误] 找不到 JAR 目录: $JAR_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$JAR_DIR"
|
||||
|
||||
if [ ! -f "$JAR_FILE" ]; then
|
||||
echo "[错误] 找不到 JAR 文件: $JAR_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -x "$JAVA_BIN" ]; then
|
||||
echo "[错误] 找不到可执行的 java: $JAVA_BIN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 后台运行,日志记录
|
||||
nohup "$JAVA_BIN" -jar "$JAR_FILE" > "$LOG_FILE" 2>&1 &
|
||||
|
||||
echo "程序已在后台启动 ✅"
|
||||
echo "日志路径: $LOG_FILE"
|
||||
27
bin/nfd-service-install.bat
Normal file
27
bin/nfd-service-install.bat
Normal file
@@ -0,0 +1,27 @@
|
||||
::
|
||||
:: generate service xml file
|
||||
::
|
||||
|
||||
@echo off
|
||||
pushd %~dp0
|
||||
set MY_DIR=%~dp0
|
||||
set MY_DIR=%MY_DIR:~0,-1%
|
||||
|
||||
for /f "delims=X" %%i in ('dir /b %MY_DIR%\netdisk-fast-download.jar') do (
|
||||
set LAUNCH_JAR=%MY_DIR%\%%i
|
||||
)
|
||||
|
||||
(for /f "delims=" %%a in (nfd-service-template.xml) do (
|
||||
set "str=%%a"
|
||||
setlocal enabledelayedexpansion
|
||||
set "str=!str:${dd}=%MY_DIR%!"
|
||||
set "str=!str:${jar}=%LAUNCH_JAR%!"
|
||||
echo,!str!
|
||||
endlocal
|
||||
))>"nfd-service.xml"
|
||||
|
||||
|
||||
sc delete netdisk-fast-download
|
||||
nfd-service install
|
||||
sc start netdisk-fast-download
|
||||
pause
|
||||
12
bin/nfd-service-template.xml
Normal file
12
bin/nfd-service-template.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<service>
|
||||
<id>netdisk-fast-download</id>
|
||||
<name>netdisk-fast-download</name>
|
||||
<description>netdisk fast download service</description>
|
||||
<executable>java</executable>
|
||||
<arguments> -server -Xmx128m -Dfile.encoding=utf8 -jar ${jar} </arguments>
|
||||
<logpath>${dd}\logs</logpath>
|
||||
<log mode="roll-by-time">
|
||||
<pattern>yyyyMMdd</pattern>
|
||||
</log>
|
||||
</service>
|
||||
BIN
bin/nfd-service.exe
Normal file
BIN
bin/nfd-service.exe
Normal file
Binary file not shown.
@@ -1,5 +1,11 @@
|
||||
@echo off && @chcp 65001 > nul
|
||||
pushd %~dp0
|
||||
set LIB_DIR=%~dp0
|
||||
for /f "delims=X" %%i in ('dir /b %LIB_DIR%\netdisk-fast-download-*.jar') do set LAUNCH_JAR=%LIB_DIR%\%%i
|
||||
for /f "delims=X" %%i in ('dir /b %LIB_DIR%\netdisk-fast-download.jar') do (
|
||||
set LAUNCH_JAR=%LIB_DIR%%%i
|
||||
)
|
||||
|
||||
set "JAVA_HOME=D:\App\dragonwell-17.0.3.0.3+7-GA"
|
||||
"%JAVA_HOME%\bin\java.exe" -Xmx512M -Dfile.encoding=utf8 -jar %LAUNCH_JAR% %*
|
||||
|
||||
pause
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# set -x
|
||||
LAUNCH_JAR="netdisk-fast-download-*.jar"
|
||||
LAUNCH_JAR="netdisk-fast-download.jar"
|
||||
nohup java -Xmx512M -jar "$LAUNCH_JAR" "$@" >startup.log 2>&1 &
|
||||
tail -f startup.log
|
||||
|
||||
|
||||
14
bin/stop.sh
Normal file
14
bin/stop.sh
Normal file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
# set -x
|
||||
|
||||
# 找到运行中的 Java 进程的 PID
|
||||
PID=$(ps -ef | grep 'netdisk-fast-download.jar' | grep -v grep | awk '{print $2}')
|
||||
|
||||
if [ -z "$PID" ]; then
|
||||
echo "未找到正在运行的进程 netdisk-fast-download.jar"
|
||||
exit 1
|
||||
else
|
||||
# 杀掉进程
|
||||
echo "停止 netdisk-fast-download.jar (PID: $PID)..."
|
||||
kill -9 "$PID"
|
||||
fi
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>netdisk-fast-download</artifactId>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<version>0.1.3</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -16,21 +16,20 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<slf4j.version>2.0.5</slf4j.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<vertx.version>4.4.1</vertx.version>
|
||||
<vertx.version>4.5.6</vertx.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>1.0.8</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>2.1.214</version>
|
||||
<version>2.2.220</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
|
||||
@@ -42,7 +41,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<version>3.18.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
@@ -60,6 +59,18 @@
|
||||
<artifactId>vertx-jdbc-client</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>9.2.0</version>
|
||||
</dependency>
|
||||
<!-- PG驱动-->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.7.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.qaiu;
|
||||
|
||||
public class StartH2DatabaseServer {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ public @interface Constraint {
|
||||
boolean notNull() default false;
|
||||
|
||||
/**
|
||||
* 唯一键约束 TODO 待实现
|
||||
* @return 唯一键约束
|
||||
*/
|
||||
String uniqueKey() default "";
|
||||
@@ -32,7 +31,7 @@ public @interface Constraint {
|
||||
*/
|
||||
String defaultValue() default "";
|
||||
/**
|
||||
* 默认值是否是函数
|
||||
* 默认值是否是函数 like value=NOW()
|
||||
* @return false 不是函数
|
||||
*/
|
||||
boolean defaultValueIsFunction() default false;
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.qaiu.db.ddl;
|
||||
|
||||
import cn.qaiu.db.pool.JDBCPoolInit;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CreateDatabase {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCPoolInit.class);
|
||||
|
||||
/**
|
||||
* 解析数据库URL,获取数据库名
|
||||
* @param url 数据库URL
|
||||
* @return 数据库名
|
||||
*/
|
||||
public static String getDatabaseName(String url) {
|
||||
// 正则表达式匹配数据库名
|
||||
String regex = "jdbc:mysql://[^/]+/(\\w+)(\\?.*)?";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(url);
|
||||
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid database URL: " + url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用JDBC原生方法创建数据库
|
||||
* @param url 数据库连接URL
|
||||
* @param user 数据库用户名
|
||||
* @param password 数据库密码
|
||||
*/
|
||||
public static void createDatabase(String url, String user, String password) {
|
||||
String dbName = getDatabaseName(url);
|
||||
LOGGER.info(">>>>>>>>>>> 创建数据库:'{}' <<<<<<<<<<<< ", dbName);
|
||||
|
||||
// 去掉数据库名,构建不带数据库名的URL
|
||||
String baseUrl = url.substring(0, url.lastIndexOf("/") + 1) + "?characterEncoding=UTF-8&useUnicode=true";
|
||||
|
||||
try (Connection conn = DriverManager.getConnection(baseUrl, user, password);
|
||||
Statement stmt = conn.createStatement()) {
|
||||
// 创建数据库
|
||||
stmt.executeUpdate("CREATE DATABASE IF NOT EXISTS " + dbName + " CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
|
||||
LOGGER.info(">>>>>>>>>>> 数据库'{}'创建成功 <<<<<<<<<<<<", dbName);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void createDatabase(JsonObject dbConfig) {
|
||||
createDatabase(
|
||||
dbConfig.getString("jdbcUrl"),
|
||||
dbConfig.getString("username"),
|
||||
dbConfig.getString("password")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package cn.qaiu.db.ddl;
|
||||
|
||||
import cn.qaiu.db.pool.JDBCType;
|
||||
import cn.qaiu.vx.core.util.ReflectionUtil;
|
||||
import io.vertx.codegen.format.CamelCase;
|
||||
import io.vertx.codegen.format.Case;
|
||||
import io.vertx.codegen.format.LowerCamelCase;
|
||||
import io.vertx.codegen.format.SnakeCase;
|
||||
import io.vertx.jdbcclient.JDBCPool;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.sqlclient.Pool;
|
||||
import io.vertx.sqlclient.templates.annotations.Column;
|
||||
import io.vertx.sqlclient.templates.annotations.RowMapped;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -13,9 +16,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 创建表
|
||||
@@ -23,148 +24,312 @@ import java.util.Set;
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public class CreateTable {
|
||||
public static Map<Class<?>, String> javaProperty2SqlColumnMap = new HashMap<>();
|
||||
public static Map<Class<?>, String> javaProperty2SqlColumnMap = new HashMap<>() {{
|
||||
// Java类型到SQL类型的映射
|
||||
put(Integer.class, "INT");
|
||||
put(Short.class, "SMALLINT");
|
||||
put(Byte.class, "TINYINT");
|
||||
put(Long.class, "BIGINT");
|
||||
put(java.math.BigDecimal.class, "DECIMAL");
|
||||
put(Double.class, "DOUBLE");
|
||||
put(Float.class, "REAL");
|
||||
put(Boolean.class, "BOOLEAN");
|
||||
put(String.class, "VARCHAR");
|
||||
put(Date.class, "TIMESTAMP");
|
||||
put(java.time.LocalDateTime.class, "TIMESTAMP");
|
||||
put(java.sql.Timestamp.class, "TIMESTAMP");
|
||||
put(java.sql.Date.class, "DATE");
|
||||
put(java.sql.Time.class, "TIME");
|
||||
|
||||
// 基本数据类型
|
||||
put(int.class, "INT");
|
||||
put(short.class, "SMALLINT");
|
||||
put(byte.class, "TINYINT");
|
||||
put(long.class, "BIGINT");
|
||||
put(double.class, "DOUBLE");
|
||||
put(float.class, "REAL");
|
||||
put(boolean.class, "BOOLEAN");
|
||||
}};
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CreateTable.class);
|
||||
|
||||
static {
|
||||
javaProperty2SqlColumnMap.put(Integer.class, "INT");
|
||||
javaProperty2SqlColumnMap.put(Short.class, "SMALLINT");
|
||||
javaProperty2SqlColumnMap.put(Byte.class, "TINYINT");
|
||||
javaProperty2SqlColumnMap.put(Long.class, "BIGINT");
|
||||
javaProperty2SqlColumnMap.put(java.math.BigDecimal.class, "DECIMAL");
|
||||
javaProperty2SqlColumnMap.put(Double.class, "DOUBLE");
|
||||
javaProperty2SqlColumnMap.put(Float.class, "REAL");
|
||||
javaProperty2SqlColumnMap.put(Boolean.class, "BOOLEAN");
|
||||
javaProperty2SqlColumnMap.put(String.class, "VARCHAR");
|
||||
javaProperty2SqlColumnMap.put(java.util.Date.class, "TIMESTAMP");
|
||||
javaProperty2SqlColumnMap.put(java.sql.Timestamp.class, "TIMESTAMP");
|
||||
javaProperty2SqlColumnMap.put(java.sql.Date.class, "DATE");
|
||||
javaProperty2SqlColumnMap.put(java.sql.Time.class, "TIME");
|
||||
|
||||
javaProperty2SqlColumnMap.put(int.class, "INT");
|
||||
javaProperty2SqlColumnMap.put(short.class, "SMALLINT");
|
||||
javaProperty2SqlColumnMap.put(byte.class, "TINYINT");
|
||||
javaProperty2SqlColumnMap.put(long.class, "BIGINT");
|
||||
javaProperty2SqlColumnMap.put(double.class, "DOUBLE");
|
||||
javaProperty2SqlColumnMap.put(float.class, "REAL");
|
||||
javaProperty2SqlColumnMap.put(boolean.class, "BOOLEAN");
|
||||
}
|
||||
public static String UNIQUE_PREFIX = "idx_";
|
||||
|
||||
private static Case getCase(Class<?> clz) {
|
||||
switch (clz.getName()) {
|
||||
case "io.vertx.codegen.format.CamelCase":
|
||||
return CamelCase.INSTANCE;
|
||||
case "io.vertx.codegen.format.SnakeCase":
|
||||
return SnakeCase.INSTANCE;
|
||||
case "io.vertx.codegen.format.LowerCamelCase":
|
||||
return LowerCamelCase.INSTANCE;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
return switch (clz.getName()) {
|
||||
case "io.vertx.codegen.format.CamelCase" -> CamelCase.INSTANCE;
|
||||
case "io.vertx.codegen.format.SnakeCase" -> SnakeCase.INSTANCE;
|
||||
case "io.vertx.codegen.format.LowerCamelCase" -> LowerCamelCase.INSTANCE;
|
||||
default -> throw new UnsupportedOperationException();
|
||||
};
|
||||
}
|
||||
|
||||
public static List<String> getCreateTableSQL(Class<?> clz, JDBCType type) {
|
||||
// 获取表名和主键
|
||||
TableInfo tableInfo = extractTableInfo(clz, type);
|
||||
|
||||
// 构建表的SQL语句
|
||||
List<String> sqlList = new ArrayList<>();
|
||||
StringBuilder sb = new StringBuilder(50);
|
||||
sb.append("CREATE TABLE IF NOT EXISTS ")
|
||||
.append(tableInfo.quotationMarks).append(tableInfo.tableName).append(tableInfo.quotationMarks)
|
||||
.append(" ( \r\n ");
|
||||
|
||||
// 处理字段并生成列定义
|
||||
List<String> indexSQLs = new ArrayList<>();
|
||||
processFields(clz, tableInfo, sb, indexSQLs);
|
||||
|
||||
// 去掉最后一个逗号并添加表尾部信息
|
||||
String tableSQL = sb.substring(0, sb.lastIndexOf(",")) + tableInfo.endStr;
|
||||
sqlList.add(tableSQL);
|
||||
|
||||
// 添加索引SQL
|
||||
sqlList.addAll(indexSQLs);
|
||||
|
||||
return sqlList;
|
||||
}
|
||||
|
||||
|
||||
// 修改extractTableInfo方法,处理没有Table注解时默认使用id字段作为主键
|
||||
private static TableInfo extractTableInfo(Class<?> clz, JDBCType type) {
|
||||
String quotationMarks;
|
||||
String endStr;
|
||||
if (type == JDBCType.MySQL) {
|
||||
quotationMarks = "`";
|
||||
endStr = ")ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
} else {
|
||||
quotationMarks = "\"";
|
||||
endStr = ");";
|
||||
}
|
||||
|
||||
String primaryKey = null;
|
||||
String tableName = null;
|
||||
Case caseFormat = SnakeCase.INSTANCE;
|
||||
|
||||
// 判断类上是否有RowMapped注解
|
||||
if (clz.isAnnotationPresent(RowMapped.class)) {
|
||||
RowMapped annotation = clz.getAnnotation(RowMapped.class);
|
||||
caseFormat = getCase(annotation.formatter());
|
||||
}
|
||||
|
||||
// 判断类上是否有Table注解
|
||||
if (clz.isAnnotationPresent(Table.class)) {
|
||||
Table annotation = clz.getAnnotation(Table.class);
|
||||
tableName = StringUtils.isNotEmpty(annotation.value())
|
||||
? annotation.value()
|
||||
: LowerCamelCase.INSTANCE.to(caseFormat, clz.getSimpleName());
|
||||
primaryKey = annotation.keyFields();
|
||||
}
|
||||
|
||||
// 如果表名仍为null,使用类名转下划线命名作为表名
|
||||
if (StringUtils.isEmpty(tableName)) {
|
||||
tableName = LowerCamelCase.INSTANCE.to(SnakeCase.INSTANCE, clz.getSimpleName());
|
||||
}
|
||||
|
||||
// 如果主键为空,默认使用id字段作为主键
|
||||
if (StringUtils.isEmpty(primaryKey)) {
|
||||
try {
|
||||
clz.getDeclaredField("id");
|
||||
primaryKey = "id";
|
||||
} catch (NoSuchFieldException e) {
|
||||
// 如果没有id字段,不设置主键
|
||||
primaryKey = null;
|
||||
}
|
||||
}
|
||||
|
||||
return new TableInfo(tableName, quotationMarks, endStr, primaryKey, caseFormat, type);
|
||||
}
|
||||
|
||||
// 修改processFields方法,处理索引
|
||||
private static void processFields(Class<?> clz, TableInfo tableInfo, StringBuilder sb, List<String> indexSQLs) {
|
||||
Field[] fields = clz.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
// 跳过无效字段
|
||||
if (isIgnoredField(field)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取字段名和SQL类型
|
||||
String column = LowerCamelCase.INSTANCE.to(tableInfo.caseFormat, field.getName());
|
||||
String sqlType = javaProperty2SqlColumnMap.get(field.getType());
|
||||
|
||||
// 处理字段注解
|
||||
column = processColumnAnnotation(field, column);
|
||||
int[] decimalSize = {22, 2};
|
||||
int varcharSize = 255;
|
||||
if (field.isAnnotationPresent(Length.class)) {
|
||||
Length length = field.getAnnotation(Length.class);
|
||||
decimalSize = length.decimalSize();
|
||||
varcharSize = length.varcharSize();
|
||||
}
|
||||
|
||||
// 构建列定义
|
||||
sb.append(tableInfo.quotationMarks).append(column).append(tableInfo.quotationMarks)
|
||||
.append(" ").append(sqlType);
|
||||
appendTypeLength(sqlType, sb, decimalSize, varcharSize);
|
||||
appendConstraints(field, sb, tableInfo);
|
||||
appendPrimaryKey(tableInfo.primaryKey, column, sb);
|
||||
|
||||
// 添加索引
|
||||
appendIndex(tableInfo, indexSQLs, field);
|
||||
|
||||
sb.append(",\n ");
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCreateTableSQL(Class<?> clz) {
|
||||
// 判断类上是否有次注解
|
||||
String primaryKey = null; // 主键
|
||||
String tableName = null; // 表名
|
||||
Case caseFormat = SnakeCase.INSTANCE;
|
||||
if (clz.isAnnotationPresent(RowMapped.class)) {
|
||||
RowMapped annotation = clz.getAnnotation(RowMapped.class);
|
||||
Class<? extends Case> formatter = annotation.formatter();
|
||||
caseFormat = getCase(formatter);
|
||||
}
|
||||
// 判断是否忽略字段
|
||||
private static boolean isIgnoredField(Field field) {
|
||||
return field.getName().equals("serialVersionUID")
|
||||
|| StringUtils.isEmpty(javaProperty2SqlColumnMap.get(field.getType()))
|
||||
|| field.isAnnotationPresent(TableGenIgnore.class);
|
||||
}
|
||||
|
||||
if (clz.isAnnotationPresent(Table.class)) {
|
||||
// 获取类上的注解
|
||||
Table annotation = clz.getAnnotation(Table.class);
|
||||
// 输出注解上的类名
|
||||
String tableNameAnnotation = annotation.value();
|
||||
if (StringUtils.isNotEmpty(tableNameAnnotation)) {
|
||||
tableName = tableNameAnnotation;
|
||||
} else {
|
||||
tableName = LowerCamelCase.INSTANCE.to(caseFormat, clz.getSimpleName());
|
||||
// 处理Column注解
|
||||
private static String processColumnAnnotation(Field field, String column) {
|
||||
if (field.isAnnotationPresent(Column.class)) {
|
||||
Column columnAnnotation = field.getAnnotation(Column.class);
|
||||
if (StringUtils.isNotBlank(columnAnnotation.name())) {
|
||||
column = columnAnnotation.name();
|
||||
}
|
||||
primaryKey = annotation.keyFields();
|
||||
}
|
||||
Field[] fields = clz.getDeclaredFields();
|
||||
String column;
|
||||
int[] decimalSize = {22, 2};
|
||||
int varcharSize = 255;
|
||||
StringBuilder sb = new StringBuilder(50);
|
||||
sb.append("CREATE TABLE IF NOT EXISTS \"").append(tableName).append("\" ( \r\n ");
|
||||
boolean firstId = true;
|
||||
for (Field f : fields) {
|
||||
Class<?> paramType = f.getType();
|
||||
String sqlType = javaProperty2SqlColumnMap.get(paramType);
|
||||
if (f.getName().equals("serialVersionUID") || StringUtils.isEmpty(sqlType) || f.isAnnotationPresent(TableGenIgnore.class)) {
|
||||
continue;
|
||||
return column;
|
||||
}
|
||||
|
||||
// 添加类型长度
|
||||
private static void appendTypeLength(String sqlType, StringBuilder sb, int[] decimalSize, int varcharSize) {
|
||||
if ("DECIMAL".equals(sqlType)) {
|
||||
sb.append("(").append(decimalSize[0]).append(",").append(decimalSize[1]).append(")");
|
||||
} else if ("VARCHAR".equals(sqlType)) {
|
||||
sb.append("(").append(varcharSize).append(")");
|
||||
}
|
||||
}
|
||||
|
||||
// 添加约束
|
||||
private static void appendConstraints(Field field, StringBuilder sb, TableInfo tableInfo) {
|
||||
JDBCType type = tableInfo.dbType;
|
||||
|
||||
if (field.isAnnotationPresent(Constraint.class)) {
|
||||
Constraint constraint = field.getAnnotation(Constraint.class);
|
||||
if (constraint.notNull()) {
|
||||
sb.append(" NOT NULL");
|
||||
}
|
||||
column = LowerCamelCase.INSTANCE.to(caseFormat, f.getName());
|
||||
if (f.isAnnotationPresent(Column.class)) {
|
||||
Column columnAnnotation = f.getAnnotation(Column.class);
|
||||
//输出注解属性
|
||||
if (StringUtils.isNotBlank(columnAnnotation.name())) {
|
||||
column = columnAnnotation.name();
|
||||
}
|
||||
String apostrophe = constraint.defaultValueIsFunction() ? "" : "'";
|
||||
if (StringUtils.isNotEmpty(constraint.defaultValue())) {
|
||||
sb.append(" DEFAULT ").append(apostrophe).append(constraint.defaultValue()).append(apostrophe);
|
||||
}
|
||||
if (f.isAnnotationPresent(Length.class)) {
|
||||
Length fieldAnnotation = f.getAnnotation(Length.class);
|
||||
decimalSize = fieldAnnotation.decimalSize();
|
||||
varcharSize = fieldAnnotation.varcharSize();
|
||||
}
|
||||
sb.append("\"").append(column).append("\"");
|
||||
sb.append(" ").append(sqlType);
|
||||
// 添加类型长度
|
||||
if (sqlType.equals("DECIMAL")) {
|
||||
sb.append("(").append(decimalSize[0]).append(",").append(decimalSize[1]).append(")");
|
||||
}
|
||||
if (sqlType.equals("VARCHAR")) {
|
||||
sb.append("(").append(varcharSize).append(")");
|
||||
}
|
||||
if (f.isAnnotationPresent(Constraint.class)) {
|
||||
Constraint constraintAnnotation = f.getAnnotation(Constraint.class);
|
||||
if (constraintAnnotation.notNull()) {
|
||||
//非空约束
|
||||
sb.append(" NOT NULL");
|
||||
}
|
||||
String apostrophe = constraintAnnotation.defaultValueIsFunction() ? "" : "'";
|
||||
if (StringUtils.isNotEmpty(constraintAnnotation.defaultValue())) {
|
||||
//默认值约束
|
||||
sb.append(" DEFAULT ").append(apostrophe).append(constraintAnnotation.defaultValue()).append(apostrophe);
|
||||
}
|
||||
if (constraintAnnotation.autoIncrement() && paramType.equals(Integer.class) || paramType.equals(Long.class)) {
|
||||
////自增
|
||||
if (constraint.autoIncrement()) {
|
||||
if (type == JDBCType.PostgreSQL) {
|
||||
// 需要移除字段类型(最后一个单词)
|
||||
if (field.getType().equals(Integer.class)) {
|
||||
sb.delete(sb.lastIndexOf(" "), sb.length());
|
||||
sb.append(" SERIAL");
|
||||
} else if (field.getType().equals(Long.class)) {
|
||||
sb.delete(sb.lastIndexOf(" "), sb.length());
|
||||
sb.append(" BIGSERIAL");
|
||||
}
|
||||
} else if (field.getType().equals(Integer.class) || field.getType().equals(Long.class)) {
|
||||
sb.append(" AUTO_INCREMENT");
|
||||
}
|
||||
}
|
||||
if (StringUtils.isEmpty(primaryKey)) {
|
||||
if (firstId) {//类型转换
|
||||
sb.append(" PRIMARY KEY");
|
||||
firstId = false;
|
||||
}
|
||||
} else {
|
||||
if (primaryKey.equals(column.toLowerCase())) {
|
||||
sb.append(" PRIMARY KEY");
|
||||
}
|
||||
}
|
||||
sb.append(",\n ");
|
||||
}
|
||||
String sql = sb.toString();
|
||||
//去掉最后一个逗号
|
||||
int lastIndex = sql.lastIndexOf(",");
|
||||
sql = sql.substring(0, lastIndex) + sql.substring(lastIndex + 1);
|
||||
return sql.substring(0, sql.length() - 1) + ");\r\n";
|
||||
}
|
||||
|
||||
public static void createTable(JDBCPool pool, String tableClassPath) {
|
||||
Set<Class<?>> tableClassList = ReflectionUtil.getReflections(tableClassPath).getTypesAnnotatedWith(Table.class);
|
||||
if (tableClassList.isEmpty()) LOGGER.info("Table model class not fount");
|
||||
tableClassList.forEach(clazz -> {
|
||||
String createTableSQL = getCreateTableSQL(clazz);
|
||||
pool.query(createTableSQL).execute().onSuccess(
|
||||
rs -> LOGGER.info("\n" + createTableSQL + "create table --> ok")
|
||||
).onFailure(Throwable::printStackTrace);
|
||||
});
|
||||
// 添加主键
|
||||
private static void appendPrimaryKey(String primaryKey, String column, StringBuilder sb) {
|
||||
if (StringUtils.isEmpty(primaryKey)) {
|
||||
return;
|
||||
}
|
||||
if (primaryKey.equalsIgnoreCase(column)) {
|
||||
sb.append(" PRIMARY KEY");
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendIndex(TableInfo tableInfo, List<String> indexSQLs, Field field) {
|
||||
if (!field.isAnnotationPresent(Constraint.class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Constraint constraint = field.getAnnotation(Constraint.class);
|
||||
if (StringUtils.isEmpty(constraint.uniqueKey())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String indexName = UNIQUE_PREFIX + tableInfo.tableName + "_" + constraint.uniqueKey();
|
||||
String columnName = field.getName();
|
||||
|
||||
// 检查是否已有相同索引名称的索引
|
||||
Optional<String> existingIndex = indexSQLs.stream()
|
||||
.filter(sql -> sql.contains(tableInfo.quotationMarks + indexName + tableInfo.quotationMarks))
|
||||
.findFirst();
|
||||
|
||||
if (existingIndex.isPresent()) {
|
||||
// 如果存在相同索引名称,追加字段到索引定义中
|
||||
String updatedIndex = existingIndex.get().replaceFirst(
|
||||
"\\(([^)]+)\\)", // 匹配索引字段列表
|
||||
"($1, " + tableInfo.quotationMarks + columnName + tableInfo.quotationMarks + ")"
|
||||
);
|
||||
indexSQLs.remove(existingIndex.get());
|
||||
indexSQLs.add(updatedIndex);
|
||||
} else {
|
||||
// 如果不存在相同索引名称,创建新的索引
|
||||
String indexSQL = String.format(
|
||||
"CREATE UNIQUE INDEX %s %s%s%s ON %s%s%s (%s%s%s);",
|
||||
tableInfo.dbType == JDBCType.MySQL ? "" : "IF NOT EXISTS",
|
||||
tableInfo.quotationMarks, indexName, tableInfo.quotationMarks,
|
||||
tableInfo.quotationMarks, tableInfo.tableName, tableInfo.quotationMarks,
|
||||
tableInfo.quotationMarks, columnName, tableInfo.quotationMarks
|
||||
);
|
||||
indexSQLs.add(indexSQL);
|
||||
}
|
||||
}
|
||||
|
||||
// 表信息类
|
||||
private record TableInfo(
|
||||
String tableName, // 表名
|
||||
String quotationMarks, // 引号或反引号
|
||||
String endStr, // 表尾部信息
|
||||
String primaryKey, // 主键字段
|
||||
Case caseFormat, // 命名格式
|
||||
JDBCType dbType // 数据库类型
|
||||
) {
|
||||
}
|
||||
|
||||
public static Future<Void> createTable(Pool pool, JDBCType type) {
|
||||
Promise<Void> promise = Promise.promise();
|
||||
Set<Class<?>> tableClasses = ReflectionUtil.getReflections().getTypesAnnotatedWith(Table.class);
|
||||
|
||||
if (tableClasses.isEmpty()) {
|
||||
LOGGER.warn("Table model class not found");
|
||||
promise.complete();
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
List<Future<Object>> futures = new ArrayList<>();
|
||||
|
||||
for (Class<?> clazz : tableClasses) {
|
||||
List<String> sqlList = getCreateTableSQL(clazz, type);
|
||||
LOGGER.info("Class `{}` auto-generate table", clazz.getName());
|
||||
|
||||
for (String sql : sqlList) {
|
||||
try {
|
||||
pool.query(sql).execute().toCompletionStage().toCompletableFuture().join();
|
||||
futures.add(Future.succeededFuture());
|
||||
LOGGER.debug("Executed SQL:\n{}", sql);
|
||||
} catch (Exception e) {
|
||||
String message = e.getMessage();
|
||||
if (message != null && message.contains("Duplicate key name")) {
|
||||
LOGGER.warn("Ignoring duplicate key error: {}", message);
|
||||
futures.add(Future.succeededFuture());
|
||||
} else {
|
||||
LOGGER.error("SQL Error: {}\nSQL: {}", message, sql);
|
||||
futures.add(Future.failedFuture(e));
|
||||
throw new RuntimeException(e); // Stop execution for other exceptions
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future.all(futures).onSuccess(r -> promise.complete()).onFailure(promise::fail);
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
package cn.qaiu.db.pool;
|
||||
|
||||
import cn.qaiu.db.ddl.CreateTable;
|
||||
import cn.qaiu.db.server.H2ServerHolder;
|
||||
import cn.qaiu.db.ddl.CreateDatabase;
|
||||
import cn.qaiu.vx.core.util.VertxHolder;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.jdbcclient.JDBCPool;
|
||||
import org.h2.tools.Server;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* 初始化JDBC
|
||||
* <br>Create date 2021/8/10 12:04
|
||||
@@ -24,16 +20,29 @@ import java.sql.SQLException;
|
||||
public class JDBCPoolInit {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCPoolInit.class);
|
||||
|
||||
private static final String providerClass = io.vertx.ext.jdbc.spi.impl.HikariCPDataSourceProvider.class.getName();
|
||||
|
||||
private JDBCPool pool = null;
|
||||
JsonObject dbConfig;
|
||||
Vertx vertx = VertxHolder.getVertxInstance();
|
||||
String url;
|
||||
|
||||
private final JDBCType type;
|
||||
|
||||
private static JDBCPoolInit instance;
|
||||
|
||||
public JDBCType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public JDBCPoolInit(Builder builder) {
|
||||
this.dbConfig = builder.dbConfig;
|
||||
this.url = builder.url;
|
||||
this.type = JDBCType.getJDBCTypeByURL(builder.url);
|
||||
if (StringUtils.isBlank(builder.dbConfig.getString("provider_class"))) {
|
||||
builder.dbConfig.put("provider_class", providerClass);
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
@@ -62,86 +71,34 @@ public class JDBCPoolInit {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* init h2db<br>
|
||||
* 这个方法只允许调用一次
|
||||
*/
|
||||
public void initPool() {
|
||||
synchronized public Future<Void> initPool() {
|
||||
if (pool != null) {
|
||||
LOGGER.error("pool 重复初始化");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// 异步启动H2服务
|
||||
vertx.createSharedWorkerExecutor("h2-server", 1, Long.MAX_VALUE)
|
||||
.executeBlocking(this::h2serverExecute)
|
||||
.onSuccess(res->{
|
||||
LOGGER.info(res);
|
||||
// 初始化数据库连接
|
||||
vertx.createSharedWorkerExecutor("sql-pool-init")
|
||||
.executeBlocking(this::poolInitExecute)
|
||||
.onSuccess(LOGGER::info)
|
||||
.onFailure(Throwable::printStackTrace);
|
||||
})
|
||||
.onFailure(Throwable::printStackTrace);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void poolInitExecute(Promise<String> promise) {
|
||||
// 初始化数据库连接
|
||||
// 初始化连接池
|
||||
if (type == JDBCType.MySQL) {
|
||||
CreateDatabase.createDatabase(dbConfig);
|
||||
}
|
||||
pool = JDBCPool.pool(vertx, dbConfig);
|
||||
CreateTable.createTable(pool, dbConfig.getString("tableClassPath"));
|
||||
promise.complete("init jdbc pool success");
|
||||
|
||||
LOGGER.info("数据库连接初始化: URL=" + url);
|
||||
return CreateTable.createTable(pool, type);
|
||||
}
|
||||
|
||||
private void checkOrCreateDBFile() {
|
||||
LOGGER.info("init sql start");
|
||||
String[] path = url.split("\\./");
|
||||
path[1] = path[1].split(";")[0];
|
||||
path[1] += ".mv.db";
|
||||
File file = new File(path[1]);
|
||||
if (!file.exists()) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
if (file.getParentFile().mkdirs()) {
|
||||
LOGGER.info("mkdirs -> {}", file.getParentFile().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (file.createNewFile()) {
|
||||
LOGGER.info("create file -> {}", file.getAbsolutePath());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(e.getMessage());
|
||||
throw new RuntimeException("file create failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void h2serverExecute(Promise<String> promise) {
|
||||
// 初始化H2db, 创建本地db文件
|
||||
checkOrCreateDBFile();
|
||||
|
||||
try {
|
||||
String url = dbConfig.getString("jdbcUrl");
|
||||
String[] portStr = url.split(":");
|
||||
String port = portStr[portStr.length - 1].split("[/\\\\]")[0];
|
||||
LOGGER.info("H2server listen port to {}", port);
|
||||
H2ServerHolder.init(Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", port).start());
|
||||
promise.complete("Start h2Server success");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Start h2Server failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取连接池
|
||||
*
|
||||
* @return pool
|
||||
*/
|
||||
public JDBCPool getPool() {
|
||||
synchronized public JDBCPool getPool() {
|
||||
return pool;
|
||||
}
|
||||
}
|
||||
|
||||
35
core-database/src/main/java/cn/qaiu/db/pool/JDBCType.java
Normal file
35
core-database/src/main/java/cn/qaiu/db/pool/JDBCType.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package cn.qaiu.db.pool;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* @since 2023/10/10 14:06
|
||||
*/
|
||||
public enum JDBCType {
|
||||
// 添加驱动类型字段
|
||||
MySQL("jdbc:mysql:"),
|
||||
H2DB("jdbc:h2:"),
|
||||
PostgreSQL("jdbc:postgresql:");
|
||||
private final String urlPrefix; // JDBC URL 前缀
|
||||
|
||||
// 构造函数
|
||||
JDBCType(String urlPrefix) {
|
||||
this.urlPrefix = urlPrefix;
|
||||
}
|
||||
|
||||
// 获取 JDBC URL 前缀
|
||||
public String getUrlPrefix() {
|
||||
return urlPrefix;
|
||||
}
|
||||
|
||||
// 根据 JDBC URL 获取 JDBC 类型
|
||||
public static JDBCType getJDBCTypeByURL(String jdbcURL) {
|
||||
for (JDBCType jdbcType : values()) {
|
||||
if (StringUtils.startsWithIgnoreCase(jdbcURL, jdbcType.getUrlPrefix())) {
|
||||
return jdbcType;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("不支持的SQL类型: " + jdbcURL);
|
||||
}
|
||||
}
|
||||
50
core/pom.xml
50
core/pom.xml
@@ -5,41 +5,22 @@
|
||||
<parent>
|
||||
<artifactId>netdisk-fast-download</artifactId>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<version>0.1.3</version>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>1.0.8</version>
|
||||
<artifactId>core</artifactId>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<vertx.version>4.4.1</vertx.version>
|
||||
<org.reflections.version>0.10.2</org.reflections.version>
|
||||
<lombok.version>1.18.12</lombok.version>
|
||||
<slf4j.version>2.0.5</slf4j.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<jackson.version>2.14.2</jackson.version>
|
||||
<maven.build.timestamp.format>yyMMdd_HHmm</maven.build.timestamp.format>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-dependencies</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!--logback日志实现-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.4.6</version>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@@ -80,20 +61,28 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.4</version>
|
||||
</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>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@@ -102,6 +91,13 @@
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<!-- 代码生成器 -->
|
||||
<annotationProcessors>
|
||||
<annotationProcessor>io.vertx.codegen.CodeGenProcessor</annotationProcessor>
|
||||
</annotationProcessors>
|
||||
<generatedSourcesDirectory>
|
||||
${project.basedir}/src/main/generated
|
||||
</generatedSourcesDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package cn.qaiu.vx.core;
|
||||
|
||||
import cn.qaiu.vx.core.util.ConfigConstant;
|
||||
import cn.qaiu.vx.core.util.CommonUtil;
|
||||
import cn.qaiu.vx.core.util.ConfigUtil;
|
||||
import cn.qaiu.vx.core.util.VertxHolder;
|
||||
import cn.qaiu.vx.core.verticle.ReverseProxyVerticle;
|
||||
import cn.qaiu.vx.core.verticle.RouterVerticle;
|
||||
import cn.qaiu.vx.core.verticle.ServiceVerticle;
|
||||
import io.vertx.core.*;
|
||||
import io.vertx.core.dns.AddressResolverOptions;
|
||||
import io.vertx.core.impl.launcher.commands.VersionCommand;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.shareddata.LocalMap;
|
||||
import org.slf4j.Logger;
|
||||
@@ -17,6 +19,8 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.locks.LockSupport;
|
||||
|
||||
import static cn.qaiu.vx.core.util.ConfigConstant.*;
|
||||
|
||||
/**
|
||||
* vertx启动类 需要在主启动类完成回调
|
||||
* <br>Create date 2021-05-07 10:26:54
|
||||
@@ -42,12 +46,17 @@ public final class Deploy {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param args 启动参数
|
||||
* @param handle 启动完成后回调处理函数
|
||||
*/
|
||||
public void start(String[] args, Handler<JsonObject> handle) {
|
||||
this.mainThread = Thread.currentThread();
|
||||
this.handle = handle;
|
||||
if (args.length > 0) {
|
||||
if (args.length > 0 && args[0].startsWith("app-")) {
|
||||
// 启动参数dev或者prod
|
||||
path.append("-").append(args[0]);
|
||||
path.append("-").append(args[0].replace("app-",""));
|
||||
}
|
||||
|
||||
// 读取yml配置
|
||||
@@ -63,7 +72,7 @@ public final class Deploy {
|
||||
var activeMode = conf.getString("active");
|
||||
if ("dev".equals(activeMode)) {
|
||||
LOGGER.info("---------------> development environment <--------------\n");
|
||||
System.setProperty("vertxweb.environment","dev");
|
||||
System.setProperty("vertxweb.environment", "dev");
|
||||
} else {
|
||||
LOGGER.info("---------------> Production environment <--------------\n");
|
||||
}
|
||||
@@ -80,7 +89,7 @@ public final class Deploy {
|
||||
var calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date());
|
||||
var year = calendar.get(Calendar.YEAR);
|
||||
var logoTemplete = """
|
||||
var logoTemplate = """
|
||||
|
||||
Web Server powered by:\s
|
||||
____ ____ _ _ _ \s
|
||||
@@ -93,9 +102,9 @@ public final class Deploy {
|
||||
|
||||
""";
|
||||
|
||||
System.out.printf(logoTemplete,
|
||||
conf.getString("version_app"),
|
||||
conf.getString("version_vertx"),
|
||||
System.out.printf(logoTemplate,
|
||||
CommonUtil.getAppVersion(),
|
||||
VersionCommand.getVersion(),
|
||||
conf.getString("copyright"),
|
||||
year
|
||||
);
|
||||
@@ -107,29 +116,47 @@ public final class Deploy {
|
||||
private void deployVerticle() {
|
||||
tempVertx.close();
|
||||
LOGGER.info("配置读取成功");
|
||||
customConfig = globalConfig.getJsonObject(ConfigConstant.CUSTOM);
|
||||
customConfig = globalConfig.getJsonObject(CUSTOM);
|
||||
|
||||
var vertxOptions = new VertxOptions(globalConfig.getJsonObject(ConfigConstant.VERTX));
|
||||
JsonObject vertxConfig = globalConfig.getJsonObject(VERTX);
|
||||
Integer vertxConfigELPS = vertxConfig.getInteger(EVENT_LOOP_POOL_SIZE);
|
||||
var vertxOptions = vertxConfigELPS == 0 ?
|
||||
new VertxOptions() : new VertxOptions(vertxConfig);
|
||||
|
||||
vertxOptions.setAddressResolverOptions(
|
||||
new AddressResolverOptions().
|
||||
addServer("114.114.114.114").
|
||||
addServer("114.114.115.115").
|
||||
addServer("8.8.8.8").
|
||||
addServer("8.8.4.4"));
|
||||
LOGGER.info("vertxConfigEventLoopPoolSize: {}, eventLoopPoolSize: {}, workerPoolSize: {}", vertxConfigELPS,
|
||||
vertxOptions.getEventLoopPoolSize(),
|
||||
vertxOptions.getWorkerPoolSize());
|
||||
var vertx = Vertx.vertx(vertxOptions);
|
||||
VertxHolder.init(vertx);
|
||||
//配置保存在共享数据中
|
||||
var sharedData = vertx.sharedData();
|
||||
LocalMap<String, Object> localMap = sharedData.getLocalMap(ConfigConstant.LOCAL);
|
||||
localMap.put(ConfigConstant.GLOBAL_CONFIG, globalConfig);
|
||||
localMap.put(ConfigConstant.CUSTOM_CONFIG, customConfig);
|
||||
localMap.put(ConfigConstant.SERVER, globalConfig.getJsonObject(ConfigConstant.SERVER));
|
||||
var future0 = vertx.createSharedWorkerExecutor("other-handle").executeBlocking(bch -> {
|
||||
handle.handle(globalConfig);
|
||||
bch.complete("other handle complete");
|
||||
});
|
||||
LocalMap<String, Object> localMap = sharedData.getLocalMap(LOCAL);
|
||||
localMap.put(GLOBAL_CONFIG, globalConfig);
|
||||
localMap.put(CUSTOM_CONFIG, customConfig);
|
||||
localMap.put(SERVER, globalConfig.getJsonObject(SERVER));
|
||||
var future0 = vertx.createSharedWorkerExecutor("other-handle")
|
||||
.executeBlocking(() -> {
|
||||
handle.handle(globalConfig);
|
||||
return "Other handle complete";
|
||||
});
|
||||
|
||||
var future1 = vertx.deployVerticle(RouterVerticle.class, getWorkDeploymentOptions("Router"));
|
||||
var future2 = vertx.deployVerticle(ServiceVerticle.class, getWorkDeploymentOptions("Service"));
|
||||
var future3 = vertx.deployVerticle(ReverseProxyVerticle.class, getWorkDeploymentOptions("proxy"));
|
||||
future0.onSuccess(res -> {
|
||||
LOGGER.info(res);
|
||||
// 部署 路由、异步service、反向代理 服务
|
||||
var future1 = vertx.deployVerticle(RouterVerticle.class, getWorkDeploymentOptions("Router"));
|
||||
var future2 = vertx.deployVerticle(ServiceVerticle.class, getWorkDeploymentOptions("Service"));
|
||||
var future3 = vertx.deployVerticle(ReverseProxyVerticle.class, getWorkDeploymentOptions("proxy"));
|
||||
|
||||
CompositeFuture.all(future1, future2, future3, future0)
|
||||
.onSuccess(this::deployWorkVerticalSuccess)
|
||||
.onFailure(this::deployVerticalFailed);
|
||||
Future.all(future1, future2, future3)
|
||||
.onSuccess(this::deployWorkVerticalSuccess)
|
||||
.onFailure(this::deployVerticalFailed);
|
||||
}).onFailure(e -> LOGGER.error("Other handle error", e));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,13 +187,13 @@ public final class Deploy {
|
||||
* @return Deployment Options
|
||||
*/
|
||||
private DeploymentOptions getWorkDeploymentOptions(String name) {
|
||||
return getWorkDeploymentOptions(name, customConfig.getInteger(ConfigConstant.ASYNC_SERVICE_INSTANCES));
|
||||
return getWorkDeploymentOptions(name, customConfig.getInteger(ASYNC_SERVICE_INSTANCES));
|
||||
}
|
||||
|
||||
private DeploymentOptions getWorkDeploymentOptions(String name, int ins) {
|
||||
return new DeploymentOptions()
|
||||
.setWorkerPoolName(name)
|
||||
.setWorker(true)
|
||||
.setThreadingModel(ThreadingModel.WORKER)
|
||||
.setInstances(ins);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.qaiu.vx.core.annotaions;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Documented
|
||||
@Inherited
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface HandleSortFilter {
|
||||
/**
|
||||
* 注册顺序,数字越大越先注册<br>
|
||||
* 值<0时会过滤掉该处理器
|
||||
*/
|
||||
int value() default 0;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.qaiu.vx.core.annotaions;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 拦截器配置注解
|
||||
* 正则匹配拦截途径
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@Documented
|
||||
@Inherited
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface InterceptorConfig {
|
||||
|
||||
String pattern() default "";
|
||||
|
||||
/**
|
||||
* 注册顺序,数字越大越先注册
|
||||
*/
|
||||
int order() default 0;
|
||||
}
|
||||
@@ -1,9 +1,16 @@
|
||||
package cn.qaiu.vx.core.base;
|
||||
|
||||
import cn.qaiu.vx.core.interceptor.AfterInterceptor;
|
||||
import cn.qaiu.vx.core.model.JsonResult;
|
||||
import cn.qaiu.vx.core.util.CommonUtil;
|
||||
import cn.qaiu.vx.core.util.ReflectionUtil;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import static io.vertx.core.http.HttpHeaders.CONTENT_TYPE;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.qaiu.vx.core.util.ResponseUtil.*;
|
||||
|
||||
/**
|
||||
* 统一响应处理
|
||||
@@ -13,22 +20,43 @@ import static io.vertx.core.http.HttpHeaders.CONTENT_TYPE;
|
||||
*/
|
||||
public interface BaseHttpApi {
|
||||
|
||||
default void fireJsonResponse(RoutingContext ctx, JsonObject jsonResult) {
|
||||
ctx.response().putHeader(CONTENT_TYPE, "application/json; charset=utf-8")
|
||||
.setStatusCode(200)
|
||||
.end(jsonResult.encode());
|
||||
// 需要扫描注册的Router路径
|
||||
Reflections reflections = ReflectionUtil.getReflections();
|
||||
|
||||
default void doFireJsonObjectResponse(RoutingContext ctx, JsonObject jsonObject) {
|
||||
if (!ctx.response().ended()) {
|
||||
fireJsonObjectResponse(ctx, jsonObject);
|
||||
}
|
||||
handleAfterInterceptor(ctx, jsonObject);
|
||||
}
|
||||
|
||||
default <T> void fireJsonResponse(RoutingContext ctx, T jsonResult) {
|
||||
JsonObject jsonObject = JsonObject.mapFrom(jsonResult);
|
||||
fireJsonResponse(ctx, jsonObject);
|
||||
|
||||
default <T> void doFireJsonResultResponse(RoutingContext ctx, JsonResult<T> jsonResult) {
|
||||
if (!ctx.response().ended()) {
|
||||
fireJsonResultResponse(ctx, jsonResult);
|
||||
}
|
||||
handleAfterInterceptor(ctx, jsonResult.toJsonObject());
|
||||
}
|
||||
|
||||
default void fireTextResponse(RoutingContext ctx, String text) {
|
||||
ctx.response().putHeader("content-type", "text/html; charset=utf-8").end(text);
|
||||
|
||||
default Set<AfterInterceptor> getAfterInterceptor() {
|
||||
|
||||
Set<Class<? extends AfterInterceptor>> afterInterceptorClassSet =
|
||||
reflections.getSubTypesOf(AfterInterceptor.class);
|
||||
if (afterInterceptorClassSet == null) {
|
||||
return null;
|
||||
}
|
||||
return CommonUtil.sortClassSet(afterInterceptorClassSet);
|
||||
}
|
||||
|
||||
default void sendError(int statusCode, RoutingContext ctx) {
|
||||
ctx.response().setStatusCode(statusCode).end();
|
||||
default void handleAfterInterceptor(RoutingContext ctx, JsonObject jsonObject) {
|
||||
Set<AfterInterceptor> afterInterceptor = getAfterInterceptor();
|
||||
if (afterInterceptor != null) {
|
||||
afterInterceptor.forEach(ai -> ai.handle(ctx, jsonObject));
|
||||
}
|
||||
if (!ctx.response().ended()) {
|
||||
fireTextResponse(ctx, "handleAfterInterceptor: response not end");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@ import cn.qaiu.vx.core.annotaions.RouteHandler;
|
||||
import cn.qaiu.vx.core.annotaions.RouteMapping;
|
||||
import cn.qaiu.vx.core.annotaions.SockRouteMapper;
|
||||
import cn.qaiu.vx.core.base.BaseHttpApi;
|
||||
import cn.qaiu.vx.core.enums.MIMEType;
|
||||
import cn.qaiu.vx.core.interceptor.BeforeInterceptor;
|
||||
import cn.qaiu.vx.core.model.JsonResult;
|
||||
import cn.qaiu.vx.core.util.*;
|
||||
import io.netty.handler.codec.http.HttpHeaderValues;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.MultiMap;
|
||||
@@ -19,25 +20,27 @@ import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.Route;
|
||||
import io.vertx.ext.web.Router;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
import io.vertx.ext.web.handler.BodyHandler;
|
||||
import io.vertx.ext.web.handler.CorsHandler;
|
||||
import io.vertx.ext.web.handler.*;
|
||||
import io.vertx.ext.web.handler.sockjs.SockJSHandler;
|
||||
import io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions;
|
||||
import javassist.CtClass;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.reflections.Reflections;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static cn.qaiu.vx.core.util.ConfigConstant.ROUTE_TIME_OUT;
|
||||
import static cn.qaiu.vx.core.verticle.ReverseProxyVerticle.REROUTE_PATH_PREFIX;
|
||||
import static io.vertx.core.http.HttpHeaders.*;
|
||||
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE_TIME;
|
||||
|
||||
/**
|
||||
* 路由映射, 参数绑定
|
||||
@@ -56,15 +59,11 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
add(HttpMethod.DELETE);
|
||||
add(HttpMethod.HEAD);
|
||||
}};
|
||||
// 需要扫描注册的Router路径
|
||||
private static volatile Reflections reflections;
|
||||
|
||||
private final String gatewayPrefix;
|
||||
|
||||
public RouterHandlerFactory(String routerScanAddress, String gatewayPrefix) {
|
||||
Objects.requireNonNull(routerScanAddress, "The router package address scan is empty.");
|
||||
public RouterHandlerFactory(String gatewayPrefix) {
|
||||
Objects.requireNonNull(gatewayPrefix, "The gateway prefix is empty.");
|
||||
reflections = ReflectionUtil.getReflections(routerScanAddress);
|
||||
this.gatewayPrefix = gatewayPrefix;
|
||||
}
|
||||
|
||||
@@ -72,22 +71,37 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
* 开始扫描并注册handler
|
||||
*/
|
||||
public Router createRouter() {
|
||||
Router router = Router.router(VertxHolder.getVertxInstance());
|
||||
router.route().handler(ctx -> {
|
||||
// 主路由
|
||||
Router mainRouter = Router.router(VertxHolder.getVertxInstance());
|
||||
mainRouter.route().handler(ctx -> {
|
||||
String realPath = ctx.request().uri();;
|
||||
if (realPath.startsWith(REROUTE_PATH_PREFIX)) {
|
||||
// vertx web proxy暂不支持rewrite, 所以这里进行手动替换, 请求地址中的请求path前缀替换为originPath
|
||||
String rePath = realPath.substring(REROUTE_PATH_PREFIX.length());
|
||||
ctx.reroute(rePath);
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.debug("The HTTP service request address information ===>path:{}, uri:{}, method:{}",
|
||||
ctx.request().path(), ctx.request().absoluteURI(), ctx.request().method());
|
||||
ctx.response().headers().add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
|
||||
ctx.response().headers().add(DATE, LocalDateTime.now().format(ISO_LOCAL_DATE_TIME));
|
||||
ctx.response().headers().add(ACCESS_CONTROL_ALLOW_METHODS, "POST, GET, OPTIONS, PUT, DELETE, HEAD");
|
||||
ctx.response().headers().add(ACCESS_CONTROL_ALLOW_HEADERS, "X-PINGOTHER, Origin,Content-Type, Accept, X-Requested-With, Dev, Authorization, Version, Token");
|
||||
ctx.response().headers().add(ACCESS_CONTROL_ALLOW_HEADERS, "X-PINGOTHER, Origin,Content-Type, Accept, " +
|
||||
"X-Requested-With, Dev, Authorization, Version, Token");
|
||||
ctx.response().headers().add(ACCESS_CONTROL_MAX_AGE, "1728000");
|
||||
ctx.next();
|
||||
});
|
||||
// 添加跨域的方法
|
||||
router.route().handler(CorsHandler.create().addRelativeOrigin(".*").allowCredentials(true).allowedMethods(httpMethods));
|
||||
mainRouter.route().handler(CorsHandler.create().addRelativeOrigin(".*").allowCredentials(true).allowedMethods(httpMethods));
|
||||
|
||||
// 配置文件上传路径
|
||||
router.route().handler(BodyHandler.create().setUploadsDirectory("uploads"));
|
||||
mainRouter.route().handler(BodyHandler.create().setUploadsDirectory("uploads"));
|
||||
|
||||
// 拦截器
|
||||
Set<Handler<RoutingContext>> interceptorSet = getInterceptorSet();
|
||||
Route route0 = mainRouter.route("/*");
|
||||
interceptorSet.forEach(route0::handler);
|
||||
|
||||
try {
|
||||
Set<Class<?>> handlers = reflections.getTypesAnnotatedWith(RouteHandler.class);
|
||||
@@ -101,7 +115,7 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
for (Class<?> handler : sortedHandlers) {
|
||||
try {
|
||||
// 注册请求处理方法
|
||||
registerNewHandler(router, handler);
|
||||
registerNewHandler(mainRouter, handler);
|
||||
} catch (Throwable e) {
|
||||
LOGGER.error("Error register {}, Error details:", handler, e.getCause());
|
||||
|
||||
@@ -111,11 +125,12 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
LOGGER.error("Manually Register Handler Fail, Error details:" + e.getMessage());
|
||||
}
|
||||
// 错误请求处理
|
||||
router.errorHandler(405, ctx -> fireJsonResponse(ctx, JsonResult
|
||||
mainRouter.errorHandler(405, ctx -> doFireJsonResultResponse(ctx, JsonResult
|
||||
.error("Method Not Allowed", 405)));
|
||||
router.errorHandler(404, ctx -> ctx.response().setStatusCode(404).setChunked(true)
|
||||
mainRouter.errorHandler(404, ctx -> ctx.response().setStatusCode(404).setChunked(true)
|
||||
.end("Internal server error: 404 not found"));
|
||||
return router;
|
||||
|
||||
return mainRouter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,15 +154,13 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
method -> method.isAnnotationPresent(SockRouteMapper.class)
|
||||
).toList());
|
||||
|
||||
// 拦截器
|
||||
Handler<RoutingContext> interceptor = getInterceptor();
|
||||
// 依次注册处理方法
|
||||
for (Method method : methodList) {
|
||||
if (method.isAnnotationPresent(RouteMapping.class)) {
|
||||
// 普通路由
|
||||
RouteMapping mapping = method.getAnnotation(RouteMapping.class);
|
||||
HttpMethod routeMethod = HttpMethod.valueOf(mapping.method().name());
|
||||
String routeUrl = getRouteUrl(method.getName(), mapping.value());
|
||||
String routeUrl = getRouteUrl(mapping.value());
|
||||
String url = root.concat(routeUrl);
|
||||
// 匹配方法
|
||||
Route route = router.route(routeMethod, url);
|
||||
@@ -157,17 +170,23 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
route.consumes(mineType);
|
||||
}
|
||||
|
||||
// 先执行拦截方法, 再进入业务请求
|
||||
route.handler(interceptor);
|
||||
// 设置默认超时
|
||||
route.handler(TimeoutHandler.create(SharedDataUtil.getCustomConfig().getInteger(ROUTE_TIME_OUT)));
|
||||
route.handler(ResponseTimeHandler.create());
|
||||
route.handler(ctx -> handlerMethod(instance, method, ctx)).failureHandler(ctx -> {
|
||||
if (ctx.response().ended()) return;
|
||||
ctx.failure().printStackTrace();
|
||||
fireJsonResponse(ctx, JsonResult.error(ctx.failure().getMessage(), 500));
|
||||
// 超时处理器状态码503
|
||||
if (ctx.statusCode() == 503 || ctx.failure() == null) {
|
||||
doFireJsonResultResponse(ctx, JsonResult.error("未知异常, 请联系管理员", 500));
|
||||
} else {
|
||||
ctx.failure().printStackTrace();
|
||||
doFireJsonResultResponse(ctx, JsonResult.error(ctx.failure().getMessage(), 500));
|
||||
}
|
||||
});
|
||||
} else if (method.isAnnotationPresent(SockRouteMapper.class)) {
|
||||
// websocket 基于sockJs
|
||||
SockRouteMapper mapping = method.getAnnotation(SockRouteMapper.class);
|
||||
String routeUrl = getRouteUrl(method.getName(), mapping.value());
|
||||
String routeUrl = getRouteUrl(mapping.value());
|
||||
String url = root.concat(routeUrl);
|
||||
LOGGER.info("Register New Websocket Handler -> {}", url);
|
||||
SockJSHandlerOptions options = new SockJSHandlerOptions()
|
||||
@@ -194,13 +213,12 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
/**
|
||||
* 获取并处理路由URL分隔符
|
||||
*
|
||||
* @param methodName 路由method
|
||||
* @return String
|
||||
*/
|
||||
private String getRouteUrl(String methodName, String mapperValue) {
|
||||
private String getRouteUrl(String mapperValue) {
|
||||
String routeUrl;
|
||||
if (mapperValue.startsWith("/:") || "/".equals(mapperValue)) {
|
||||
routeUrl = (methodName + mapperValue);
|
||||
if ("/".equals(mapperValue)) {
|
||||
routeUrl = mapperValue;
|
||||
} else if (mapperValue.startsWith("/")) {
|
||||
routeUrl = mapperValue.substring(1);
|
||||
} else {
|
||||
@@ -213,15 +231,10 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
* 配置拦截
|
||||
*
|
||||
* @return Handler
|
||||
* @throws Throwable Throwable
|
||||
*/
|
||||
private Handler<RoutingContext> getInterceptor() throws Throwable {
|
||||
private Set<Handler<RoutingContext>> getInterceptorSet() {
|
||||
// 配置拦截
|
||||
Class<?> interceptorClass = Class.forName(SharedDataUtil.getValueForCustomConfig("interceptorClassPath"));
|
||||
Object handleInstance = ReflectionUtil.newWithNoParam(interceptorClass);
|
||||
Method doHandle = interceptorClass.getMethod("doHandle");
|
||||
// 反射调用
|
||||
return CastUtil.cast(ReflectionUtil.invoke(doHandle, handleInstance));
|
||||
return getBeforeInterceptor().stream().map(BeforeInterceptor::doHandle).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,7 +256,7 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
if (handler.isAnnotationPresent(RouteHandler.class)) {
|
||||
RouteHandler routeHandler = handler.getAnnotation(RouteHandler.class);
|
||||
String value = routeHandler.value();
|
||||
root += ("/".equals(value) ? "" : value);
|
||||
root += (value.startsWith("/") ? value.substring(1) : value);
|
||||
}
|
||||
if (!root.endsWith("/")) {
|
||||
root = root + "/";
|
||||
@@ -286,37 +299,12 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
});
|
||||
}
|
||||
|
||||
final MultiMap queryParams = ctx.queryParams();
|
||||
if ("POST".equals(ctx.request().method().name())) {
|
||||
queryParams.addAll(ctx.request().params());
|
||||
}
|
||||
|
||||
JsonArray entityPackagesReg = SharedDataUtil.getJsonArrayForCustomConfig("entityPackagesReg");
|
||||
// 绑定get或post请求头的请求参数
|
||||
methodParametersTemp.forEach((k, v) -> {
|
||||
if (ReflectionUtil.isBasicType(v.getRight())) {
|
||||
String fmt = getFmt(v.getLeft(), v.getRight());
|
||||
String value = queryParams.get(k);
|
||||
parameterValueList.put(k, ReflectionUtil.conversion(v.getRight(), value, fmt));
|
||||
} else if (RoutingContext.class.getName().equals(v.getRight().getName())) {
|
||||
parameterValueList.put(k, ctx);
|
||||
} else if (HttpServerRequest.class.getName().equals(v.getRight().getName())) {
|
||||
parameterValueList.put(k, ctx.request());
|
||||
} else if (HttpServerResponse.class.getName().equals(v.getRight().getName())) {
|
||||
parameterValueList.put(k, ctx.response());
|
||||
} else if (CommonUtil.matchRegList(entityPackagesReg.getList(), v.getRight().getName())) {
|
||||
// 绑定实体类
|
||||
try {
|
||||
Class<?> aClass = Class.forName(v.getRight().getName());
|
||||
Object entity = ParamUtil.multiMapToEntity(queryParams, aClass);
|
||||
parameterValueList.put(k, entity);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
final MultiMap queryParams = ctx.queryParams();
|
||||
// 解析body-json参数
|
||||
if ("application/json".equals(ctx.parsedHeaders().contentType().value()) && ctx.body().asJsonObject() != null) {
|
||||
if (HttpHeaderValues.APPLICATION_JSON.toString().equals(ctx.parsedHeaders().contentType().value())
|
||||
&& ctx.body().asJsonObject() != null) {
|
||||
JsonObject body = ctx.body().asJsonObject();
|
||||
if (body != null) {
|
||||
methodParametersTemp.forEach((k, v) -> {
|
||||
@@ -336,26 +324,66 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (ctx.body() != null) {
|
||||
queryParams.addAll(ParamUtil.paramsToMap(ctx.body().asString()));
|
||||
}
|
||||
|
||||
// 解析其他参数
|
||||
if ("POST".equals(ctx.request().method().name())) {
|
||||
queryParams.addAll(ctx.request().params());
|
||||
}
|
||||
// 绑定get或post请求头的请求参数
|
||||
methodParametersTemp.forEach((k, v) -> {
|
||||
if (ReflectionUtil.isBasicType(v.getRight())) {
|
||||
String fmt = getFmt(v.getLeft(), v.getRight());
|
||||
String value = queryParams.get(k);
|
||||
parameterValueList.put(k, ReflectionUtil.conversion(v.getRight(), value, fmt));
|
||||
} else if (RoutingContext.class.getName().equals(v.getRight().getName())) {
|
||||
parameterValueList.put(k, ctx);
|
||||
} else if (HttpServerRequest.class.getName().equals(v.getRight().getName())) {
|
||||
parameterValueList.put(k, ctx.request());
|
||||
} else if (HttpServerResponse.class.getName().equals(v.getRight().getName())) {
|
||||
parameterValueList.put(k, ctx.response());
|
||||
} else if (parameterValueList.get(k) == null
|
||||
&& CommonUtil.matchRegList(entityPackagesReg.getList(), v.getRight().getName())) {
|
||||
// 绑定实体类
|
||||
try {
|
||||
Class<?> aClass = Class.forName(v.getRight().getName());
|
||||
Object entity = ParamUtil.multiMapToEntity(queryParams, aClass);
|
||||
parameterValueList.put(k, entity);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
// 调用handle 获取响应对象
|
||||
Object[] parameterValueArray = parameterValueList.values().toArray(new Object[0]);
|
||||
try {
|
||||
// 反射调用
|
||||
Object data = ReflectionUtil.invokeWithArguments(method, instance, parameterValueArray);
|
||||
if (data != null) {
|
||||
|
||||
if (data instanceof JsonResult) {
|
||||
fireJsonResponse(ctx, data);
|
||||
doFireJsonResultResponse(ctx, (JsonResult<?>) data);
|
||||
}
|
||||
if (data instanceof JsonObject) {
|
||||
doFireJsonObjectResponse(ctx, ((JsonObject) data));
|
||||
} else if (data instanceof Future) { // 处理异步响应
|
||||
((Future<?>) data).onSuccess(res -> {
|
||||
if (res instanceof JsonObject) {
|
||||
fireJsonResponse(ctx, res);
|
||||
} else if (res != null){
|
||||
fireJsonResponse(ctx, JsonResult.data(res));
|
||||
if (res instanceof JsonResult) {
|
||||
doFireJsonResultResponse(ctx, (JsonResult<?>) res);
|
||||
}
|
||||
}).onFailure(e -> fireJsonResponse(ctx, JsonResult.error(e.getMessage())));
|
||||
if (res instanceof JsonObject) {
|
||||
doFireJsonObjectResponse(ctx, ((JsonObject) res));
|
||||
} else if (res != null) {
|
||||
doFireJsonResultResponse(ctx, JsonResult.data(res));
|
||||
} else {
|
||||
handleAfterInterceptor(ctx, null);
|
||||
}
|
||||
|
||||
}).onFailure(e -> doFireJsonResultResponse(ctx, JsonResult.error(e.getMessage())));
|
||||
} else {
|
||||
ctx.response().headers().set(CONTENT_TYPE, MIMEType.TEXT_HTML.getValue());
|
||||
ctx.end(data.toString());
|
||||
doFireJsonResultResponse(ctx, JsonResult.data(data));
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
@@ -363,12 +391,12 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
String err = e.getMessage();
|
||||
if (e.getCause() != null) {
|
||||
if (e.getCause() instanceof InvocationTargetException) {
|
||||
err = ((InvocationTargetException)e.getCause()).getTargetException().getMessage();
|
||||
err = ((InvocationTargetException) e.getCause()).getTargetException().getMessage();
|
||||
} else {
|
||||
err = e.getCause().getMessage();
|
||||
}
|
||||
}
|
||||
fireJsonResponse(ctx, JsonResult.error(err));
|
||||
doFireJsonResultResponse(ctx, JsonResult.error(err));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -386,4 +414,13 @@ public class RouterHandlerFactory implements BaseHttpApi {
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
private Set<BeforeInterceptor> getBeforeInterceptor() {
|
||||
Set<Class<? extends BeforeInterceptor>> interceptorClassSet =
|
||||
reflections.getSubTypesOf(BeforeInterceptor.class);
|
||||
if (interceptorClassSet == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return CommonUtil.sortClassSet(interceptorClassSet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.qaiu.vx.core.interceptor;
|
||||
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
|
||||
/**
|
||||
* 后置拦截器接口
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public interface AfterInterceptor {
|
||||
|
||||
void handle(RoutingContext ctx, JsonObject responseData);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package cn.qaiu.vx.core.interceptor;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
|
||||
import static cn.qaiu.vx.core.util.ResponseUtil.sendError;
|
||||
|
||||
/**
|
||||
* 前置拦截器接口
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public interface BeforeInterceptor extends Handler<RoutingContext> {
|
||||
String IS_NEXT = "RoutingContextIsNext";
|
||||
|
||||
default Handler<RoutingContext> doHandle() {
|
||||
|
||||
return ctx -> {
|
||||
// 加同步锁
|
||||
synchronized (BeforeInterceptor.class) {
|
||||
ctx.put(IS_NEXT, false);
|
||||
BeforeInterceptor.this.handle(ctx);
|
||||
if (!(Boolean) ctx.get(IS_NEXT) && !ctx.response().ended()) {
|
||||
sendError(ctx, 403);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
default void doNext(RoutingContext context) {
|
||||
// 设置上下文状态为可以继续执行
|
||||
// 添加同步锁保障多线程下执行时序
|
||||
synchronized (BeforeInterceptor.class) {
|
||||
context.put(IS_NEXT, true);
|
||||
context.next();
|
||||
}
|
||||
}
|
||||
|
||||
void handle(RoutingContext context);
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package cn.qaiu.vx.core.interceptor;
|
||||
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
|
||||
/**
|
||||
* 拦截器接口
|
||||
* <br>Create date 2021-05-06 09:20:37
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
public interface Interceptor {
|
||||
|
||||
default Handler<RoutingContext> doHandle() {
|
||||
return this::handle;
|
||||
}
|
||||
|
||||
void handle(RoutingContext context);
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
package cn.qaiu.vx.core.model;
|
||||
|
||||
|
||||
import cn.qaiu.vx.core.util.CastUtil;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
@@ -13,6 +17,7 @@ import java.io.Serializable;
|
||||
*/
|
||||
public class JsonResult<T> implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final int SUCCESS_CODE = 200;
|
||||
@@ -25,12 +30,10 @@ public class JsonResult<T> implements Serializable {
|
||||
|
||||
private int code = SUCCESS_CODE;//状态码
|
||||
|
||||
private String msg = SUCCESS_MESSAGE;//消息
|
||||
private String msg = SUCCESS_MESSAGE; //消息
|
||||
|
||||
private boolean success = true; //是否成功
|
||||
|
||||
private int count;
|
||||
|
||||
private T data;
|
||||
|
||||
private long timestamp = System.currentTimeMillis(); //时间戳
|
||||
@@ -49,20 +52,6 @@ public class JsonResult<T> implements Serializable {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public JsonResult(int code, String msg, boolean success, T data, int count) {
|
||||
this(code, msg, success, data);
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public JsonResult<T> setCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
@@ -131,20 +120,9 @@ public class JsonResult<T> implements Serializable {
|
||||
return new JsonResult<>(SUCCESS_CODE, msg, true, data);
|
||||
}
|
||||
|
||||
// 响应成功消息和数据实体
|
||||
public static <T> JsonResult<T> data(String msg, T data, int count) {
|
||||
if (StringUtils.isEmpty(msg)) msg = SUCCESS_MESSAGE;
|
||||
return new JsonResult<>(SUCCESS_CODE, msg, true, data, count);
|
||||
}
|
||||
|
||||
// 响应数据实体
|
||||
public static <T> JsonResult<T> data(T data) {
|
||||
return new JsonResult<>(SUCCESS_CODE, SUCCESS_MESSAGE, true, data, 0);
|
||||
}
|
||||
|
||||
// 响应数据实体
|
||||
public static <T> JsonResult<T> data(T data, int count) {
|
||||
return new JsonResult<>(SUCCESS_CODE, SUCCESS_MESSAGE, true, data, count);
|
||||
return new JsonResult<>(SUCCESS_CODE, SUCCESS_MESSAGE, true, data);
|
||||
}
|
||||
|
||||
// 响应成功消息
|
||||
@@ -157,4 +135,16 @@ public class JsonResult<T> implements Serializable {
|
||||
public static <T> JsonResult<T> success() {
|
||||
return new JsonResult<>(SUCCESS_CODE, SUCCESS_MESSAGE, true, null);
|
||||
}
|
||||
|
||||
// 转为json对象
|
||||
public JsonObject toJsonObject() {
|
||||
return JsonObject.mapFrom(this);
|
||||
}
|
||||
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
// 转为json对象
|
||||
public static JsonResult<?> toJsonResult(JsonObject json) {
|
||||
return CastUtil.cast(json.mapTo(JsonResult.class));
|
||||
}
|
||||
}
|
||||
|
||||
7
core/src/main/java/cn/qaiu/vx/core/package-info.java
Normal file
7
core/src/main/java/cn/qaiu/vx/core/package-info.java
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* ModuleGen cn.qaiu.vx.core
|
||||
*/
|
||||
@ModuleGen(name = "vertx-http-proxy", groupPackage = "cn.qaiu.vx.core", useFutures = true)
|
||||
package cn.qaiu.vx.core;
|
||||
|
||||
import io.vertx.codegen.annotations.ModuleGen;
|
||||
@@ -1,9 +1,8 @@
|
||||
package cn.qaiu.vx.core.util;
|
||||
|
||||
import cn.qaiu.vx.core.annotaions.HandleSortFilter;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.apache.commons.beanutils.Converter;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -15,6 +14,9 @@ import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* CommonUtil
|
||||
@@ -70,10 +72,11 @@ public class CommonUtil {
|
||||
} catch (UnknownHostException e) {
|
||||
return false;
|
||||
}
|
||||
try(Socket ignored = new Socket(Address, port)) {
|
||||
//建立一个Socket连接
|
||||
try (Socket ignored = new Socket(Address, port)) {
|
||||
//建立一个Socket连接
|
||||
flag = true;
|
||||
} catch (IOException ignoredException) {}
|
||||
} catch (IOException ignoredException) {
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
@@ -95,23 +98,6 @@ public class CommonUtil {
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册枚举转换器
|
||||
*
|
||||
* @param enums 枚举类
|
||||
*/
|
||||
@SafeVarargs
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public static void enumConvert(Class<? extends Enum>... enums) {
|
||||
for (Class<? extends Enum> anEnum : enums) {
|
||||
ConvertUtils.register(new Converter() {
|
||||
public Object convert(Class type, Object value) {
|
||||
return Enum.valueOf(anEnum, (String) value);
|
||||
}
|
||||
}, anEnum);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理其他配置
|
||||
*
|
||||
@@ -126,4 +112,49 @@ public class CommonUtil {
|
||||
LocalConstant.put(configName, map);
|
||||
LOGGER.info("读取配置{}成功", configName);
|
||||
}
|
||||
|
||||
public static <T> Set<T> sortClassSet(Set<Class<? extends T>> set) {
|
||||
return set.stream().filter(c1 -> {
|
||||
HandleSortFilter s1 = c1.getAnnotation(HandleSortFilter.class);
|
||||
if (s1 != null) {
|
||||
return s1.value() > 0;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}).sorted((c1, c2) -> {
|
||||
HandleSortFilter s1 = c1.getAnnotation(HandleSortFilter.class);
|
||||
HandleSortFilter s2 = c2.getAnnotation(HandleSortFilter.class);
|
||||
int n1 = 0, n2 = 0;
|
||||
if (s1 != null) {
|
||||
n1 = s1.value();
|
||||
}
|
||||
if (s2 != null) {
|
||||
n2 = s2.value();
|
||||
}
|
||||
return n1 - n2;
|
||||
}).map(c -> {
|
||||
try {
|
||||
return ReflectionUtil.newWithNoParam(c);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static String appVersion;
|
||||
|
||||
public static String getAppVersion() {
|
||||
if (null == appVersion) {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(CommonUtil.class.getClassLoader().getResourceAsStream("app.properties"));
|
||||
if (!properties.isEmpty()) {
|
||||
appVersion = properties.getProperty("app.version") + "build" + properties.getProperty("build");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return appVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,21 @@ package cn.qaiu.vx.core.util;
|
||||
public interface ConfigConstant {
|
||||
String CUSTOM = "custom";
|
||||
String VERTX = "vertx";
|
||||
String EVENT_LOOP_POOL_SIZE = "eventLoopPoolSize";
|
||||
String LOCAL = "local";
|
||||
String SERVER = "server";
|
||||
String CACHE = "cache";
|
||||
|
||||
String PROXY_SERVER = "proxy-server";
|
||||
|
||||
String PROXY = "proxy";
|
||||
|
||||
String AUTHS = "auths";
|
||||
String GLOBAL_CONFIG = "globalConfig";
|
||||
String CUSTOM_CONFIG = "customConfig";
|
||||
String ASYNC_SERVICE_INSTANCES = "asyncServiceInstances";
|
||||
String IGNORES_REG="ignoresReg";
|
||||
String BASE_LOCATIONS="baseLocations";
|
||||
|
||||
String ROUTE_TIME_OUT="routeTimeOut";
|
||||
}
|
||||
|
||||
46
core/src/main/java/cn/qaiu/vx/core/util/JacksonConfig.java
Normal file
46
core/src/main/java/cn/qaiu/vx/core/util/JacksonConfig.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package cn.qaiu.vx.core.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||
import io.vertx.core.json.jackson.DatabindCodec;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* @date 2023/10/14 9:07
|
||||
*/
|
||||
public class JacksonConfig {
|
||||
|
||||
static {
|
||||
// 通过该方法对mapper对象进行设置,所有序列化的对象都将按改规则进行系列化
|
||||
// Include.Include.ALWAYS 默认
|
||||
// Include.NON_DEFAULT 属性为默认值不序列化
|
||||
// Include.NON_EMPTY 属性为 空("") 或者为 NULL 都不序列化,则返回的json是没有这个字段的。这样对移动端会更省流量
|
||||
// Include.NON_NULL 属性为NULL 不序列化,就是为null的字段不参加序列化
|
||||
// objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
ObjectMapper objectMapper = DatabindCodec.mapper();
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class,
|
||||
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||
javaTimeModule.addDeserializer(LocalDate.class,
|
||||
new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
||||
javaTimeModule.addDeserializer(LocalTime.class,
|
||||
new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
|
||||
objectMapper.registerModule(javaTimeModule);
|
||||
LoggerFactory.getLogger(JacksonConfig.class).info("Global JacksonConfig complete.");
|
||||
}
|
||||
|
||||
public static void nothing() {}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
package cn.qaiu.vx.core.util;
|
||||
|
||||
import io.vertx.core.MultiMap;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -18,28 +17,37 @@ import java.util.Map;
|
||||
public final class ParamUtil {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ParamUtil.class);
|
||||
|
||||
public static Map<String, String> multiMapToMap(MultiMap multiMap) {
|
||||
public static Map<String, Object> multiMapToMap(MultiMap multiMap) {
|
||||
if (multiMap == null) return null;
|
||||
Map<String, String> map = new HashMap<>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (Map.Entry<String, String> entry : multiMap.entries()) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static <T> T multiMapToEntity(MultiMap multiMap,Class<T> tClass) throws NoSuchMethodException {
|
||||
Map<String,String> map = multiMapToMap(multiMap);
|
||||
T obj = null;
|
||||
try {
|
||||
obj = tClass.getDeclaredConstructor().newInstance();
|
||||
BeanUtils.populate(obj,map);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("实例化异常");
|
||||
} catch (InvocationTargetException e2) {
|
||||
e2.printStackTrace();
|
||||
LOGGER.error("map2bean转换异常");
|
||||
public static <T> T multiMapToEntity(MultiMap multiMap, Class<T> tClass) {
|
||||
Map<String, Object> map = multiMapToMap(multiMap);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return obj;
|
||||
return new JsonObject(map).mapTo(tClass);
|
||||
}
|
||||
|
||||
public static MultiMap paramsToMap(String paramString) {
|
||||
MultiMap entries = MultiMap.caseInsensitiveMultiMap();
|
||||
if (paramString == null) return entries;
|
||||
String[] params = paramString.split("&");
|
||||
if (params.length == 0) return entries;
|
||||
for (String param : params) {
|
||||
String[] kv = param.split("=");
|
||||
if (kv.length == 2) {
|
||||
entries.set(kv[0], kv[1]);
|
||||
} else {
|
||||
entries.set(kv[0], "");
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ import javassist.bytecode.AccessFlag;
|
||||
import javassist.bytecode.CodeAttribute;
|
||||
import javassist.bytecode.LocalVariableAttribute;
|
||||
import javassist.bytecode.MethodInfo;
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.*;
|
||||
import org.reflections.scanners.MemberUsageScanner;
|
||||
import org.reflections.scanners.MethodParameterNamesScanner;
|
||||
import org.reflections.scanners.Scanners;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.reflections.util.FilterBuilder;
|
||||
@@ -24,6 +25,8 @@ import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.qaiu.vx.core.util.ConfigConstant.BASE_LOCATIONS;
|
||||
|
||||
/**
|
||||
* 基于org.reflection和javassist的反射工具包
|
||||
* 通过包扫描实现路由地址的注解映射
|
||||
@@ -33,6 +36,16 @@ import java.util.*;
|
||||
*/
|
||||
public final class ReflectionUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 以默认配置的基础包路径获取反射器
|
||||
*
|
||||
* @return Reflections object
|
||||
*/
|
||||
public static Reflections getReflections() {
|
||||
return getReflections(SharedDataUtil.getStringForCustomConfig(BASE_LOCATIONS));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取反射器
|
||||
*
|
||||
@@ -48,6 +61,7 @@ public final class ReflectionUtil {
|
||||
} else {
|
||||
packageAddressList = Collections.singletonList(packageAddress);
|
||||
}
|
||||
|
||||
return getReflections(packageAddressList);
|
||||
}
|
||||
|
||||
@@ -70,11 +84,12 @@ public final class ReflectionUtil {
|
||||
// 发现注解api层 没有继承父类时 这里反射一直有问题(Scanner SubTypesScanner was not configured)
|
||||
// 因此这里需要手动配置各种Scanner扫描器 -- https://blog.csdn.net/qq_29499107/article/details/106889781
|
||||
configurationBuilder.setScanners(
|
||||
new SubTypesScanner(false), //允许getAllTypes获取所有Object的子类, 不设置为false则 getAllTypes 会报错.默认为true.
|
||||
Scanners.SubTypes.filterResultsBy(s -> true), //允许getAllTypes获取所有Object的子类, 不设置为false则 getAllTypes
|
||||
// 会报错.默认为true.
|
||||
new MethodParameterNamesScanner(), //设置方法参数名称 扫描器,否则调用getConstructorParamNames 会报错
|
||||
new MethodAnnotationsScanner(), //设置方法注解 扫描器, 否则getConstructorsAnnotatedWith,getMethodsAnnotatedWith 会报错
|
||||
new MemberUsageScanner(), //设置 member 扫描器,否则 getMethodUsage 会报错, 不推荐使用,有可能会报错 Caused by: java.lang.ClassCastException: javassist.bytecode.InterfaceMethodrefInfo cannot be cast to javassist.bytecode.MethodrefInfo
|
||||
new TypeAnnotationsScanner() //设置类注解 扫描器 ,否则 getTypesAnnotatedWith 会报错
|
||||
Scanners.MethodsAnnotated, //设置方法注解 扫描器, 否则getConstructorsAnnotatedWith,getMethodsAnnotatedWith 会报错
|
||||
new MemberUsageScanner(), //设置 member 扫描器,否则 getMethodUsage 会报错
|
||||
Scanners.TypesAnnotated //设置类注解 扫描器 ,否则 getTypesAnnotatedWith 会报错
|
||||
);
|
||||
|
||||
configurationBuilder.filterInputsBy(filterBuilder);
|
||||
@@ -98,7 +113,8 @@ public final class ReflectionUtil {
|
||||
MethodInfo methodInfo = cm.getMethodInfo();
|
||||
CtClass[] parameterTypes = cm.getParameterTypes();
|
||||
CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
|
||||
LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
|
||||
LocalVariableAttribute attr =
|
||||
(LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
|
||||
|
||||
boolean flag = true;
|
||||
boolean flag2 = cm.getModifiers() - 1 != AccessFlag.STATIC;
|
||||
@@ -110,7 +126,8 @@ public final class ReflectionUtil {
|
||||
continue;
|
||||
}
|
||||
flag = false;
|
||||
paramMap.put(attr.variableName(j + (flag2 ? 1 : 0)), Pair.of(parameterAnnotations[j - k], parameterTypes[j - k]));
|
||||
paramMap.put(attr.variableName(j + (flag2 ? 1 : 0)), Pair.of(parameterAnnotations[j - k],
|
||||
parameterTypes[j - k]));
|
||||
}
|
||||
} catch (NotFoundException e) {
|
||||
e.printStackTrace();
|
||||
@@ -169,10 +186,10 @@ public final class ReflectionUtil {
|
||||
return DateUtils.parseDate(value, fmt);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
throw new ConversionException("无法将格式化日期");
|
||||
throw new RuntimeException("无法将格式化日期");
|
||||
}
|
||||
default:
|
||||
throw new ConversionException("无法将String类型" + value + "转为[" + name + "]");
|
||||
throw new RuntimeException("无法将String类型" + value + "转为[" + name + "]");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +201,7 @@ public final class ReflectionUtil {
|
||||
* @return Array
|
||||
*/
|
||||
public static Object conversionArray(CtClass ctClass, String value) {
|
||||
if (!isBasicTypeArray(ctClass)) throw new ConversionException("无法解析数组");
|
||||
if (!isBasicTypeArray(ctClass)) throw new RuntimeException("无法解析数组");
|
||||
String[] strArr = value.split(",");
|
||||
List<Object> obj = new ArrayList<>();
|
||||
Arrays.stream(strArr).forEach(v -> obj.add(conversion(ctClass, v, null)));
|
||||
@@ -214,7 +231,8 @@ public final class ReflectionUtil {
|
||||
if (ctClass.isPrimitive() || "java.util.Date".equals(ctClass.getName())) {
|
||||
return true;
|
||||
}
|
||||
return ctClass.getName().matches("^java\\.lang\\.((Boolean)|(Character)|(Byte)|(Short)|(Integer)|(Long)|(Float)|(Double)|(String))$");
|
||||
return ctClass.getName().matches("^java\\.lang\\.((Boolean)|(Character)|(Byte)|(Short)|(Integer)|(Long)|" +
|
||||
"(Float)|(Double)|(String))$");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -238,7 +256,8 @@ public final class ReflectionUtil {
|
||||
* @throws InstantiationException InstantiationException
|
||||
* @throws IllegalAccessException IllegalAccessException
|
||||
*/
|
||||
public static <T> T newWithNoParam(Class<T> handler) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
|
||||
public static <T> T newWithNoParam(Class<T> handler) throws NoSuchMethodException, InvocationTargetException,
|
||||
InstantiationException, IllegalAccessException {
|
||||
return handler.getConstructor().newInstance();
|
||||
}
|
||||
|
||||
|
||||
51
core/src/main/java/cn/qaiu/vx/core/util/ResponseUtil.java
Normal file
51
core/src/main/java/cn/qaiu/vx/core/util/ResponseUtil.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package cn.qaiu.vx.core.util;
|
||||
|
||||
import cn.qaiu.vx.core.model.JsonResult;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.http.HttpHeaders;
|
||||
import io.vertx.core.http.HttpServerResponse;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.RoutingContext;
|
||||
|
||||
import static io.vertx.core.http.HttpHeaders.CONTENT_TYPE;
|
||||
|
||||
public class ResponseUtil {
|
||||
|
||||
public static void redirect(HttpServerResponse response, String url) {
|
||||
response.putHeader(CONTENT_TYPE, "text/html; charset=utf-8")
|
||||
.putHeader(HttpHeaders.LOCATION, url).setStatusCode(302).end();
|
||||
}
|
||||
|
||||
public static void redirect(HttpServerResponse response, String url, Promise<?> promise) {
|
||||
redirect(response, url);
|
||||
promise.complete();
|
||||
}
|
||||
|
||||
public static void fireJsonObjectResponse(RoutingContext ctx, JsonObject jsonObject) {
|
||||
ctx.response().putHeader(CONTENT_TYPE, "application/json; charset=utf-8")
|
||||
.setStatusCode(200)
|
||||
.end(jsonObject.encode());
|
||||
}
|
||||
|
||||
public static void fireJsonObjectResponse(HttpServerResponse ctx, JsonObject jsonObject) {
|
||||
ctx.putHeader(CONTENT_TYPE, "application/json; charset=utf-8")
|
||||
.setStatusCode(200)
|
||||
.end(jsonObject.encode());
|
||||
}
|
||||
|
||||
public static <T> void fireJsonResultResponse(RoutingContext ctx, JsonResult<T> jsonResult) {
|
||||
fireJsonObjectResponse(ctx, jsonResult.toJsonObject());
|
||||
}
|
||||
|
||||
public static <T> void fireJsonResultResponse(HttpServerResponse ctx, JsonResult<T> jsonResult) {
|
||||
fireJsonObjectResponse(ctx, jsonResult.toJsonObject());
|
||||
}
|
||||
|
||||
public static void fireTextResponse(RoutingContext ctx, String text) {
|
||||
ctx.response().putHeader(CONTENT_TYPE, "text/html; charset=utf-8").end(text);
|
||||
}
|
||||
|
||||
public static void sendError(RoutingContext ctx, int statusCode) {
|
||||
ctx.response().setStatusCode(statusCode).end();
|
||||
}
|
||||
}
|
||||
@@ -32,11 +32,11 @@ public class SharedDataUtil {
|
||||
return (JsonObject) localMap.get(key);
|
||||
}
|
||||
|
||||
public static JsonObject getJsonObjectForCustomConfig(String key) {
|
||||
return getJsonConfig("customConfig").getJsonObject(key);
|
||||
public static JsonObject getCustomConfig() {
|
||||
return getJsonConfig("customConfig");
|
||||
}
|
||||
|
||||
public static String getJsonStringForCustomConfig(String key) {
|
||||
public static String getStringForCustomConfig(String key) {
|
||||
return getJsonConfig("customConfig").getString(key);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
package cn.qaiu.vx.core.verticle;
|
||||
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.VertxOptions;
|
||||
import io.vertx.core.dns.AddressResolverOptions;
|
||||
import io.vertx.core.http.*;
|
||||
import io.vertx.core.net.NetClient;
|
||||
import io.vertx.core.net.NetClientOptions;
|
||||
import io.vertx.core.net.NetSocket;
|
||||
import io.vertx.core.net.ProxyOptions;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class HttpProxyVerticle extends AbstractVerticle {
|
||||
|
||||
private HttpClient httpClient;
|
||||
private NetClient netClient;
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
ProxyOptions proxyOptions = new ProxyOptions().setHost("127.0.0.1").setPort(7890);
|
||||
// 初始化 HTTP 客户端,用于向目标服务器发送 HTTP 请求
|
||||
HttpClientOptions httpClientOptions = new HttpClientOptions();
|
||||
httpClient = vertx.createHttpClient(httpClientOptions.setProxyOptions(proxyOptions));
|
||||
|
||||
// 创建并启动 HTTP 代理服务器,监听指定端口
|
||||
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setClientAuth(ClientAuth.REQUIRED));
|
||||
server.requestHandler(this::handleClientRequest);
|
||||
|
||||
// 初始化 NetClient,用于在 CONNECT 请求中建立 TCP 连接隧道
|
||||
netClient = vertx.createNetClient(new NetClientOptions()
|
||||
.setProxyOptions(proxyOptions)
|
||||
.setConnectTimeout(15000)
|
||||
.setTrustAll(true));
|
||||
|
||||
// 启动 HTTP 代理服务器
|
||||
server.listen(7891, ar -> {
|
||||
if (ar.succeeded()) {
|
||||
System.out.println("HTTP Proxy server started on port 7891");
|
||||
} else {
|
||||
System.err.println("Failed to start HTTP Proxy server: " + ar.cause());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 处理 HTTP CONNECT 请求,用于代理 HTTPS 流量
|
||||
private void handleConnectRequest(HttpServerRequest clientRequest) {
|
||||
String[] uriParts = clientRequest.uri().split(":");
|
||||
if (uriParts.length != 2) {
|
||||
clientRequest.response().setStatusCode(400).end("Bad Request: Invalid URI format");
|
||||
return;
|
||||
}
|
||||
|
||||
// 解析目标主机和端口
|
||||
String targetHost = uriParts[0];
|
||||
int targetPort;
|
||||
try {
|
||||
targetPort = Integer.parseInt(uriParts[1]);
|
||||
} catch (NumberFormatException e) {
|
||||
clientRequest.response().setStatusCode(400).end("Bad Request: Invalid port");
|
||||
return;
|
||||
}
|
||||
clientRequest.pause();
|
||||
// 通过 NetClient 连接目标服务器并创建隧道
|
||||
netClient.connect(targetPort, targetHost, connectionAttempt -> {
|
||||
if (connectionAttempt.succeeded()) {
|
||||
NetSocket targetSocket = connectionAttempt.result();
|
||||
|
||||
// 升级客户端连接到 NetSocket 并实现双向数据流
|
||||
clientRequest.toNetSocket().onComplete(clientSocketAttempt -> {
|
||||
if (clientSocketAttempt.succeeded()) {
|
||||
NetSocket clientSocket = clientSocketAttempt.result();
|
||||
|
||||
// 设置双向数据流转发
|
||||
clientSocket.handler(targetSocket::write);
|
||||
targetSocket.handler(clientSocket::write);
|
||||
|
||||
// 关闭其中一方时关闭另一方
|
||||
clientSocket.closeHandler(v -> targetSocket.close());
|
||||
targetSocket.closeHandler(v -> clientSocket.close());
|
||||
} else {
|
||||
System.err.println("Failed to upgrade client connection to socket: " + clientSocketAttempt.cause().getMessage());
|
||||
targetSocket.close();
|
||||
clientRequest.response().setStatusCode(500).end("Internal Server Error");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
System.err.println("Failed to connect to target: " + connectionAttempt.cause().getMessage());
|
||||
clientRequest.response().setStatusCode(502).end("Bad Gateway: Unable to connect to target");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 处理客户端的 HTTP 请求
|
||||
private void handleClientRequest(HttpServerRequest clientRequest) {
|
||||
String s = clientRequest.headers().get("Proxy-Authorization");
|
||||
if (s == null) {
|
||||
clientRequest.response().setStatusCode(403).end();
|
||||
return;
|
||||
}
|
||||
String[] split = new String(Base64.getDecoder().decode(s.replace("Basic ", ""))).split(":");
|
||||
if (split.length > 1) {
|
||||
System.out.println(split[0]);
|
||||
System.out.println(split[1]);
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
if (clientRequest.method() == HttpMethod.CONNECT) {
|
||||
// 处理 CONNECT 请求
|
||||
handleConnectRequest(clientRequest);
|
||||
} else {
|
||||
// 处理普通的 HTTP 请求
|
||||
handleHttpRequest(clientRequest);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理 HTTP 请求,转发至目标服务器并返回响应
|
||||
private void handleHttpRequest(HttpServerRequest clientRequest) {
|
||||
// 获取目标主机
|
||||
String hostHeader = clientRequest.getHeader("Host");
|
||||
if (hostHeader == null) {
|
||||
clientRequest.response().setStatusCode(400).end("Host header is missing");
|
||||
return;
|
||||
}
|
||||
|
||||
String targetHost = hostHeader.split(":")[0];
|
||||
int targetPort = 80; // 默认为 HTTP 的端口
|
||||
clientRequest.pause(); // 暂停客户端请求的读取,避免数据丢失
|
||||
|
||||
httpClient.request(clientRequest.method(), targetPort, targetHost, clientRequest.uri())
|
||||
.onSuccess(request -> {
|
||||
clientRequest.resume(); // 恢复客户端请求的读取
|
||||
|
||||
// 逐个设置请求头
|
||||
clientRequest.headers().forEach(header -> request.putHeader(header.getKey(), header.getValue()));
|
||||
|
||||
// 将客户端请求的 body 转发给目标服务器
|
||||
clientRequest.bodyHandler(body -> request.send(body, ar -> {
|
||||
if (ar.succeeded()) {
|
||||
var response = ar.result();
|
||||
clientRequest.response().setStatusCode(response.statusCode());
|
||||
clientRequest.response().headers().setAll(response.headers());
|
||||
response.body().onSuccess(b-> clientRequest.response().end(b));
|
||||
} else {
|
||||
clientRequest.response().setStatusCode(502).end("Bad Gateway: Unable to reach target");
|
||||
}
|
||||
}));
|
||||
})
|
||||
.onFailure(err -> {
|
||||
err.printStackTrace();
|
||||
clientRequest.response().setStatusCode(502).end("Bad Gateway: Request failed");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
// 停止 HTTP 客户端以释放资源
|
||||
if (httpClient != null) {
|
||||
httpClient.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO add Deploy
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
// 配置 DNS 解析器,使用多个 DNS 服务器来提升解析速度
|
||||
Vertx vertx = Vertx.vertx(new VertxOptions()
|
||||
.setAddressResolverOptions(new AddressResolverOptions()
|
||||
.addServer("114.114.114.114")
|
||||
.addServer("114.114.115.115")
|
||||
.addServer("8.8.8.8")
|
||||
.addServer("8.8.4.4")));
|
||||
|
||||
// 部署 Verticle 并启动动态 HTTP 代理服务器
|
||||
vertx.deployVerticle(new HttpProxyVerticle());
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,13 @@ import io.vertx.core.Future;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.http.HttpClient;
|
||||
import io.vertx.core.http.HttpServer;
|
||||
import io.vertx.core.http.WebSocket;
|
||||
import io.vertx.core.http.HttpServerOptions;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.net.PemKeyCertOptions;
|
||||
import io.vertx.ext.web.Route;
|
||||
import io.vertx.ext.web.Router;
|
||||
import io.vertx.ext.web.handler.StaticHandler;
|
||||
import io.vertx.ext.web.handler.sockjs.SockJSHandler;
|
||||
import io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions;
|
||||
import io.vertx.ext.web.proxy.handler.ProxyHandler;
|
||||
import io.vertx.httpproxy.HttpProxy;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -40,14 +40,17 @@ public class ReverseProxyVerticle extends AbstractVerticle {
|
||||
.getJsonConfig(ConfigConstant.GLOBAL_CONFIG)
|
||||
.getString("proxyConf");
|
||||
private static final Future<JsonObject> CONFIG = ConfigUtil.readYamlConfig(PATH_PROXY_CONFIG);
|
||||
private static final String DEFAULT_PATH_404 = "webroot/err/404.html";
|
||||
private static final String DEFAULT_PATH_404 = "webroot/err/page404.html";
|
||||
|
||||
private static String serverName = "Vert.x-proxy-server"; //Server name in Http response header
|
||||
|
||||
public static String REROUTE_PATH_PREFIX = "/__rrvpspp"; //re_route_vert_proxy_server_path_prefix 硬编码
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Promise<Void> startPromise) throws Exception {
|
||||
public void start(Promise<Void> startPromise) {
|
||||
CONFIG.onSuccess(this::handleProxyConfList);
|
||||
// createFileListener
|
||||
startPromise.complete();
|
||||
}
|
||||
|
||||
@@ -74,22 +77,24 @@ public class ReverseProxyVerticle extends AbstractVerticle {
|
||||
* @param proxyConf 代理配置
|
||||
*/
|
||||
private void handleProxyConf(JsonObject proxyConf) {
|
||||
// 404 path
|
||||
if (proxyConf.containsKey("404")) {
|
||||
// page404 path
|
||||
if (proxyConf.containsKey(
|
||||
|
||||
"page404")) {
|
||||
System.getProperty("user.dir");
|
||||
String path = proxyConf.getString("404");
|
||||
String path = proxyConf.getString("page404");
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
proxyConf.put("404", DEFAULT_PATH_404);
|
||||
proxyConf.put("page404", DEFAULT_PATH_404);
|
||||
} else {
|
||||
if (!path.startsWith("/")) {
|
||||
path = "/" + path;
|
||||
}
|
||||
if (!new File(System.getProperty("user.dir") + path).exists()) {
|
||||
proxyConf.put("404", DEFAULT_PATH_404);
|
||||
proxyConf.put("page404", DEFAULT_PATH_404);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
proxyConf.put("404", DEFAULT_PATH_404);
|
||||
proxyConf.put("page404", DEFAULT_PATH_404);
|
||||
}
|
||||
|
||||
final HttpClient httpClient = VertxHolder.getVertxInstance().createHttpClient();
|
||||
@@ -111,17 +116,10 @@ public class ReverseProxyVerticle extends AbstractVerticle {
|
||||
handleStatic(proxyConf.getJsonObject("static"), proxyRouter);
|
||||
}
|
||||
|
||||
// static server
|
||||
if (proxyConf.containsKey("sock")) {
|
||||
handleSock(proxyConf.getJsonArray("sock"), httpClient, proxyRouter);
|
||||
}
|
||||
// Send page404 page
|
||||
proxyRouter.errorHandler(404, ctx -> ctx.response().sendFile(proxyConf.getString("page404")));
|
||||
|
||||
// Send 404 page
|
||||
proxyRouter.errorHandler(404, ctx -> {
|
||||
ctx.response().sendFile(proxyConf.getString("404"));
|
||||
});
|
||||
|
||||
HttpServer server = vertx.createHttpServer();
|
||||
HttpServer server = getHttpsServer(proxyConf);
|
||||
server.requestHandler(proxyRouter);
|
||||
|
||||
Integer port = proxyConf.getInteger("listen");
|
||||
@@ -129,6 +127,38 @@ public class ReverseProxyVerticle extends AbstractVerticle {
|
||||
server.listen(port);
|
||||
}
|
||||
|
||||
private HttpServer getHttpsServer(JsonObject proxyConf) {
|
||||
HttpServerOptions httpServerOptions = new HttpServerOptions();
|
||||
if (proxyConf.containsKey("ssl")) {
|
||||
JsonObject sslConfig = proxyConf.getJsonObject("ssl");
|
||||
|
||||
URL sslUrl = this.getClass().getClassLoader().getResource("");
|
||||
if (sslUrl == null) {
|
||||
throw new RuntimeException("SSL url not exist...");
|
||||
}
|
||||
if (sslConfig.containsKey("enable") && sslConfig.getBoolean("enable")) {
|
||||
String sslCertificatePath = sslUrl.getPath() + sslConfig.getString("ssl_certificate");
|
||||
String sslCertificateKeyPath = sslUrl.getPath() + sslConfig.getString("ssl_certificate_key");
|
||||
LOGGER.info("enable ssl config. ");
|
||||
httpServerOptions
|
||||
.setSsl(true)
|
||||
.setKeyCertOptions(
|
||||
new PemKeyCertOptions()
|
||||
.setKeyPath(sslCertificateKeyPath)
|
||||
.setCertPath(sslCertificatePath)
|
||||
).addEnabledSecureTransportProtocol(sslConfig.getString("ssl_protocols"));
|
||||
String sslCiphers = sslConfig.getString("ssl_ciphers");
|
||||
if (sslCiphers != null && !sslCiphers.isEmpty()) {
|
||||
for (String s : sslCiphers.split(":")) {
|
||||
httpServerOptions.addEnabledCipherSuite(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return vertx.createHttpServer(httpServerOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理静态资源配置
|
||||
*
|
||||
@@ -145,9 +175,12 @@ public class ReverseProxyVerticle extends AbstractVerticle {
|
||||
ctx.next();
|
||||
});
|
||||
|
||||
final StaticHandler staticHandler = StaticHandler.create();
|
||||
|
||||
StaticHandler staticHandler;
|
||||
if (staticConf.containsKey("root")) {
|
||||
staticHandler.setWebRoot(staticConf.getString("root"));
|
||||
staticHandler = StaticHandler.create(staticConf.getString("root"));
|
||||
} else {
|
||||
staticHandler = StaticHandler.create();
|
||||
}
|
||||
if (staticConf.containsKey("directory-listing")) {
|
||||
staticHandler.setDirectoryListing(staticConf.getBoolean("directory-listing"));
|
||||
@@ -178,7 +211,7 @@ public class ReverseProxyVerticle extends AbstractVerticle {
|
||||
port = 80;
|
||||
}
|
||||
String originPath = url.getPath();
|
||||
LOGGER.debug("Conf(path, originPath, host, port) ----> {},{},{},{}", path, originPath, host, port);
|
||||
LOGGER.info("path {}, originPath {}, to {}:{}", path, originPath, host, port);
|
||||
|
||||
// 注意这里不能origin多个代理地址, 一个实例只能代理一个origin
|
||||
final HttpProxy httpProxy = HttpProxy.reverseProxy(httpClient);
|
||||
@@ -189,14 +222,21 @@ public class ReverseProxyVerticle extends AbstractVerticle {
|
||||
|
||||
// 代理目标路径为空 就像nginx一样路径穿透 (相对路径)
|
||||
if (StringUtils.isEmpty(originPath) || path.equals(originPath)) {
|
||||
proxyRouter.route(path + "*").handler(ProxyHandler.create(httpProxy));
|
||||
Route route = path.startsWith("~") ? proxyRouter.routeWithRegex(path.substring(1))
|
||||
: proxyRouter.route(path);
|
||||
route.handler(ProxyHandler.create(httpProxy));
|
||||
} else {
|
||||
proxyRouter.route(originPath + "*").handler(ProxyHandler.create(httpProxy));
|
||||
proxyRouter.route(path + "*").handler(ctx -> {
|
||||
String realPath = ctx.request().path();
|
||||
if (realPath.startsWith(path)) {
|
||||
// 配置 /api/, / => 请求 /api/test 代理后 /test
|
||||
// 配置 /api/, /xxx => 请求 /api/test 代理后 /xxx/test
|
||||
final String path0 = path;
|
||||
final String originPath0 = REROUTE_PATH_PREFIX + originPath;
|
||||
|
||||
proxyRouter.route(originPath0 + "*").handler(ProxyHandler.create(httpProxy));
|
||||
proxyRouter.route(path0 + "*").handler(ctx -> {
|
||||
String realPath = ctx.request().uri();
|
||||
if (realPath.startsWith(path0)) {
|
||||
// vertx web proxy暂不支持rewrite, 所以这里进行手动替换, 请求地址中的请求path前缀替换为originPath
|
||||
String rePath = realPath.replaceAll("^" + path, originPath);
|
||||
String rePath = realPath.replaceAll("^" + path0, originPath0);
|
||||
ctx.reroute(rePath);
|
||||
} else {
|
||||
ctx.next();
|
||||
@@ -210,54 +250,4 @@ public class ReverseProxyVerticle extends AbstractVerticle {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理websocket
|
||||
*
|
||||
* @param confList sock配置
|
||||
* @param httpClient 客户端
|
||||
* @param proxyRouter 代理路由
|
||||
*/
|
||||
private void handleSock(JsonArray confList, HttpClient httpClient, Router proxyRouter) {
|
||||
// 代理规则
|
||||
confList.stream().map(e -> (JsonObject) e).forEach(conf -> {
|
||||
|
||||
String origin = conf.getString("origin");
|
||||
String path = conf.getString("path");
|
||||
LOGGER.info("websocket proxy: {}, {}",origin,path);
|
||||
|
||||
SockJSHandlerOptions options = new SockJSHandlerOptions()
|
||||
.setHeartbeatInterval(2000)
|
||||
.setRegisterWriteHandler(true);
|
||||
|
||||
SockJSHandler sockJSHandler = SockJSHandler.create(VertxHolder.getVertxInstance(), options);
|
||||
if (!path.startsWith("/")) {
|
||||
path = "/" + path;
|
||||
}
|
||||
|
||||
|
||||
Router route = sockJSHandler.socketHandler(sock -> {
|
||||
sock.handler(buffer -> {
|
||||
Future<WebSocket> webSocketFuture = httpClient.webSocket(8086,"127.0.0.1",sock.uri());
|
||||
webSocketFuture.onSuccess(s -> {
|
||||
System.out.println(buffer.toString());
|
||||
s.write(buffer).onSuccess(v -> {
|
||||
s.handler(w->{
|
||||
System.out.println("--------"+w.toString());
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
sock.endHandler(v -> {
|
||||
|
||||
});
|
||||
sock.closeHandler(v -> {
|
||||
|
||||
});
|
||||
});
|
||||
proxyRouter.mountSubRouter("/real/serverApi/test", route);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package cn.qaiu.vx.core.verticle;
|
||||
|
||||
import cn.qaiu.vx.core.handlerfactory.RouterHandlerFactory;
|
||||
import cn.qaiu.vx.core.util.CommonUtil;
|
||||
import cn.qaiu.vx.core.util.JacksonConfig;
|
||||
import cn.qaiu.vx.core.util.SharedDataUtil;
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.Promise;
|
||||
@@ -23,7 +24,6 @@ public class RouterVerticle extends AbstractVerticle {
|
||||
|
||||
private static final int port = SharedDataUtil.getValueForServerConfig("port");
|
||||
private static final Router router = new RouterHandlerFactory(
|
||||
SharedDataUtil.getJsonStringForCustomConfig("routerLocations"),
|
||||
SharedDataUtil.getJsonStringForServerConfig("contextPath")).createRouter();
|
||||
|
||||
private static final JsonObject globalConfig = SharedDataUtil.getJsonConfig("globalConfig");
|
||||
@@ -31,6 +31,8 @@ public class RouterVerticle extends AbstractVerticle {
|
||||
private HttpServer server;
|
||||
|
||||
static {
|
||||
LOGGER.info(JacksonConfig.class.getSimpleName() + " >> ");
|
||||
JacksonConfig.nothing();
|
||||
LOGGER.info("To start listening to port {} ......", port);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package cn.qaiu.vx.core.verticle;
|
||||
import cn.qaiu.vx.core.annotaions.Service;
|
||||
import cn.qaiu.vx.core.base.BaseAsyncService;
|
||||
import cn.qaiu.vx.core.util.ReflectionUtil;
|
||||
import cn.qaiu.vx.core.util.SharedDataUtil;
|
||||
import io.vertx.core.AbstractVerticle;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.serviceproxy.ServiceBinder;
|
||||
@@ -27,8 +26,7 @@ public class ServiceVerticle extends AbstractVerticle {
|
||||
private static final Set<Class<?>> handlers;
|
||||
|
||||
static {
|
||||
String handlerLocations = SharedDataUtil.getJsonStringForCustomConfig("handlerLocations");
|
||||
Reflections reflections = ReflectionUtil.getReflections(handlerLocations);
|
||||
Reflections reflections = ReflectionUtil.getReflections();
|
||||
handlers = reflections.getTypesAnnotatedWith(Service.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package cn.qaiu.vx.core.verticle.conf;
|
||||
|
||||
import io.vertx.codegen.annotations.DataObject;
|
||||
import io.vertx.codegen.json.annotations.JsonGen;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.net.ProxyOptions;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@DataObject
|
||||
@JsonGen(publicConverter = false)
|
||||
public class HttpProxyConf {
|
||||
|
||||
public static final String DEFAULT_USERNAME = UUID.randomUUID().toString();
|
||||
|
||||
public static final String DEFAULT_PASSWORD = UUID.randomUUID().toString();
|
||||
|
||||
public static final Integer DEFAULT_PORT = 6402;
|
||||
|
||||
public static final Integer DEFAULT_TIMEOUT = 15000;
|
||||
|
||||
Integer timeout;
|
||||
|
||||
String username;
|
||||
|
||||
String password;
|
||||
|
||||
Integer port;
|
||||
|
||||
ProxyOptions preProxyOptions;
|
||||
|
||||
public HttpProxyConf() {
|
||||
this.username = DEFAULT_USERNAME;
|
||||
this.password = DEFAULT_PASSWORD;
|
||||
this.timeout = DEFAULT_PORT;
|
||||
this.timeout = DEFAULT_TIMEOUT;
|
||||
this.preProxyOptions = new ProxyOptions();
|
||||
}
|
||||
|
||||
public HttpProxyConf(JsonObject json) {
|
||||
this();
|
||||
}
|
||||
|
||||
|
||||
public Integer getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public HttpProxyConf setTimeout(Integer timeout) {
|
||||
this.timeout = timeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public HttpProxyConf setUsername(String username) {
|
||||
this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public HttpProxyConf setPassword(String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public HttpProxyConf setPort(Integer port) {
|
||||
this.port = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProxyOptions getPreProxyOptions() {
|
||||
return preProxyOptions;
|
||||
}
|
||||
|
||||
public HttpProxyConf setPreProxyOptions(ProxyOptions preProxyOptions) {
|
||||
this.preProxyOptions = preProxyOptions;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
2
core/src/main/resources/app.properties
Normal file
2
core/src/main/resources/app.properties
Normal file
@@ -0,0 +1,2 @@
|
||||
app.version=${project.version}
|
||||
build=${maven.build.timestamp}
|
||||
310
mvnw
vendored
Normal file
310
mvnw
vendored
Normal file
@@ -0,0 +1,310 @@
|
||||
#!/bin/sh
|
||||
# ----------------------------------------------------------------------------
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Maven Start Up Batch script
|
||||
#
|
||||
# Required ENV vars:
|
||||
# ------------------
|
||||
# JAVA_HOME - location of a JDK home dir
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# M2_HOME - location of maven2's installed home dir
|
||||
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
# e.g. to debug Maven itself, use
|
||||
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
if [ -z "$MAVEN_SKIP_RC" ] ; then
|
||||
|
||||
if [ -f /etc/mavenrc ] ; then
|
||||
. /etc/mavenrc
|
||||
fi
|
||||
|
||||
if [ -f "$HOME/.mavenrc" ] ; then
|
||||
. "$HOME/.mavenrc"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# OS specific support. $var _must_ be set to either true or false.
|
||||
cygwin=false;
|
||||
darwin=false;
|
||||
mingw=false
|
||||
case "`uname`" in
|
||||
CYGWIN*) cygwin=true ;;
|
||||
MINGW*) mingw=true;;
|
||||
Darwin*) darwin=true
|
||||
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
|
||||
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
if [ -x "/usr/libexec/java_home" ]; then
|
||||
export JAVA_HOME="`/usr/libexec/java_home`"
|
||||
else
|
||||
export JAVA_HOME="/Library/Java/Home"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
if [ -r /etc/gentoo-release ] ; then
|
||||
JAVA_HOME=`java-config --jre-home`
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$M2_HOME" ] ; then
|
||||
## resolve links - $0 may be a link to maven's home
|
||||
PRG="$0"
|
||||
|
||||
# need this for relative symlinks
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG="`dirname "$PRG"`/$link"
|
||||
fi
|
||||
done
|
||||
|
||||
saveddir=`pwd`
|
||||
|
||||
M2_HOME=`dirname "$PRG"`/..
|
||||
|
||||
# make it fully qualified
|
||||
M2_HOME=`cd "$M2_HOME" && pwd`
|
||||
|
||||
cd "$saveddir"
|
||||
# echo Using m2 at $M2_HOME
|
||||
fi
|
||||
|
||||
# For Cygwin, ensure paths are in UNIX format before anything is touched
|
||||
if $cygwin ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --unix "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
|
||||
fi
|
||||
|
||||
# For Mingw, ensure paths are in UNIX format before anything is touched
|
||||
if $mingw ; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME="`(cd "$M2_HOME"; pwd)`"
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ]; then
|
||||
javaExecutable="`which javac`"
|
||||
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
|
||||
# readlink(1) is not available as standard on Solaris 10.
|
||||
readLink=`which readlink`
|
||||
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
|
||||
if $darwin ; then
|
||||
javaHome="`dirname \"$javaExecutable\"`"
|
||||
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
|
||||
else
|
||||
javaExecutable="`readlink -f \"$javaExecutable\"`"
|
||||
fi
|
||||
javaHome="`dirname \"$javaExecutable\"`"
|
||||
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
|
||||
JAVA_HOME="$javaHome"
|
||||
export JAVA_HOME
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$JAVACMD" ] ; then
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
else
|
||||
JAVACMD="`which java`"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
echo "Error: JAVA_HOME is not defined correctly." >&2
|
||||
echo " We cannot execute $JAVACMD" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$JAVA_HOME" ] ; then
|
||||
echo "Warning: JAVA_HOME environment variable is not set."
|
||||
fi
|
||||
|
||||
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
|
||||
|
||||
# traverses directory structure from process work directory to filesystem root
|
||||
# first directory with .mvn subdirectory is considered project base directory
|
||||
find_maven_basedir() {
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "Path not specified to find_maven_basedir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
basedir="$1"
|
||||
wdir="$1"
|
||||
while [ "$wdir" != '/' ] ; do
|
||||
if [ -d "$wdir"/.mvn ] ; then
|
||||
basedir=$wdir
|
||||
break
|
||||
fi
|
||||
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
|
||||
if [ -d "${wdir}" ]; then
|
||||
wdir=`cd "$wdir/.."; pwd`
|
||||
fi
|
||||
# end of workaround
|
||||
done
|
||||
echo "${basedir}"
|
||||
}
|
||||
|
||||
# concatenates all lines of a file
|
||||
concat_lines() {
|
||||
if [ -f "$1" ]; then
|
||||
echo "$(tr -s '\n' ' ' < "$1")"
|
||||
fi
|
||||
}
|
||||
|
||||
BASE_DIR=`find_maven_basedir "$(pwd)"`
|
||||
if [ -z "$BASE_DIR" ]; then
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
##########################################################################################
|
||||
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
# This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
##########################################################################################
|
||||
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found .mvn/wrapper/maven-wrapper.jar"
|
||||
fi
|
||||
else
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
|
||||
fi
|
||||
if [ -n "$MVNW_REPOURL" ]; then
|
||||
jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
else
|
||||
jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
fi
|
||||
while IFS="=" read key value; do
|
||||
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
|
||||
esac
|
||||
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Downloading from: $jarUrl"
|
||||
fi
|
||||
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
|
||||
if $cygwin; then
|
||||
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
|
||||
fi
|
||||
|
||||
if command -v wget > /dev/null; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found wget ... using wget"
|
||||
fi
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
wget "$jarUrl" -O "$wrapperJarPath"
|
||||
else
|
||||
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath"
|
||||
fi
|
||||
elif command -v curl > /dev/null; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Found curl ... using curl"
|
||||
fi
|
||||
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
|
||||
curl -o "$wrapperJarPath" "$jarUrl" -f
|
||||
else
|
||||
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
|
||||
fi
|
||||
|
||||
else
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo "Falling back to using Java to download"
|
||||
fi
|
||||
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
|
||||
# For Cygwin, switch paths to Windows format before running javac
|
||||
if $cygwin; then
|
||||
javaClass=`cygpath --path --windows "$javaClass"`
|
||||
fi
|
||||
if [ -e "$javaClass" ]; then
|
||||
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo " - Compiling MavenWrapperDownloader.java ..."
|
||||
fi
|
||||
# Compiling the Java class
|
||||
("$JAVA_HOME/bin/javac" "$javaClass")
|
||||
fi
|
||||
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
|
||||
# Running the downloader
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo " - Running MavenWrapperDownloader.java ..."
|
||||
fi
|
||||
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
##########################################################################################
|
||||
# End of extension
|
||||
##########################################################################################
|
||||
|
||||
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
|
||||
if [ "$MVNW_VERBOSE" = true ]; then
|
||||
echo $MAVEN_PROJECTBASEDIR
|
||||
fi
|
||||
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin; then
|
||||
[ -n "$M2_HOME" ] &&
|
||||
M2_HOME=`cygpath --path --windows "$M2_HOME"`
|
||||
[ -n "$JAVA_HOME" ] &&
|
||||
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
|
||||
[ -n "$CLASSPATH" ] &&
|
||||
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
|
||||
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
|
||||
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
|
||||
fi
|
||||
|
||||
# Provide a "standardized" way to retrieve the CLI args that will
|
||||
# work with both Windows and non-Windows executions.
|
||||
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
|
||||
export MAVEN_CMD_LINE_ARGS
|
||||
|
||||
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
exec "$JAVACMD" \
|
||||
$MAVEN_OPTS \
|
||||
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
|
||||
"-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
|
||||
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
|
||||
182
mvnw.cmd
vendored
Normal file
182
mvnw.cmd
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Maven Start Up Batch script
|
||||
@REM
|
||||
@REM Required ENV vars:
|
||||
@REM JAVA_HOME - location of a JDK home dir
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM M2_HOME - location of maven2's installed home dir
|
||||
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
|
||||
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
|
||||
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
|
||||
@REM e.g. to debug Maven itself, use
|
||||
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
|
||||
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
|
||||
@echo off
|
||||
@REM set title of command window
|
||||
title %0
|
||||
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
|
||||
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
|
||||
|
||||
@REM set %HOME% to equivalent of $HOME
|
||||
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
|
||||
|
||||
@REM Execute a user defined script before this one
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
|
||||
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
|
||||
if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
|
||||
:skipRcPre
|
||||
|
||||
@setlocal
|
||||
|
||||
set ERROR_CODE=0
|
||||
|
||||
@REM To isolate internal variables from possible post scripts, we use another setlocal
|
||||
@setlocal
|
||||
|
||||
@REM ==== START VALIDATION ====
|
||||
if not "%JAVA_HOME%" == "" goto OkJHome
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME not found in your environment. >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
:OkJHome
|
||||
if exist "%JAVA_HOME%\bin\java.exe" goto init
|
||||
|
||||
echo.
|
||||
echo Error: JAVA_HOME is set to an invalid directory. >&2
|
||||
echo JAVA_HOME = "%JAVA_HOME%" >&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the >&2
|
||||
echo location of your Java installation. >&2
|
||||
echo.
|
||||
goto error
|
||||
|
||||
@REM ==== END VALIDATION ====
|
||||
|
||||
:init
|
||||
|
||||
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
|
||||
@REM Fallback to current working directory if not found.
|
||||
|
||||
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
|
||||
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
|
||||
|
||||
set EXEC_DIR=%CD%
|
||||
set WDIR=%EXEC_DIR%
|
||||
:findBaseDir
|
||||
IF EXIST "%WDIR%"\.mvn goto baseDirFound
|
||||
cd ..
|
||||
IF "%WDIR%"=="%CD%" goto baseDirNotFound
|
||||
set WDIR=%CD%
|
||||
goto findBaseDir
|
||||
|
||||
:baseDirFound
|
||||
set MAVEN_PROJECTBASEDIR=%WDIR%
|
||||
cd "%EXEC_DIR%"
|
||||
goto endDetectBaseDir
|
||||
|
||||
:baseDirNotFound
|
||||
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
|
||||
cd "%EXEC_DIR%"
|
||||
|
||||
:endDetectBaseDir
|
||||
|
||||
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
|
||||
|
||||
@setlocal EnableExtensions EnableDelayedExpansion
|
||||
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
|
||||
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
|
||||
|
||||
:endReadAdditionalConfig
|
||||
|
||||
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
|
||||
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
|
||||
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
|
||||
|
||||
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
|
||||
FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
|
||||
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
|
||||
)
|
||||
|
||||
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
|
||||
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
|
||||
if exist %WRAPPER_JAR% (
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Found %WRAPPER_JAR%
|
||||
)
|
||||
) else (
|
||||
if not "%MVNW_REPOURL%" == "" (
|
||||
SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar"
|
||||
)
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Couldn't find %WRAPPER_JAR%, downloading it ...
|
||||
echo Downloading from: %DOWNLOAD_URL%
|
||||
)
|
||||
|
||||
powershell -Command "&{"^
|
||||
"$webclient = new-object System.Net.WebClient;"^
|
||||
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
|
||||
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
|
||||
"}"^
|
||||
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
|
||||
"}"
|
||||
if "%MVNW_VERBOSE%" == "true" (
|
||||
echo Finished downloading %WRAPPER_JAR%
|
||||
)
|
||||
)
|
||||
@REM End of extension
|
||||
|
||||
@REM Provide a "standardized" way to retrieve the CLI args that will
|
||||
@REM work with both Windows and non-Windows executions.
|
||||
set MAVEN_CMD_LINE_ARGS=%*
|
||||
|
||||
%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
|
||||
if ERRORLEVEL 1 goto error
|
||||
goto end
|
||||
|
||||
:error
|
||||
set ERROR_CODE=1
|
||||
|
||||
:end
|
||||
@endlocal & set ERROR_CODE=%ERROR_CODE%
|
||||
|
||||
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
|
||||
@REM check for post script, once with legacy .bat ending and once with .cmd ending
|
||||
if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
|
||||
if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
|
||||
:skipRcPost
|
||||
|
||||
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
|
||||
if "%MAVEN_BATCH_PAUSE%" == "on" pause
|
||||
|
||||
if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
|
||||
|
||||
exit /B %ERROR_CODE%
|
||||
74
note.txt
Normal file
74
note.txt
Normal file
@@ -0,0 +1,74 @@
|
||||
直链缓存设计
|
||||
每个网盘对应的标准分享URL如下
|
||||
|
||||
蓝奏云 (lz) https://lanzoux.com/{shareKey}
|
||||
蓝奏云优享 (iz) https://www.ilanzou.com/s/{shareKey}
|
||||
奶牛快传 (cow) https://cowtransfer.com/s/{shareKey}
|
||||
移动云云空间 (ec) https://www.ecpan.cn/web/#/yunpanProxy?path=%2F%23%2Fdrive%2Foutside&data={shareKey}&isShare=1
|
||||
小飞机网盘 (fj) https://share.feijipan.com/s/{shareKey}
|
||||
亿方云 (fc) https://v2.fangcloud.com/sharing/{shareKey}
|
||||
123云盘 (ye) https://www.123pan.com/s/{shareKey}.html
|
||||
文叔叔 (ws) https://f.ws59.cn/f/{shareKey}
|
||||
联想乐云 (le) https://lecloud.lenovo.com/share/{shareKey}
|
||||
|
||||
私有化网盘需要自己的域名也就是origin地址.
|
||||
Cloudreve自建网盘 (ce) {origin}/s/{shareKey}
|
||||
|
||||
分享URL -> 类型+key
|
||||
类型+key -> 标准分享URL
|
||||
|
||||
缓存key -> 下载URL
|
||||
分享链接 -> add 网盘类型 pwd origin(私有化) -> 直链
|
||||
|
||||
开源版 TODO
|
||||
1. 缓存优化, 配置自动重载
|
||||
2. 缓存删除接口(后台功能)
|
||||
3. JS脚本引擎 自定义解析
|
||||
|
||||
|
||||
|
||||
专属版 功能设计
|
||||
1. 支持绑定域名, 后台管理-账号管理, token管理, 账号解析次数限制
|
||||
2. 流量统计, 文件分享信息, 目录解析, 文件云下载
|
||||
3. IP代理池
|
||||
|
||||
网页跳转 防盗链
|
||||
可禁用parser接口
|
||||
|
||||
标志短链 鉴权后 生成混淆链接
|
||||
|
||||
|
||||
短链算法:
|
||||
1. 基于Hash映射 hash(type:key:pwd) = h/xxxxx
|
||||
|
||||
鉴权实现:
|
||||
auth-jdbc
|
||||
|
||||
// 基于标准SQL语法
|
||||
|
||||
支持H2, MySQL
|
||||
|
||||
用户:
|
||||
jwt鉴权用户
|
||||
|
||||
角色:
|
||||
超级管理员
|
||||
注册用户
|
||||
|
||||
定义操作(权限):
|
||||
用户的创建/删除/查询/修改, 生成短链/删除短链/修改解析次数和有效期/查询短链信息(
|
||||
文件信息: 文件/文件夹, 文件数量, 文件大小, 文件类型; 链接信息: 解析次数, 缓存次数等)
|
||||
|
||||
微服务设计:
|
||||
TODO
|
||||
|
||||
后台管理:
|
||||
菜单:
|
||||
网盘管理: token配置, 启用/禁用
|
||||
短链管理: 短链列表, 新增, 删除
|
||||
解析统计: 下载次数统计, 下载流量统计, 详细解析列表
|
||||
状态监视: 服务请求并发数; 来源IP列表: 拉黑, 限制次数; Nginx
|
||||
系统配置: 管理员账户, 系统参数: 域名配置, 预览URL,
|
||||
|
||||
|
||||
|
||||
144
parser/pom.xml
Normal file
144
parser/pom.xml
Normal file
@@ -0,0 +1,144 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>netdisk-fast-download</artifactId>
|
||||
<groupId>cn.qaiu</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>parser</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
<name>cn.qaiu:parser</name>
|
||||
<description>NFD parser</description>
|
||||
<url>https://qaiu.top</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--logback日志实现-->
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vertx</groupId>
|
||||
<artifactId>vertx-web-client</artifactId>
|
||||
<version>${vertx.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.openjdk.nashorn/nashorn-core -->
|
||||
<dependency>
|
||||
<groupId>org.openjdk.nashorn</groupId>
|
||||
<artifactId>nashorn-core</artifactId>
|
||||
<version>15.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<licenses>
|
||||
<license>
|
||||
<name>MIT License</name>
|
||||
<url>https://opensource.org/license/mit</url>
|
||||
</license>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer>
|
||||
<name>qaiu</name>
|
||||
<email>qaiu00@gmail.com</email>
|
||||
<organization>https://qaiu.top</organization>
|
||||
</developer>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection>scm:git@github.com:qaiu/netdisk-fast-download.git</connection>
|
||||
<developerConnection>scm:git@github.com:qaiu/netdisk-fast-download.git</developerConnection>
|
||||
<url>git@github.com:qaiu/netdisk-fast-download.git</url>
|
||||
</scm>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>sonatype</id>
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
<configuration>
|
||||
<attach>true</attach>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
</plugin>
|
||||
<!-- Gpg Signature -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-gpg-plugin</artifactId>
|
||||
<version>1.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>sign-artifacts</id>
|
||||
<phase>verify</phase>
|
||||
<goals>
|
||||
<goal>sign</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.sonatype.central</groupId>
|
||||
<artifactId>central-publishing-maven-plugin</artifactId>
|
||||
<version>0.6.0</version>
|
||||
<extensions>true</extensions>
|
||||
<configuration>
|
||||
<publishingServerId>central</publishingServerId>
|
||||
<autoPublish>true</autoPublish>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
24
parser/src/main/java/cn/qaiu/WebClientVertxInit.java
Normal file
24
parser/src/main/java/cn/qaiu/WebClientVertxInit.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package cn.qaiu;
|
||||
|
||||
import io.vertx.core.Vertx;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class WebClientVertxInit {
|
||||
private Vertx vertx = null;
|
||||
private static final WebClientVertxInit INSTANCE = new WebClientVertxInit();
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(WebClientVertxInit.class);
|
||||
|
||||
public static void init(Vertx vx) {
|
||||
INSTANCE.vertx = vx;
|
||||
}
|
||||
|
||||
public static Vertx get() {
|
||||
if (INSTANCE.vertx == null) {
|
||||
log.info("getVertx: Vertx实例不存在, 创建Vertx实例.");
|
||||
INSTANCE.vertx = Vertx.vertx();
|
||||
}
|
||||
return INSTANCE.vertx;
|
||||
}
|
||||
}
|
||||
250
parser/src/main/java/cn/qaiu/entity/FileInfo.java
Normal file
250
parser/src/main/java/cn/qaiu/entity/FileInfo.java
Normal file
@@ -0,0 +1,250 @@
|
||||
package cn.qaiu.entity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class FileInfo {
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 文件ID
|
||||
*/
|
||||
private String fileId;
|
||||
|
||||
private String fileIcon;
|
||||
|
||||
/**
|
||||
* 文件大小(byte)
|
||||
*/
|
||||
private Long size;
|
||||
|
||||
private String sizeStr;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String fileType;
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
*/
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
* 创建(上传)时间 yyyy-MM-dd HH:mm:ss格式
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
/**
|
||||
* 上次修改时间
|
||||
*/
|
||||
private String updateTime;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 文件描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 下载次数
|
||||
*/
|
||||
private Integer downloadCount;
|
||||
|
||||
/**
|
||||
* 网盘标识
|
||||
*/
|
||||
private String panType;
|
||||
|
||||
/**
|
||||
* nfd下载链接(可能获取不到)
|
||||
* note: 不是下载直链
|
||||
*/
|
||||
private String parserUrl;
|
||||
|
||||
//预览地址
|
||||
private String previewUrl;
|
||||
|
||||
// 文件hash默认类型为md5
|
||||
private String hash;
|
||||
|
||||
/**
|
||||
* 扩展参数
|
||||
*/
|
||||
private Map<String, Object> extParameters;
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public FileInfo setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public FileInfo setFileId(String fileId) {
|
||||
this.fileId = fileId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFileIcon() {
|
||||
return fileIcon;
|
||||
}
|
||||
|
||||
public FileInfo setFileIcon(String fileIcon) {
|
||||
this.fileIcon = fileIcon;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public FileInfo setSize(Long size) {
|
||||
this.size = size;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getSizeStr() {
|
||||
return sizeStr;
|
||||
}
|
||||
|
||||
public FileInfo setSizeStr(String sizeStr) {
|
||||
this.sizeStr = sizeStr;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFileType() {
|
||||
return fileType;
|
||||
}
|
||||
|
||||
public FileInfo setFileType(String fileType) {
|
||||
this.fileType = fileType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public FileInfo setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public FileInfo setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public FileInfo setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getCreateBy() {
|
||||
return createBy;
|
||||
}
|
||||
|
||||
public FileInfo setCreateBy(String createBy) {
|
||||
this.createBy = createBy;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public FileInfo setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getDownloadCount() {
|
||||
return downloadCount;
|
||||
}
|
||||
|
||||
public FileInfo setDownloadCount(Integer downloadCount) {
|
||||
this.downloadCount = downloadCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getPanType() {
|
||||
return panType;
|
||||
}
|
||||
|
||||
public FileInfo setPanType(String panType) {
|
||||
this.panType = panType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getParserUrl() {
|
||||
return parserUrl;
|
||||
}
|
||||
|
||||
public FileInfo setParserUrl(String parserUrl) {
|
||||
this.parserUrl = parserUrl;
|
||||
return this;
|
||||
}
|
||||
public String getPreviewUrl() {
|
||||
return previewUrl;
|
||||
}
|
||||
public FileInfo setPreviewUrl(String previewUrl) {
|
||||
this.previewUrl = previewUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public FileInfo setHash(String hash) {
|
||||
this.hash = hash;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, Object> getExtParameters() {
|
||||
return extParameters;
|
||||
}
|
||||
|
||||
public FileInfo setExtParameters(Map<String, Object> extParameters) {
|
||||
this.extParameters = extParameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FileInfo{" +
|
||||
"fileName='" + fileName + '\'' +
|
||||
", fileId='" + fileId + '\'' +
|
||||
", size=" + size +
|
||||
", fileType='" + fileType + '\'' +
|
||||
", filePath='" + filePath + '\'' +
|
||||
", createTime='" + createTime + '\'' +
|
||||
", updateTime='" + updateTime + '\'' +
|
||||
", createBy='" + createBy + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", downloadCount=" + downloadCount +
|
||||
", extParameters=" + extParameters +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
170
parser/src/main/java/cn/qaiu/entity/ShareLinkInfo.java
Normal file
170
parser/src/main/java/cn/qaiu/entity/ShareLinkInfo.java
Normal file
@@ -0,0 +1,170 @@
|
||||
package cn.qaiu.entity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ShareLinkInfo {
|
||||
|
||||
private String shareKey; // 分享键
|
||||
|
||||
private String panName; // 网盘名称
|
||||
private String type; // 分享类型
|
||||
private String sharePassword; // 分享密码(如果存在)
|
||||
private String shareUrl; // 原始分享链接
|
||||
private String standardUrl; // 规范化的标准链接
|
||||
|
||||
/**
|
||||
* 其他参数预定义
|
||||
* dirId: 目录ID 传入
|
||||
* auths: 认证相关 传入
|
||||
* UA: 浏览器请求头 传入
|
||||
* fileInfo: 解析成功的文件信息对象 传出
|
||||
*/
|
||||
private Map<String, Object> otherParam;
|
||||
|
||||
private ShareLinkInfo(Builder builder) {
|
||||
this.shareKey = builder.shareKey;
|
||||
this.panName = builder.panName;
|
||||
this.type = builder.type;
|
||||
this.sharePassword = builder.sharePassword;
|
||||
this.shareUrl = builder.shareUrl;
|
||||
this.standardUrl = builder.standardUrl;
|
||||
this.otherParam = builder.otherParam;
|
||||
}
|
||||
|
||||
// Getter和Setter方法
|
||||
|
||||
public String getShareKey() {
|
||||
return shareKey;
|
||||
}
|
||||
|
||||
public String getPanName() {
|
||||
return panName;
|
||||
}
|
||||
|
||||
public void setShareKey(String shareKey) {
|
||||
this.shareKey = shareKey;
|
||||
}
|
||||
|
||||
public void setPanName(String panName) {
|
||||
this.panName = panName;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getSharePassword() {
|
||||
return sharePassword;
|
||||
}
|
||||
|
||||
public void setSharePassword(String sharePassword) {
|
||||
this.sharePassword = sharePassword;
|
||||
}
|
||||
|
||||
public String getShareUrl() {
|
||||
return shareUrl;
|
||||
}
|
||||
|
||||
public void setShareUrl(String shareUrl) {
|
||||
this.shareUrl = shareUrl;
|
||||
}
|
||||
|
||||
public String getStandardUrl() {
|
||||
return standardUrl;
|
||||
}
|
||||
|
||||
public void setStandardUrl(String standardUrl) {
|
||||
this.standardUrl = standardUrl;
|
||||
}
|
||||
|
||||
public String getCacheKey() {
|
||||
// 将type和shareKey组合成一个字符串作为缓存key
|
||||
String key = type + ":" + shareKey;
|
||||
if (type.equals("p115")) {
|
||||
key += ("_" + otherParam.get("UA").toString().hashCode());
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
public ShareLinkInfo setOtherParam(Map<String, Object> otherParam) {
|
||||
this.otherParam = otherParam;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Map<String, Object> getOtherParam() {
|
||||
return otherParam;
|
||||
}
|
||||
|
||||
// 静态方法创建建造者对象
|
||||
public static ShareLinkInfo.Builder newBuilder() {
|
||||
return new ShareLinkInfo.Builder();
|
||||
}
|
||||
|
||||
// 建造者类
|
||||
public static class Builder {
|
||||
public String panName; // 分享网盘名称
|
||||
private String shareKey; // 分享键
|
||||
private String type; // 分享类型 (网盘模板枚举的小写)
|
||||
private String sharePassword = ""; // 分享密码(如果存在)
|
||||
private String shareUrl; // 原始分享链接
|
||||
private String standardUrl; // 规范化的标准链接
|
||||
private Map<String, Object> otherParam = new HashMap<>(); // 其他参数
|
||||
|
||||
public Builder shareKey(String shareKey) {
|
||||
this.shareKey = shareKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder panName(String panName) {
|
||||
this.panName = panName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder sharePassword(String sharePassword) {
|
||||
this.sharePassword = sharePassword;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder shareUrl(String shareUrl) {
|
||||
this.shareUrl = shareUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder standardUrl(String standardUrl) {
|
||||
this.standardUrl = standardUrl;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder otherParam(Map<String, Object> otherParam) {
|
||||
this.otherParam = otherParam;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ShareLinkInfo build() {
|
||||
return new ShareLinkInfo(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ShareLinkInfo{" +
|
||||
"shareKey='" + shareKey + '\'' +
|
||||
", panName='" + panName + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", sharePassword='" + sharePassword + '\'' +
|
||||
", shareUrl='" + shareUrl + '\'' +
|
||||
", standardUrl='" + standardUrl + '\'' +
|
||||
", otherParam='" + otherParam + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
35
parser/src/main/java/cn/qaiu/parser/IPanTool.java
Normal file
35
parser/src/main/java/cn/qaiu/parser/IPanTool.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package cn.qaiu.parser;//package cn.qaiu.lz.common.parser;
|
||||
|
||||
import cn.qaiu.entity.FileInfo;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Promise;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IPanTool {
|
||||
Future<String> parse();
|
||||
|
||||
default String parseSync() {
|
||||
return parse().toCompletionStage().toCompletableFuture().join();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析文件列表
|
||||
* @return List
|
||||
*/
|
||||
default Future<List<FileInfo>> parseFileList() {
|
||||
Promise<List<FileInfo>> promise = Promise.promise();
|
||||
promise.fail("Not implemented yet");
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文件ID获取下载链接
|
||||
* @return url
|
||||
*/
|
||||
default Future<String> parseById() {
|
||||
Promise<String> promise = Promise.promise();
|
||||
promise.complete("Not implemented yet");
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
303
parser/src/main/java/cn/qaiu/parser/PanBase.java
Normal file
303
parser/src/main/java/cn/qaiu/parser/PanBase.java
Normal file
@@ -0,0 +1,303 @@
|
||||
package cn.qaiu.parser;
|
||||
|
||||
import cn.qaiu.WebClientVertxInit;
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.net.ProxyOptions;
|
||||
import io.vertx.core.net.ProxyType;
|
||||
import io.vertx.ext.web.client.HttpResponse;
|
||||
import io.vertx.ext.web.client.WebClient;
|
||||
import io.vertx.ext.web.client.WebClientOptions;
|
||||
import io.vertx.ext.web.client.WebClientSession;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* 解析器抽象类包含promise, HTTP Client, 默认失败方法等;
|
||||
* 新增网盘解析器需要继承该类. <br>
|
||||
* <h2>实现类命名规则: </h2>
|
||||
* <p>{网盘标识}Tool, 网盘标识不超过5个字符, 可以取网盘名称首字母缩写或拼音首字母, <br>
|
||||
* 音乐类型的解析以M开头, 例如网易云音乐Mne</p>
|
||||
*/
|
||||
public abstract class PanBase implements IPanTool {
|
||||
protected Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
protected Promise<String> promise = Promise.promise();
|
||||
|
||||
/**
|
||||
* Http client
|
||||
*/
|
||||
protected WebClient client = WebClient.create(WebClientVertxInit.get(),
|
||||
new WebClientOptions());
|
||||
|
||||
/**
|
||||
* Http client session (会话管理, 带cookie请求)
|
||||
*/
|
||||
protected WebClientSession clientSession = WebClientSession.create(client);
|
||||
|
||||
/**
|
||||
* Http client 不自动跳转
|
||||
*/
|
||||
protected WebClient clientNoRedirects = WebClient.create(WebClientVertxInit.get(),
|
||||
new WebClientOptions().setFollowRedirects(false));
|
||||
|
||||
protected ShareLinkInfo shareLinkInfo;
|
||||
|
||||
/**
|
||||
* 子类重写此构造方法不需要添加额外逻辑
|
||||
* 如:
|
||||
* <blockquote><pre>
|
||||
* public XxTool(String key, String pwd) {
|
||||
* super(key, pwd);
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param shareLinkInfo 分享链接信息
|
||||
*/
|
||||
public PanBase(ShareLinkInfo shareLinkInfo) {
|
||||
this.shareLinkInfo = shareLinkInfo;
|
||||
if (shareLinkInfo.getOtherParam().containsKey("proxy")) {
|
||||
JsonObject proxy = (JsonObject) shareLinkInfo.getOtherParam().get("proxy");
|
||||
ProxyOptions proxyOptions = new ProxyOptions()
|
||||
.setType(ProxyType.valueOf(proxy.getString("type").toUpperCase()))
|
||||
.setHost(proxy.getString("host"))
|
||||
.setPort(proxy.getInteger("port"));
|
||||
if (StringUtils.isNotEmpty(proxy.getString("username"))) {
|
||||
proxyOptions.setUsername(proxy.getString("username"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(proxy.getString("password"))) {
|
||||
proxyOptions.setPassword(proxy.getString("password"));
|
||||
}
|
||||
this.client = WebClient.create(WebClientVertxInit.get(),
|
||||
new WebClientOptions()
|
||||
.setUserAgentEnabled(false)
|
||||
.setProxyOptions(proxyOptions));
|
||||
|
||||
this.clientSession = WebClientSession.create(client);
|
||||
this.clientNoRedirects = WebClient.create(WebClientVertxInit.get(),
|
||||
new WebClientOptions().setFollowRedirects(false)
|
||||
.setUserAgentEnabled(false)
|
||||
.setProxyOptions(proxyOptions));
|
||||
}
|
||||
}
|
||||
|
||||
protected PanBase() {
|
||||
}
|
||||
|
||||
protected String baseMsg() {
|
||||
if (shareLinkInfo.getShareUrl() != null) {
|
||||
return shareLinkInfo.getPanName() + "-" + shareLinkInfo.getType() + ": url=" + shareLinkInfo.getShareUrl();
|
||||
}
|
||||
return shareLinkInfo.getPanName() + "-" + shareLinkInfo.getType() + ": key=" + shareLinkInfo.getShareKey() +
|
||||
";pwd=" + shareLinkInfo.getSharePassword();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 失败时生成异常消息
|
||||
*
|
||||
* @param t 异常实例
|
||||
* @param errorMsg 提示消息
|
||||
* @param args log参数变量
|
||||
*/
|
||||
protected void fail(Throwable t, String errorMsg, Object... args) {
|
||||
try {
|
||||
// 判断是否已经完成
|
||||
if (promise.future().isComplete()) {
|
||||
log.warn("Promise 已经完成, 无法再次失败: {}, {}", errorMsg, promise.future().cause());
|
||||
return;
|
||||
}
|
||||
String s = String.format(errorMsg.replaceAll("\\{}", "%s"), args);
|
||||
log.error("解析异常: " + s, t.fillInStackTrace());
|
||||
promise.fail(baseMsg() + ": 解析异常: " + s + " -> " + t);
|
||||
} catch (Exception e) {
|
||||
log.error("ErrorMsg format fail. The parameter has been discarded", e);
|
||||
log.error("解析异常: " + errorMsg, t.fillInStackTrace());
|
||||
if (promise.future().isComplete()) {
|
||||
log.warn("ErrorMsg format. Promise 已经完成, 无法再次失败: {}", errorMsg);
|
||||
return;
|
||||
}
|
||||
promise.fail(baseMsg() + ": 解析异常: " + errorMsg + " -> " + t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败时生成异常消息
|
||||
*
|
||||
* @param errorMsg 提示消息
|
||||
* @param args log参数变量
|
||||
*/
|
||||
protected void fail(String errorMsg, Object... args) {
|
||||
try {
|
||||
// 判断是否已经完成
|
||||
if (promise.future().isComplete()) {
|
||||
log.warn("Promise 已经完成, 无法再次失败: {}, {}", errorMsg, promise.future().cause());
|
||||
return;
|
||||
}
|
||||
String s = String.format(errorMsg.replaceAll("\\{}", "%s"), args);
|
||||
promise.fail(baseMsg() + " - 解析异常: " + s);
|
||||
} catch (Exception e) {
|
||||
if (promise.future().isComplete()) {
|
||||
log.warn("ErrorMsg format. Promise 已经完成, 无法再次失败: {}", errorMsg);
|
||||
return;
|
||||
}
|
||||
log.error("ErrorMsg format fail. The parameter has been discarded", e);
|
||||
promise.fail(baseMsg() + " - 解析异常: " + errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
protected void fail() {
|
||||
fail("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成失败Future的处理器
|
||||
*
|
||||
* @param errorMsg 提示消息
|
||||
* @return Handler
|
||||
*/
|
||||
protected Handler<Throwable> handleFail(String errorMsg) {
|
||||
return t -> fail(baseMsg() + " - 请求异常 {}: -> {}", errorMsg, t.fillInStackTrace());
|
||||
}
|
||||
|
||||
protected Handler<Throwable> handleFail() {
|
||||
return handleFail("");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* bodyAsJsonObject的封装, 会自动处理异常
|
||||
*
|
||||
* @param res HttpResponse
|
||||
* @return JsonObject
|
||||
*/
|
||||
protected JsonObject asJson(HttpResponse<?> res) {
|
||||
// 检查响应头中的Content-Encoding是否为gzip
|
||||
String contentEncoding = res.getHeader("Content-Encoding");
|
||||
try {
|
||||
if ("gzip".equalsIgnoreCase(contentEncoding)) {
|
||||
// 如果是gzip压缩的响应体,解压
|
||||
return new JsonObject(decompressGzip((Buffer) res.body()));
|
||||
} else {
|
||||
return res.bodyAsJsonObject();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
if ("gzip".equalsIgnoreCase(contentEncoding)) {
|
||||
// 如果是gzip压缩的响应体,解压
|
||||
try {
|
||||
log.error(decompressGzip((Buffer) res.body()));
|
||||
fail(decompressGzip((Buffer) res.body()));
|
||||
//throw new RuntimeException("响应不是JSON格式");
|
||||
} catch (IOException ex) {
|
||||
log.error("响应gzip解压失败");
|
||||
fail("响应gzip解压失败: {}", ex.getMessage());
|
||||
//throw new RuntimeException("响应gzip解压失败", ex);
|
||||
}
|
||||
} else {
|
||||
log.error("解析失败: json格式异常: {}", res.bodyAsString());
|
||||
fail("解析失败: json格式异常: {}", res.bodyAsString());
|
||||
//throw new RuntimeException("解析失败: json格式异常");
|
||||
}
|
||||
return JsonObject.of();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* body To text的封装, 会自动处理异常, 会自动解压gzip
|
||||
* @param res HttpResponse
|
||||
* @return String
|
||||
*/
|
||||
protected String asText(HttpResponse<?> res) {
|
||||
// 检查响应头中的Content-Encoding是否为gzip
|
||||
String contentEncoding = res.getHeader("Content-Encoding");
|
||||
try {
|
||||
if ("gzip".equalsIgnoreCase(contentEncoding)) {
|
||||
// 如果是gzip压缩的响应体,解压
|
||||
return decompressGzip((Buffer) res.body());
|
||||
} else {
|
||||
return res.bodyAsString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
fail("解析失败: res格式异常");
|
||||
//throw new RuntimeException("解析失败: res格式异常");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void complete(String url) {
|
||||
promise.complete(url);
|
||||
}
|
||||
|
||||
protected Future<String> future() {
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用下一个解析器, 通用域名解析
|
||||
*/
|
||||
protected void nextParser() {
|
||||
Iterator<PanDomainTemplate> iterator = Arrays.asList(PanDomainTemplate.values()).iterator();
|
||||
while (iterator.hasNext()) {
|
||||
if (iterator.next().name().equalsIgnoreCase(shareLinkInfo.getType())) {
|
||||
if (iterator.hasNext()) {
|
||||
PanDomainTemplate next = iterator.next();
|
||||
log.debug("规则不匹配, 处理解析器转发: {} -> {}", shareLinkInfo.getPanName(), next.getDisplayName());
|
||||
ParserCreate.fromType(next.name())
|
||||
.fromAnyShareUrl(shareLinkInfo.getShareUrl())
|
||||
.createTool()
|
||||
.parse()
|
||||
.onComplete(promise);
|
||||
} else {
|
||||
fail("error: 没有下一个解析处理器");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解压gzip数据
|
||||
* @param compressedData compressedData
|
||||
* @return String
|
||||
* @throws IOException IOException
|
||||
*/
|
||||
private String decompressGzip(Buffer compressedData) throws IOException {
|
||||
try (ByteArrayInputStream bais = new ByteArrayInputStream(compressedData.getBytes());
|
||||
GZIPInputStream gzis = new GZIPInputStream(bais);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(gzis,
|
||||
StandardCharsets.UTF_8))) {
|
||||
|
||||
// 用于存储解压后的字符串
|
||||
StringBuilder decompressedData = new StringBuilder();
|
||||
|
||||
// 逐行读取解压后的数据
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
decompressedData.append(line);
|
||||
}
|
||||
|
||||
// 此时decompressedData.toString()包含了解压后的字符串
|
||||
return decompressedData.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected String getDomainName(){
|
||||
return shareLinkInfo.getOtherParam().getOrDefault("domainName", "").toString();
|
||||
}
|
||||
}
|
||||
413
parser/src/main/java/cn/qaiu/parser/PanDomainTemplate.java
Normal file
413
parser/src/main/java/cn/qaiu/parser/PanDomainTemplate.java
Normal file
@@ -0,0 +1,413 @@
|
||||
package cn.qaiu.parser;
|
||||
|
||||
import cn.qaiu.parser.impl.*;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static java.util.regex.Pattern.compile;
|
||||
|
||||
/**
|
||||
* 枚举类 PanDomainTemplate 定义了不同网盘服务的模板信息,包括:
|
||||
* <ul>
|
||||
* <li>displayName: 网盘服务的显示名称,用于用户界面展示。</li>
|
||||
* <li>regexPattern: 用于匹配和解析分享链接的正则表达式。</li>
|
||||
* <li>standardUrlTemplate: 网盘服务的标准URL模板,用于规范化分享链接。</li>
|
||||
* <li>toolClass: 网盘解析工具实现类。</li>
|
||||
* </ul>
|
||||
* 请注意:增添网盘时,保证正则表达式最后一个捕捉组能匹配到分享key
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* at 2023/6/13 4:26
|
||||
*/
|
||||
public enum PanDomainTemplate {
|
||||
|
||||
|
||||
// https://www.ilanzou.com/s/
|
||||
IZ("蓝奏云优享",
|
||||
compile("https://www\\.ilanzou\\.com/s/(?<KEY>.+)"),
|
||||
"https://www.ilanzou.com/s/{shareKey}",
|
||||
IzTool.class),
|
||||
// 网盘定义
|
||||
/*
|
||||
lanzoul.com
|
||||
lanzouh.com
|
||||
lanosso.com
|
||||
lanpv.com
|
||||
bakstotre.com
|
||||
lanzouo.com
|
||||
lanzov.com
|
||||
lanpw.com
|
||||
ulanzou.com
|
||||
lanzouf.com
|
||||
lanzn.com
|
||||
lanzouj.com
|
||||
lanzouk.com
|
||||
lanzouq.com
|
||||
lanzouv.com
|
||||
lanzoue.com
|
||||
lanzouw.com
|
||||
lanzoub.com
|
||||
lanzouu.com
|
||||
lanwp.com
|
||||
lanzouy.com
|
||||
lanzoup.com
|
||||
woozooo.com
|
||||
lanzv.com
|
||||
dmpdmp.com
|
||||
lanrar.com
|
||||
webgetstore.com
|
||||
lanzb.com
|
||||
lanzoux.com
|
||||
lanzout.com
|
||||
lanzouc.com
|
||||
ilanzou.com
|
||||
lanzoui.com
|
||||
lanzoug.com
|
||||
lanzoum.com
|
||||
t-is.cn
|
||||
*/
|
||||
LZ("蓝奏云",
|
||||
compile("https://(?:[a-zA-Z\\d-]+\\.)?(" +
|
||||
"lanzoul|" +
|
||||
"lanzouh|" +
|
||||
"lanosso|" +
|
||||
"lanpv|" +
|
||||
"bakstotre|" +
|
||||
"lanzouo|" +
|
||||
"lanzov|" +
|
||||
"lanpw|" +
|
||||
"ulanzou|" +
|
||||
"lanzouf|" +
|
||||
"lanzn|" +
|
||||
"lanzouj|" +
|
||||
"lanzouk|" +
|
||||
"lanzouq|" +
|
||||
"lanzouv|" +
|
||||
"lanzoue|" +
|
||||
"lanzouw|" +
|
||||
"lanzoub|" +
|
||||
"lanzouu|" +
|
||||
"lanwp|" +
|
||||
"lanzouy|" +
|
||||
"lanzoup|" +
|
||||
"woozooo|" +
|
||||
"lanzv|" +
|
||||
"dmpdmp|" +
|
||||
"lanrar|" +
|
||||
"webgetstore|" +
|
||||
"lanzb|" +
|
||||
"lanzoux|" +
|
||||
"lanzout|" +
|
||||
"lanzouc|" +
|
||||
"lanzoui|" +
|
||||
"lanzoug|" +
|
||||
"lanzoum" +
|
||||
")\\.com/(.+/)?(?<KEY>.+)"),
|
||||
"https://lanzoux.com/{shareKey}",
|
||||
LzTool.class),
|
||||
|
||||
// https://www.feijix.com/s/
|
||||
// https://share.feijipan.com/s/
|
||||
FJ("小飞机网盘",
|
||||
compile("https://(share\\.feijipan\\.com|www\\.feijix\\.com)/s/(?<KEY>.+)"),
|
||||
"https://www.feijix.com/s/{shareKey}",
|
||||
FjTool.class),
|
||||
|
||||
// https://lecloud.lenovo.com/share/
|
||||
LE("联想乐云",
|
||||
compile("https://lecloud?\\.lenovo\\.com/share/(?<KEY>.+)"),
|
||||
"https://lecloud.lenovo.com/share/{shareKey}",
|
||||
LeTool.class),
|
||||
|
||||
// https://v2.fangcloud.com/s/
|
||||
FC("亿方云",
|
||||
compile("https://v2\\.fangcloud\\.(com|cn)/(s|sharing)/(?<KEY>.+)"),
|
||||
"https://v2.fangcloud.com/s/{shareKey}",
|
||||
"https://www.fangcloud.com/",
|
||||
FcTool.class),
|
||||
// https://wx.mail.qq.com/ftn/download?
|
||||
QQ("QQ邮箱中转站",
|
||||
compile("https://i?wx\\.mail\\.qq\\.com/ftn/download\\?(?<KEY>.+)"),
|
||||
"https://iwx.mail.qq.com/ftn/download/{shareKey}",
|
||||
"https://mail.qq.com",
|
||||
QQTool.class),
|
||||
// https://wx.mail.qq.com/s?k=uAG9JR42Rqgt010mFp
|
||||
QQW("QQ邮箱云盘",
|
||||
compile("https://i?wx\\.mail\\.qq\\.com/s\\?k=(?<KEY>.+)"),
|
||||
"https://wx.mail.qq.com/s?k={shareKey}",
|
||||
"https://mail.qq.com",
|
||||
QQwTool.class),
|
||||
// https://qfile.qq.com/q/xxx
|
||||
QQSC("QQ闪传",
|
||||
compile("https://qfile\\.qq\\.com/q/(?<KEY>.+)"),
|
||||
"https://qfile.qq.com/q/{shareKey}",
|
||||
QQscTool.class),
|
||||
// https://f.ws59.cn/f/或者https://www.wenshushu.cn/f/
|
||||
WS("文叔叔",
|
||||
compile("https://(f\\.ws(\\d{2})\\.cn|www\\.wenshushu\\.cn)/f/(?<KEY>.+)"),
|
||||
"https://www.wenshushu.cn/f/{shareKey}",
|
||||
WsTool.class),
|
||||
// https://www.123pan.com/s/
|
||||
/*
|
||||
123254.com
|
||||
123957.com
|
||||
123295.com
|
||||
123panpay.com
|
||||
123860.com
|
||||
123pan.com
|
||||
123245.com
|
||||
123278.com
|
||||
123842.com
|
||||
123294.com
|
||||
123865.com
|
||||
123773.com
|
||||
123624.com
|
||||
123684.com
|
||||
123641.com
|
||||
123259.com
|
||||
123912.com
|
||||
123952.com
|
||||
123652.com
|
||||
123pan.cn
|
||||
123635.com
|
||||
123242.com
|
||||
123795.com
|
||||
*/
|
||||
YE("123网盘",
|
||||
compile("https://www\\.(" +
|
||||
"123254\\.com|" +
|
||||
"123957\\.com|" +
|
||||
"123295\\.com|" +
|
||||
"123panpay\\.com|" +
|
||||
"123860\\.com|" +
|
||||
"123pan\\.com|" +
|
||||
"123245\\.com|" +
|
||||
"123278\\.com|" +
|
||||
"123842\\.com|" +
|
||||
"123294\\.com|" +
|
||||
"123865\\.com|" +
|
||||
"123773\\.com|" +
|
||||
"123624\\.com|" +
|
||||
"123684\\.com|" +
|
||||
"123641\\.com|" +
|
||||
"123259\\.com|" +
|
||||
"123912\\.com|" +
|
||||
"123952\\.com|" +
|
||||
"123652\\.com|" +
|
||||
"123pan\\.cn|" +
|
||||
"123635\\.com|" +
|
||||
"123242\\.com|" +
|
||||
"123795\\.com" +
|
||||
")/s/(?<KEY>.+)(.html)?"),
|
||||
"https://www.123pan.com/s/{shareKey}",
|
||||
YeTool.class),
|
||||
// https://www.ecpan.cn/web/#/yunpanProxy?path=%2F%23%2Fdrive%2Foutside&data={code}&isShare=1
|
||||
EC("移动云空间",
|
||||
compile("https://www\\.ecpan\\.cn/web(/%23|/#)?/yunpanProxy\\?path=.*&data=" +
|
||||
"(?<KEY>[^&]+)&isShare=1"),
|
||||
"https://www.ecpan.cn/web/#/yunpanProxy?path=%2F%23%2Fdrive%2Foutside&data={shareKey}&isShare=1",
|
||||
EcTool.class),
|
||||
// https://cowtransfer.com/s/
|
||||
COW("奶牛快传",
|
||||
compile("https://(.*)cowtransfer\\.com/s/(?<KEY>.+)"),
|
||||
"https://cowtransfer.com/s/{shareKey}",
|
||||
CowTool.class),
|
||||
CT("城通网盘",
|
||||
compile("https://(?:[a-zA-Z\\d-]+\\.)?(ctfile|545c|u062|ghpym|474b)\\.com/f(ile)?/" +
|
||||
"(?<KEY>[0-9a-zA-Z_-]+)(\\?p=(?<PWD>\\w+))?"),
|
||||
"https://474b.com/file/{shareKey}",
|
||||
CtTool.class),
|
||||
// https://xxx.118pan.com/bxxx
|
||||
P118("118网盘",
|
||||
compile("https://(?:[a-zA-Z\\d-]+\\.)?118pan\\.com/b(?<KEY>.+)"),
|
||||
"https://qaiu.118pan.com/b{shareKey}",
|
||||
P118Tool.class),
|
||||
// https://www.vyuyun.com/s/QMa6ie?password=I4KG7H
|
||||
// https://www.vyuyun.com/s/QMa6ie/file?password=I4KG7H
|
||||
PVYY("微雨云存储",
|
||||
compile("https://www\\.vyuyun\\.com/s/(?<KEY>[a-zA-Z\\d-]+)(/file)?(\\?password=(?<PWD>\\w+))?"),
|
||||
"https://www.vyuyun.com/s/{shareKey}?password={pwd}",
|
||||
PvyyTool.class),
|
||||
// https://1drv.ms/w/s!Alg0feQmCv2rnRFd60DQOmMa-Oh_?e=buaRtp
|
||||
// https://1drv.ms/u/c/abfd0a26e47d3458/EdYACWvPq85Et797YmvL5LgBruUKoNxqIFATXhIv1PI2_Q?e=z4ffNJ
|
||||
POD("OneDrive",
|
||||
compile("https://1drv\\.ms/(?<KEY>.+)"),
|
||||
"https://1drv\\.ms/{shareKey}",
|
||||
"https://onedrive.live.com/",
|
||||
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))?"),
|
||||
"https://drive.google.com/file/d/{shareKey}/view?usp=sharing",
|
||||
PgdTool.class),
|
||||
// iCloud https://www.icloud.com.cn/iclouddrive/xxx#fonts
|
||||
PIC("iCloud",
|
||||
compile("https://www\\.icloud\\.com(\\.cn)?/iclouddrive/(?<KEY>[a-z_A-Z\\d-=]+)(#(.+))?"),
|
||||
"https://www.icloud.com.cn/iclouddrive/{shareKey}",
|
||||
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+).*"),
|
||||
"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+))?([&#].*)?"),
|
||||
"https://115.com/s/{shareKey}?password={pwd}",
|
||||
P115Tool.class),
|
||||
// 链接:https://www.yunpan.com/surl_yD7wz4VgU9v(提取码:fc70)
|
||||
// P360("360云盘(需要referer头)",
|
||||
// compile("https://www\\.yunpan\\.com/(?<KEY>\\w+)"),
|
||||
// "https://www.yunpan.com/{shareKey}",
|
||||
// P360Tool.class),
|
||||
|
||||
// https://pan-yz.cldisk.com/external/m/file/953658049102462976
|
||||
Pcx("超星云盘(需要referer头)",
|
||||
compile("https://pan-yz\\.cldisk\\.com/external/m/file/(?<KEY>\\w+)"),
|
||||
"https://pan-yz.cldisk.com/external/m/file/{shareKey}",
|
||||
PcxTool.class),
|
||||
// =====================音乐类解析 分享链接标志->MxxS (单歌曲/普通音质)==========================
|
||||
// http://163cn.tv/xxx
|
||||
MNES("网易云音乐分享",
|
||||
compile("http(s)?://163cn\\.tv/(?<KEY>.+)"),
|
||||
"https://163cn.tv/{shareKey}",
|
||||
MnesTool.class),
|
||||
// https://music.163.com/#/song?id=xxx
|
||||
MNE("网易云音乐歌曲详情",
|
||||
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
|
||||
MQQS("QQ音乐分享",
|
||||
compile("https://(?:[a-zA-Z\\d-]+\\.)?y\\.qq\\.com/base/fcgi-bin/u\\?__=(?<KEY>.+)"),
|
||||
"https://c6.y.qq.com/base/fcgi-bin/u?__={shareKey}",
|
||||
MqqsTool.class),
|
||||
// https://y.qq.com/n/ryqq/songDetail/000XjcLg0fbRjv?songtype=0
|
||||
MQQ("QQ音乐歌曲详情",
|
||||
compile("https://y\\.qq\\.com/n/ryqq/songDetail/(?<KEY>.+)(\\?.*)?"),
|
||||
"https://y.qq.com/n/ryqq/songDetail/{shareKey}",
|
||||
MqqsTool.MqqTool.class),
|
||||
|
||||
// https://t1.kugou.com/song.html?id=xxx
|
||||
MKGS("酷狗音乐分享",
|
||||
compile("https://(?:[a-zA-Z\\d-]+\\.)?kugou\\.com/song\\.html\\?id=(?<KEY>.+)"),
|
||||
"https://t1.kugou.com/song.html?id={shareKey}",
|
||||
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.*"),
|
||||
"https://www.kugou.com/share/{shareKey}.html",
|
||||
MkgsTool.Mkgs2Tool.class),
|
||||
// https://www.kugou.com/mixsong/2bi8Fe9CSV3
|
||||
MKG("酷狗音乐歌曲详情",
|
||||
compile("https://(?:[a-zA-Z\\d-]+\\.)?kugou\\.com/mixsong/(?<KEY>.+)\\.html.*"),
|
||||
"https://www.kugou.com/mixsong/{shareKey}.html",
|
||||
MkgsTool.MkgTool.class),
|
||||
// https://kuwo.cn/play_detail/395500809
|
||||
// https://m.kuwo.cn/newh5app/play_detail/318448522
|
||||
MKWS("酷我音乐分享*",
|
||||
compile("https://(m\\.)?kuwo\\.cn/(newh5app/)?play_detail/(?<KEY>.+)"),
|
||||
"https://kuwo.cn/play_detail/{shareKey}",
|
||||
MkwTool.class),
|
||||
// https://music.migu.cn/v3/music/song/6326951FKBJ?channelId=001002H
|
||||
MMGS("咪咕音乐分享",
|
||||
compile("https://music\\.migu\\.cn/v3/music/song/(?<KEY>.+)(\\?.*)?"),
|
||||
"https://music.migu.cn/v3/music/song/{shareKey}",
|
||||
MmgTool.class),
|
||||
// =====================私有盘解析==========================
|
||||
|
||||
// Cloudreve自定义域名解析, 解析器CeTool兜底策略, 即任意域名如果匹配不到对应的规则, 则由CeTool统一处理,
|
||||
// 如果不属于Cloudreve盘 则调用下一个自定义域名解析器, 若都处理不了则抛出异常, 这种匹配模式类似责任链
|
||||
// https://pan.huang1111.cn/s/xxx
|
||||
// 通用域名([a-z\\d]+(-[a-z\\d]+)*\.)+[a-z]{2,}
|
||||
CE("Cloudreve",
|
||||
compile("http(s)?://([a-zA-Z\\d]+(-[a-zA-Z\\d]+)*\\.)+[a-zA-Z]{2,}(/s)?/(?<KEY>.+)"),
|
||||
"https://{any}/s/{shareKey}",
|
||||
"https://cloudreve.org/",
|
||||
CeTool.class),
|
||||
// 可道云自定义域名解析
|
||||
KD("可道云",
|
||||
compile("http(s)?://([a-zA-Z\\d]+(-[a-zA-Z\\d]+)*\\.)+[a-zA-Z]{2,}(/#s)?/(?<KEY>.+)"),
|
||||
"https://{any}/#s/{shareKey}",
|
||||
"https://kodcloud.com/",
|
||||
KdTool.class),
|
||||
// 其他自定义域名解析
|
||||
OTHER("其他网盘",
|
||||
compile("http(s)?://([a-zA-Z\\d]+(-[a-zA-Z\\d]+)*\\.)+[a-zA-Z]{2,}/(?<KEY>.+)"),
|
||||
"https://{any}/{shareKey}",
|
||||
OtherTool.class);
|
||||
|
||||
public static final String KEY = "KEY";
|
||||
|
||||
public static final String PWD = "PWD";
|
||||
|
||||
// 网盘的显示名称,用于用户界面显示
|
||||
private final String displayName;
|
||||
|
||||
// 用于匹配和解析分享链接的正则表达式,保证最后一个捕捉组能匹配到分享key
|
||||
private final Pattern pattern;
|
||||
|
||||
private final String regex;
|
||||
|
||||
// 网盘的标准链接模板,不含占位符,用于规范化分享链接
|
||||
private final String standardUrlTemplate;
|
||||
|
||||
// 网盘的域名, 如果在分享链接里能提取到, 则可不写
|
||||
private String panDomain;
|
||||
|
||||
// 指向解析工具IPanTool实现类
|
||||
private final Class<? extends IPanTool> toolClass;
|
||||
|
||||
PanDomainTemplate(String displayName, Pattern pattern, String standardUrlTemplate,
|
||||
Class<? extends IPanTool> toolClass) {
|
||||
this.displayName = displayName;
|
||||
this.pattern = pattern;
|
||||
this.regex = pattern.pattern();
|
||||
this.standardUrlTemplate = standardUrlTemplate;
|
||||
this.toolClass = toolClass;
|
||||
}
|
||||
|
||||
PanDomainTemplate(String displayName, Pattern pattern, String standardUrlTemplate, String panDomain,
|
||||
Class<? extends IPanTool> toolClass) {
|
||||
this.displayName = displayName;
|
||||
this.pattern = pattern;
|
||||
this.regex = pattern.pattern();
|
||||
this.standardUrlTemplate = standardUrlTemplate;
|
||||
this.panDomain = panDomain;
|
||||
this.toolClass = toolClass;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public Pattern getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
public String getRegex() {
|
||||
return regex;
|
||||
}
|
||||
|
||||
public String getStandardUrlTemplate() {
|
||||
return standardUrlTemplate;
|
||||
}
|
||||
|
||||
public Class<? extends IPanTool> getToolClass() {
|
||||
return toolClass;
|
||||
}
|
||||
|
||||
public String getPanDomain() {
|
||||
if (panDomain == null) {
|
||||
String url = standardUrlTemplate
|
||||
.replace("{shareKey}", "");
|
||||
URL panDomainUrl = null;
|
||||
try {
|
||||
panDomainUrl = new URL(url);
|
||||
} catch (MalformedURLException ignored) {}
|
||||
|
||||
return panDomainUrl != null ? (panDomainUrl.getProtocol() + "://" + panDomainUrl.getHost()) : "无";
|
||||
}
|
||||
return panDomain;
|
||||
}
|
||||
}
|
||||
182
parser/src/main/java/cn/qaiu/parser/ParserCreate.java
Normal file
182
parser/src/main/java/cn/qaiu/parser/ParserCreate.java
Normal file
@@ -0,0 +1,182 @@
|
||||
package cn.qaiu.parser;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import static cn.qaiu.parser.PanDomainTemplate.KEY;
|
||||
import static cn.qaiu.parser.PanDomainTemplate.PWD;
|
||||
|
||||
|
||||
/**
|
||||
* 该类提供方法来解析和规范化不同来源的分享链接,确保它们可以转换为统一的标准链接格式。
|
||||
* 通过这种方式,应用程序可以更容易地处理和识别不同网盘服务的分享链接。
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* @date 2024/9/15 14:10
|
||||
*/
|
||||
public class ParserCreate {
|
||||
private final PanDomainTemplate panDomainTemplate;
|
||||
private final ShareLinkInfo shareLinkInfo;
|
||||
|
||||
private String standardUrl;
|
||||
|
||||
public ParserCreate(PanDomainTemplate panDomainTemplate, ShareLinkInfo shareLinkInfo) {
|
||||
this.panDomainTemplate = panDomainTemplate;
|
||||
this.shareLinkInfo = shareLinkInfo;
|
||||
this.standardUrl = panDomainTemplate.getStandardUrlTemplate();
|
||||
}
|
||||
|
||||
|
||||
// 解析并规范化分享链接
|
||||
public ParserCreate normalizeShareLink() {
|
||||
if (shareLinkInfo == null) {
|
||||
throw new IllegalArgumentException("ShareLinkInfo not init");
|
||||
}
|
||||
// 匹配并提取shareKey
|
||||
String shareUrl = shareLinkInfo.getShareUrl();
|
||||
if (StringUtils.isEmpty(shareUrl)) {
|
||||
throw new IllegalArgumentException("ShareLinkInfo shareUrl is empty");
|
||||
}
|
||||
Matcher matcher = this.panDomainTemplate.getPattern().matcher(shareUrl);
|
||||
if (matcher.find()) {
|
||||
String k0 = matcher.group(KEY);
|
||||
String shareKey = URLEncoder.encode(k0, StandardCharsets.UTF_8);
|
||||
|
||||
// 返回规范化的标准链接
|
||||
standardUrl = getStandardUrlTemplate()
|
||||
.replace("{shareKey}", k0);
|
||||
|
||||
try {
|
||||
String pwd = matcher.group(PWD);
|
||||
if (StringUtils.isNotEmpty(pwd)) {
|
||||
shareLinkInfo.setSharePassword(pwd);
|
||||
}
|
||||
standardUrl = standardUrl.replace("{pwd}", pwd);
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
shareLinkInfo.setShareUrl(shareUrl);
|
||||
shareLinkInfo.setShareKey(shareKey);
|
||||
if (!(panDomainTemplate.ordinal() >= PanDomainTemplate.CE.ordinal())) {
|
||||
shareLinkInfo.setStandardUrl(standardUrl);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid share URL for " + this.panDomainTemplate.getDisplayName());
|
||||
}
|
||||
|
||||
public IPanTool createTool() {
|
||||
if (shareLinkInfo == null || StringUtils.isEmpty(shareLinkInfo.getType())) {
|
||||
throw new IllegalArgumentException("ShareLinkInfo not init or type is empty");
|
||||
}
|
||||
if (StringUtils.isEmpty(shareLinkInfo.getShareKey())) {
|
||||
this.normalizeShareLink();
|
||||
}
|
||||
try {
|
||||
return this.panDomainTemplate.getToolClass()
|
||||
.getDeclaredConstructor(ShareLinkInfo.class)
|
||||
.newInstance(shareLinkInfo);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("无法创建工具实例: " + panDomainTemplate.getToolClass().getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// set share key
|
||||
public ParserCreate shareKey(String shareKey) {
|
||||
if (panDomainTemplate.ordinal() >= PanDomainTemplate.CE.ordinal()) {
|
||||
// 处理Cloudreve(ce)类: pan.huang1111.cn_s_wDz5TK _ -> /
|
||||
String[] s = shareKey.split("_");
|
||||
String standardUrl = "https://" + String.join("/", s);
|
||||
shareLinkInfo.setShareKey(s[s.length - 1]);
|
||||
shareLinkInfo.setStandardUrl(standardUrl);
|
||||
shareLinkInfo.setShareUrl(standardUrl);
|
||||
} else {
|
||||
shareLinkInfo.setShareKey(shareKey);
|
||||
standardUrl = standardUrl.replace("{shareKey}", shareKey);
|
||||
shareLinkInfo.setStandardUrl(standardUrl);
|
||||
}
|
||||
if (StringUtils.isEmpty(shareLinkInfo.getShareUrl())) {
|
||||
shareLinkInfo.setShareUrl(standardUrl);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// set any share url
|
||||
public ParserCreate fromAnyShareUrl(String url) {
|
||||
shareLinkInfo.setStandardUrl(url);
|
||||
shareLinkInfo.setShareUrl(url);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getStandardUrlTemplate() {
|
||||
return this.panDomainTemplate.getStandardUrlTemplate();
|
||||
}
|
||||
|
||||
public ShareLinkInfo getShareLinkInfo() {
|
||||
return shareLinkInfo;
|
||||
}
|
||||
|
||||
public ParserCreate setShareLinkInfoPwd(String pwd) {
|
||||
if (pwd != null) {
|
||||
shareLinkInfo.setSharePassword(pwd);
|
||||
standardUrl = standardUrl.replace("{pwd}", pwd);
|
||||
shareLinkInfo.setStandardUrl(standardUrl);
|
||||
if (shareLinkInfo.getShareUrl().contains("{pwd}")) {
|
||||
shareLinkInfo.setShareUrl(standardUrl);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// 根据分享链接获取PanDomainTemplate实例
|
||||
public synchronized static ParserCreate fromShareUrl(String shareUrl) {
|
||||
for (PanDomainTemplate panDomainTemplate : PanDomainTemplate.values()) {
|
||||
if (panDomainTemplate.getPattern().matcher(shareUrl).matches()) {
|
||||
ShareLinkInfo shareLinkInfo = ShareLinkInfo.newBuilder()
|
||||
.type(panDomainTemplate.name().toLowerCase())
|
||||
.panName(panDomainTemplate.getDisplayName())
|
||||
.shareUrl(shareUrl).build();
|
||||
if (panDomainTemplate.ordinal() >= PanDomainTemplate.CE.ordinal()) {
|
||||
shareLinkInfo.setStandardUrl(shareUrl);
|
||||
}
|
||||
ParserCreate parserCreate = new ParserCreate(panDomainTemplate, shareLinkInfo);
|
||||
return parserCreate.normalizeShareLink();
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported share URL");
|
||||
}
|
||||
|
||||
// 根据type获取枚举实例
|
||||
public synchronized static ParserCreate fromType(String type) {
|
||||
try {
|
||||
PanDomainTemplate panDomainTemplate = Enum.valueOf(PanDomainTemplate.class, type.toUpperCase());
|
||||
ShareLinkInfo shareLinkInfo = ShareLinkInfo.newBuilder()
|
||||
.type(type.toLowerCase()).build();
|
||||
shareLinkInfo.setPanName(panDomainTemplate.getDisplayName());
|
||||
return new ParserCreate(panDomainTemplate, shareLinkInfo);
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
// 如果没有找到对应的枚举实例,抛出异常
|
||||
throw new IllegalArgumentException("No enum constant for type name: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成parser短链path(不包含domainName)
|
||||
public String genPathSuffix() {
|
||||
|
||||
String path;
|
||||
if (panDomainTemplate.ordinal() >= PanDomainTemplate.CE.ordinal()) {
|
||||
// 处理Cloudreve(ce)类: pan.huang1111.cn_s_wDz5TK _ -> /
|
||||
path = this.shareLinkInfo.getType() + "/"
|
||||
+ this.shareLinkInfo.getShareUrl()
|
||||
.substring("https://".length()).replace("/", "_");
|
||||
} else {
|
||||
path = this.shareLinkInfo.getType() + "/" + this.shareLinkInfo.getShareKey();
|
||||
}
|
||||
String sharePassword = this.shareLinkInfo.getSharePassword();
|
||||
return path + (StringUtils.isBlank(sharePassword) ? "" : ("@" + sharePassword));
|
||||
}
|
||||
|
||||
}
|
||||
84
parser/src/main/java/cn/qaiu/parser/impl/CeTool.java
Normal file
84
parser/src/main/java/cn/qaiu/parser/impl/CeTool.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.parser.PanDomainTemplate;
|
||||
import cn.qaiu.parser.ParserCreate;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.client.HttpRequest;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* <a href="https://github.com/cloudreve/Cloudreve">Cloudreve自建网盘解析</a> <br>
|
||||
* <a href="https://pan.xiaomuxi.cn">暮希云盘</a> <br>
|
||||
* <a href="https://pan.huang1111.cn">huang1111</a> <br>
|
||||
* <a href="https://pan.seeoss.com">看见存储</a> <br>
|
||||
* <a href="https://dav.yiandrive.com">亿安云盘</a> <br>
|
||||
*/
|
||||
public class CeTool extends PanBase {
|
||||
|
||||
private static final String DOWNLOAD_API_PATH = "/api/v3/share/download/";
|
||||
|
||||
// api/v3/share/info/g31PcQ?password=qaiu
|
||||
private static final String SHARE_API_PATH = "/api/v3/share/info/";
|
||||
|
||||
public CeTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
|
||||
public Future<String> parse() {
|
||||
String key = shareLinkInfo.getShareKey();
|
||||
String pwd = shareLinkInfo.getSharePassword();
|
||||
// https://pan.huang1111.cn/s/wDz5TK
|
||||
// https://pan.huang1111.cn/s/y12bI6 -> https://pan.huang1111
|
||||
// .cn/api/v3/share/download/y12bI6?path=undefined%2Fundefined;
|
||||
// 类型解析 -> /ce/pan.huang1111.cn_s_wDz5TK
|
||||
// parser接口 -> /parser?url=https://pan.huang1111.cn/s/wDz5TK
|
||||
try {
|
||||
// // 处理URL
|
||||
URL url = new URL(shareLinkInfo.getShareUrl());
|
||||
String downloadApiUrl = url.getProtocol() + "://" + url.getHost() + DOWNLOAD_API_PATH + key + "?path" +
|
||||
"=undefined/undefined;";
|
||||
String shareApiUrl = url.getProtocol() + "://" + url.getHost() + SHARE_API_PATH + key;
|
||||
// 设置cookie
|
||||
HttpRequest<Buffer> httpRequest = clientSession.getAbs(shareApiUrl);
|
||||
if (pwd != null) {
|
||||
httpRequest.addQueryParam("password", pwd);
|
||||
}
|
||||
// 获取下载链接
|
||||
httpRequest.send().onSuccess(res -> {
|
||||
try {
|
||||
if (res.statusCode() == 200 && res.bodyAsJsonObject().containsKey("code")) {
|
||||
getDownURL(downloadApiUrl);
|
||||
} else {
|
||||
nextParser();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
nextParser();
|
||||
}
|
||||
}).onFailure(handleFail(shareApiUrl));
|
||||
} catch (Exception e) {
|
||||
fail(e, "URL解析错误");
|
||||
}
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
|
||||
private void getDownURL(String shareApiUrl) {
|
||||
clientSession.putAbs(shareApiUrl).send().onSuccess(res -> {
|
||||
JsonObject jsonObject = asJson(res);
|
||||
System.out.println(jsonObject.encodePrettily());
|
||||
if (jsonObject.containsKey("code") && jsonObject.getInteger("code") == 0) {
|
||||
promise.complete(jsonObject.getString("data"));
|
||||
} else {
|
||||
fail("JSON解析失败: {}", jsonObject.encodePrettily());
|
||||
}
|
||||
}).onFailure(handleFail(shareApiUrl));
|
||||
}
|
||||
}
|
||||
64
parser/src/main/java/cn/qaiu/parser/impl/CowTool.java
Normal file
64
parser/src/main/java/cn/qaiu/parser/impl/CowTool.java
Normal file
@@ -0,0 +1,64 @@
|
||||
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 org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 奶牛快传解析工具
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
* @date 2023/4/21 21:19
|
||||
*/
|
||||
public class CowTool extends PanBase {
|
||||
|
||||
private static final String API_REQUEST_URL = "https://cowtransfer.com/core/api/transfer/share";
|
||||
|
||||
public CowTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
|
||||
public Future<String> parse() {
|
||||
final String key = shareLinkInfo.getShareKey();
|
||||
String url = API_REQUEST_URL + "?uniqueUrl=" + key;
|
||||
client.getAbs(url).send().onSuccess(res -> {
|
||||
JsonObject resJson = asJson(res);
|
||||
if ("success".equals(resJson.getString("message")) && resJson.containsKey("data")) {
|
||||
JsonObject dataJson = resJson.getJsonObject("data");
|
||||
String guid = dataJson.getString("guid");
|
||||
StringBuilder url2Build = new StringBuilder(API_REQUEST_URL + "/download?transferGuid=" + guid);
|
||||
if (dataJson.getBoolean("zipDownload")) {
|
||||
// &title=xxx
|
||||
JsonObject firstFolder = dataJson.getJsonObject("firstFolder");
|
||||
url2Build.append("&title=").append(firstFolder.getString("title"));
|
||||
} else {
|
||||
String fileId = dataJson.getJsonObject("firstFile").getString("id");
|
||||
url2Build.append("&fileId=").append(fileId);
|
||||
}
|
||||
String url2 = url2Build.toString();
|
||||
client.getAbs(url2).send().onSuccess(res2 -> {
|
||||
JsonObject res2Json = asJson(res2);
|
||||
if ("success".equals(res2Json.getString("message")) && res2Json.containsKey("data")) {
|
||||
JsonObject data2 = res2Json.getJsonObject("data");
|
||||
String downloadUrl = data2.getString("downloadUrl");
|
||||
if (StringUtils.isNotEmpty(downloadUrl)) {
|
||||
log.info("cow parse success: {}", downloadUrl);
|
||||
promise.complete(downloadUrl);
|
||||
return;
|
||||
}
|
||||
fail("cow parse fail: {}; downloadUrl is empty", url2);
|
||||
return;
|
||||
}
|
||||
fail("cow parse fail: {}; json: {}", url2, res2Json);
|
||||
}).onFailure(handleFail(url2));
|
||||
return;
|
||||
}
|
||||
fail("cow parse fail: {}; json: {}", key, resJson);
|
||||
}).onFailure(handleFail(url));
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
}
|
||||
105
parser/src/main/java/cn/qaiu/parser/impl/CtTool.java
Normal file
105
parser/src/main/java/cn/qaiu/parser/impl/CtTool.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.RandomStringGenerator;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.client.HttpRequest;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <a href="https://www.ctfile.com">诚通网盘</a>
|
||||
*/
|
||||
public class CtTool extends PanBase {
|
||||
private static final String API_URL_PREFIX = "https://webapi.ctfile.com";
|
||||
|
||||
// https://webapi.ctfile.com/getfile.php?path=f&f=55050874-1246660795-6464f6&
|
||||
// passcode=7548&token=30wiijxs1fzhb6brw0p9m6&r=0.5885881231735761&
|
||||
// ref=&url=https%3A%2F%2F474b.com%2Ff%2F55050874-1246660795-6464f6%3Fp%3D7548
|
||||
private static final String API1 = API_URL_PREFIX + "/getfile.php?path={path}" +
|
||||
"&f={shareKey}&passcode={pwd}&token={token}&r={rand}&ref=";
|
||||
|
||||
//https://webapi.ctfile.com/get_file_url.php?uid=55050874&fid=1246660795&folder_id=0&
|
||||
// file_chk=054bc20461f5c63ff82015b9e69fb7fc&mb=1&token=30wiijxs1fzhb6brw0p9m6&app=0&
|
||||
// acheck=1&verifycode=&rd=0.965929071503574
|
||||
private static final String API2 = API_URL_PREFIX + "/get_file_url.php?" +
|
||||
"uid={uid}&fid={fid}&folder_id=0&file_chk={file_chk}&mb=0&token={token}&app=0&acheck=0&verifycode=" +
|
||||
"&rd={rand}";
|
||||
|
||||
|
||||
/**
|
||||
* 子类重写此构造方法不需要添加额外逻辑
|
||||
* 如:
|
||||
* <blockquote><pre>
|
||||
* public XxTool(String key, String pwd) {
|
||||
* super(key, pwd);
|
||||
* }
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param shareLinkInfo 分享链接信息
|
||||
*/
|
||||
public CtTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
final String shareKey = shareLinkInfo.getShareKey();
|
||||
if (shareKey.indexOf('-') == -1) {
|
||||
fail("shareKey格式不正确找不到'-': {}", shareKey);
|
||||
return promise.future();
|
||||
}
|
||||
String[] split = shareKey.split("-");
|
||||
String uid = split[0], fid = split[1];
|
||||
String token = RandomStringGenerator.generateRandomString();
|
||||
// 获取url path
|
||||
int i1 = shareLinkInfo.getShareUrl().indexOf("com/");
|
||||
int i2 = shareLinkInfo.getShareUrl().lastIndexOf("/");
|
||||
String path = shareLinkInfo.getShareUrl().substring(i1 + 4, i2);
|
||||
|
||||
HttpRequest<Buffer> bufferHttpRequest1 = clientSession.getAbs(UriTemplate.of(API1))
|
||||
.setTemplateParam("path", path)
|
||||
.setTemplateParam("shareKey", shareKey)
|
||||
.setTemplateParam("pwd", shareLinkInfo.getSharePassword())
|
||||
.setTemplateParam("token", token)
|
||||
.setTemplateParam("r", Math.random() + "");
|
||||
|
||||
bufferHttpRequest1
|
||||
.send().onSuccess(res -> {
|
||||
var resJson = asJson(res);
|
||||
if (resJson.containsKey("file")) {
|
||||
var fileJson = resJson.getJsonObject("file");
|
||||
if (fileJson.containsKey("file_chk")) {
|
||||
var file_chk = fileJson.getString("file_chk");
|
||||
HttpRequest<Buffer> bufferHttpRequest2 = clientSession.getAbs(UriTemplate.of(API2))
|
||||
.setTemplateParam("uid", uid)
|
||||
.setTemplateParam("fid", fid)
|
||||
.setTemplateParam("file_chk", file_chk)
|
||||
.setTemplateParam("token", token)
|
||||
.setTemplateParam("rd", Math.random() + "");
|
||||
bufferHttpRequest2
|
||||
.send().onSuccess(res2 -> {
|
||||
JsonObject resJson2 = asJson(res2);
|
||||
if (resJson2.containsKey("downurl")) {
|
||||
promise.complete(resJson2.getString("downurl"));
|
||||
} else {
|
||||
fail("解析失败, 可能分享已失效: json: {} 字段 {} 不存在", resJson2, "downurl");
|
||||
}
|
||||
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
|
||||
} else {
|
||||
fail("解析失败, file_chk找不到, 可能分享已失效或者分享密码不对: {}", fileJson);
|
||||
}
|
||||
} else {
|
||||
fail("解析失败, 文件信息为空, 可能分享已失效");
|
||||
}
|
||||
}).onFailure(handleFail(bufferHttpRequest1.queryParams().toString()));
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
69
parser/src/main/java/cn/qaiu/parser/impl/EcTool.java
Normal file
69
parser/src/main/java/cn/qaiu/parser/impl/EcTool.java
Normal file
@@ -0,0 +1,69 @@
|
||||
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.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
/**
|
||||
* 移动云空间解析
|
||||
*/
|
||||
public class EcTool extends PanBase {
|
||||
// https://www.ecpan.cn/web/#/yunpanProxy?path=%2F%23%2Fdrive%2Foutside&data=4b3d786755688b85c6eb0c04b9124f4dalzdaJpXHx&isShare=1
|
||||
private static final String FIRST_REQUEST_URL = "https://www.ecpan.cn/drive/fileextoverrid" +
|
||||
".do?extractionCode={extractionCode}&chainUrlTemplate=https:%2F%2Fwww.ecpan" +
|
||||
".cn%2Fweb%2F%23%2FyunpanProxy%3Fpath%3D%252F%2523%252Fdrive%252Foutside&parentId=-1&data={dataKey}";
|
||||
|
||||
private static final String DOWNLOAD_REQUEST_URL = "https://www.ecpan.cn/drive/sharedownload.do";
|
||||
|
||||
public EcTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
|
||||
public Future<String> parse() {
|
||||
final String dataKey = shareLinkInfo.getShareKey();
|
||||
final String pwd = shareLinkInfo.getSharePassword();
|
||||
|
||||
// 第一次请求 获取文件信息
|
||||
client.getAbs(UriTemplate.of(FIRST_REQUEST_URL))
|
||||
.setTemplateParam("dataKey", dataKey)
|
||||
.setTemplateParam("extractionCode", pwd == null ? "" : pwd)
|
||||
.send()
|
||||
.onSuccess(res -> {
|
||||
JsonObject jsonObject = asJson(res);
|
||||
log.debug("ecPan get file info -> {}", jsonObject);
|
||||
JsonObject fileInfo = jsonObject
|
||||
.getJsonObject("var")
|
||||
.getJsonObject("chainFileInfo");
|
||||
if (fileInfo.containsKey("errMesg")) {
|
||||
fail("{} 解析失败:{} key = {}", FIRST_REQUEST_URL, fileInfo.getString("errMesg"), dataKey);
|
||||
return;
|
||||
}
|
||||
if (!fileInfo.containsKey("cloudpFile")) {
|
||||
fail("{} 解析失败:cloudpFile不存在 key = {}", FIRST_REQUEST_URL, dataKey);
|
||||
return;
|
||||
}
|
||||
|
||||
JsonObject cloudpFile = fileInfo.getJsonObject("cloudpFile");
|
||||
JsonArray fileIdList = JsonArray.of(cloudpFile);
|
||||
// 构造请求JSON {"extCodeFlag":0,"isIp":0}
|
||||
JsonObject requestBodyJson = JsonObject.of("extCodeFlag", 0, "isIp", 0);
|
||||
requestBodyJson.put("shareId", Integer.parseInt(fileInfo.getString("shareId"))); // 注意shareId
|
||||
// 数据类型
|
||||
requestBodyJson.put("groupId", cloudpFile.getString("groupId"));
|
||||
requestBodyJson.put("fileIdList", fileInfo.getJsonArray("cloudpFileList"));
|
||||
|
||||
// 第二次请求 获取下载链接
|
||||
client.postAbs(DOWNLOAD_REQUEST_URL).sendJsonObject(requestBodyJson).onSuccess(res2 -> {
|
||||
JsonObject jsonRes = asJson(res2);
|
||||
log.debug("ecPan get download url -> {}", res2.body().toString());
|
||||
promise.complete(jsonRes.getJsonObject("var").getString("downloadUrl"));
|
||||
}).onFailure(handleFail(""));
|
||||
}
|
||||
).onFailure(handleFail(FIRST_REQUEST_URL));
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
102
parser/src/main/java/cn/qaiu/parser/impl/FcTool.java
Normal file
102
parser/src/main/java/cn/qaiu/parser/impl/FcTool.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.client.HttpResponse;
|
||||
import io.vertx.ext.web.client.WebClientSession;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 360亿方云
|
||||
*/
|
||||
public class FcTool extends PanBase {
|
||||
|
||||
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 DOWN_REQUEST_URL = "https://v2.fangcloud.cn/apps/files/download?file_id={fid}" +
|
||||
"&scenario=share&unique_name={uname}";
|
||||
|
||||
public FcTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
|
||||
public Future<String> parse() {
|
||||
final String dataKey = shareLinkInfo.getShareKey();
|
||||
final String pwd = shareLinkInfo.getSharePassword();
|
||||
WebClientSession sClient = WebClientSession.create(client);
|
||||
// 第一次请求 自动重定向
|
||||
sClient.getAbs(SHARE_URL_PREFIX + dataKey).send().onSuccess(res -> {
|
||||
|
||||
// 判断是否是加密分享
|
||||
if (StringUtils.isNotEmpty(pwd)) {
|
||||
// 获取requesttoken
|
||||
String html = res.bodyAsString();
|
||||
Pattern compile = Pattern.compile("name=\"requesttoken\"\\s+value=\"([a-zA-Z0-9_+=]+)\"");
|
||||
Matcher matcher = compile.matcher(html);
|
||||
if (!matcher.find()) {
|
||||
fail(SHARE_URL_PREFIX + " 未匹配到加密分享的密码输入页面的requesttoken");
|
||||
return;
|
||||
}
|
||||
String token = matcher.group(1);
|
||||
|
||||
sClient.postAbs(SHARE_URL_PREFIX2 + dataKey).sendForm(MultiMap.caseInsensitiveMultiMap()
|
||||
.set("requesttoken", token)
|
||||
.set("password", pwd)).onSuccess(res2 -> {
|
||||
if (res2.statusCode() == 302) {
|
||||
sClient.getAbs(res2.getHeader("Location")).send()
|
||||
.onSuccess(res3 -> getDownURL(dataKey, promise, res3, sClient))
|
||||
.onFailure(handleFail(res2.getHeader("Location")));
|
||||
return;
|
||||
}
|
||||
fail(SHARE_URL_PREFIX + " 密码跳转后获取重定向失败");
|
||||
}).onFailure(handleFail(SHARE_URL_PREFIX2));
|
||||
return;
|
||||
}
|
||||
getDownURL(dataKey, promise, res, sClient);
|
||||
}).onFailure(handleFail(SHARE_URL_PREFIX + dataKey));
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private void getDownURL(String dataKey, Promise<String> promise, HttpResponse<Buffer> res,
|
||||
WebClientSession sClient) {
|
||||
// 从HTML中找到文件id
|
||||
String html = res.bodyAsString();
|
||||
Pattern compile = Pattern.compile("id=\"typed_id\"\\s+value=\"file_(\\d+)\"");
|
||||
Matcher matcher = compile.matcher(html);
|
||||
if (!matcher.find()) {
|
||||
fail(SHARE_URL_PREFIX + " 未匹配到文件id(typed_id)");
|
||||
return;
|
||||
}
|
||||
String fid = matcher.group(1);
|
||||
|
||||
// 创建一个不自动重定向的WebClientSession
|
||||
WebClientSession sClientNoRedirects = WebClientSession.create(clientNoRedirects, sClient.cookieStore());
|
||||
// 第二次请求
|
||||
sClientNoRedirects.getAbs(UriTemplate.of(DOWN_REQUEST_URL))
|
||||
.setTemplateParam("fid", fid)
|
||||
.setTemplateParam("unique_name", dataKey).send().onSuccess(res2 -> {
|
||||
JsonObject resJson;
|
||||
try {
|
||||
resJson = asJson(res2);
|
||||
} catch (Exception e) {
|
||||
fail(e, DOWN_REQUEST_URL + " 第二次请求没有返回JSON, 可能下载受限");
|
||||
return;
|
||||
}
|
||||
if (!resJson.getBoolean("success")) {
|
||||
fail(DOWN_REQUEST_URL + " 第二次请求未得到正确相应: " + resJson);
|
||||
return;
|
||||
}
|
||||
promise.complete(resJson.getString("download_url"));
|
||||
}).onFailure(handleFail(DOWN_REQUEST_URL));
|
||||
}
|
||||
}
|
||||
308
parser/src/main/java/cn/qaiu/parser/impl/FjTool.java
Normal file
308
parser/src/main/java/cn/qaiu/parser/impl/FjTool.java
Normal file
@@ -0,0 +1,308 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.FileInfo;
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.AESUtils;
|
||||
import cn.qaiu.util.FileSizeConverter;
|
||||
import cn.qaiu.util.UUIDUtil;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.client.HttpRequest;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 小飞机网盘
|
||||
*
|
||||
* @version V016_230609
|
||||
*/
|
||||
public class FjTool extends PanBase {
|
||||
public static final String REFERER_URL = "https://share.feijipan.com/";
|
||||
private static final String API_URL_PREFIX = "https://api.feijipan.com/ws/";
|
||||
|
||||
private static final String FIRST_REQUEST_URL = API_URL_PREFIX + "recommend/list?devType=6&devModel=Chrome" +
|
||||
"&uuid={uuid}&extra=2×tamp={ts}&shareId={shareId}&type=0&offset=1&limit=60";
|
||||
/// recommend/list?devType=6&devModel=Chrome&uuid={uuid}&extra=2×tamp={ts}&shareId={shareId}&type=0&offset=1&limit=60
|
||||
// recommend/list?devType=6&devModel=Chrome&uuid={uuid}&extra=2×tamp={ts}&shareId=JoUTkZYj&type=0&offset=1&limit=60
|
||||
|
||||
|
||||
private static final String SECOND_REQUEST_URL = API_URL_PREFIX + "file/redirect?downloadId={fidEncode}&enable=1" +
|
||||
"&devType=6&uuid={uuid}×tamp={ts}&auth={auth}&shareId={dataKey}";
|
||||
// https://api.feijipan.com/ws/file/redirect?downloadId={fidEncode}&enable=1&devType=6&uuid={uuid}×tamp={ts}&auth={auth}&shareId={dataKey}
|
||||
|
||||
|
||||
private static final String VIP_REQUEST_URL = API_URL_PREFIX + "/buy/vip/list?devType=6&devModel=Chrome&uuid" +
|
||||
"={uuid}&extra=2×tamp={ts}";
|
||||
// https://api.feijipan.com/ws/buy/vip/list?devType=6&devModel=Chrome&uuid=WQAl5yBy1naGudJEILBvE&extra=2×tamp=E2C53155F6D09417A27981561134CB73
|
||||
|
||||
// https://api.feijipan.com/ws/share/list?devType=6&devModel=Chrome&uuid=pwRWqwbk1J-KMTlRZowrn&extra=2×tamp=C5F8A68C53121AB21FA35BA3529E8758&shareId=fmAuOh3m&folderId=28986333&offset=1&limit=60
|
||||
|
||||
private static final String FILE_LIST_URL = API_URL_PREFIX + "/share/list?devType=6&devModel=Chrome&uuid" +
|
||||
"={uuid}&extra=2×tamp={ts}&shareId={shareId}&folderId" +
|
||||
"={folderId}&offset=1&limit=60";
|
||||
|
||||
private static final MultiMap header;
|
||||
|
||||
|
||||
long nowTs = System.currentTimeMillis();
|
||||
String tsEncode = AESUtils.encrypt2Hex(Long.toString(nowTs));
|
||||
String uuid = UUIDUtil.fjUuid(); // 也可以使用 UUID.randomUUID().toString()
|
||||
|
||||
static {
|
||||
header = MultiMap.caseInsensitiveMultiMap();
|
||||
header.set("Accept", "application/json, text/plain, */*");
|
||||
header.set("Accept-Encoding", "gzip, deflate, br, zstd");
|
||||
header.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
|
||||
header.set("Cache-Control", "no-cache");
|
||||
header.set("Connection", "keep-alive");
|
||||
header.set("Content-Length", "0");
|
||||
header.set("DNT", "1");
|
||||
header.set("Host", "api.feijipan.com");
|
||||
header.set("Origin", "https://www.feijix.com");
|
||||
header.set("Pragma", "no-cache");
|
||||
header.set("Referer", "https://www.feijix.com/");
|
||||
header.set("Sec-Fetch-Dest", "empty");
|
||||
header.set("Sec-Fetch-Mode", "cors");
|
||||
header.set("Sec-Fetch-Site", "cross-site");
|
||||
header.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
|
||||
header.set("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
|
||||
header.set("sec-ch-ua-mobile", "?0");
|
||||
header.set("sec-ch-ua-platform", "\"Windows\"");
|
||||
}
|
||||
|
||||
public FjTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
|
||||
// 240530 此处shareId又改为了原始的shareId
|
||||
// String.valueOf(AESUtils.idEncrypt(dataKey));
|
||||
final String shareId = shareLinkInfo.getShareKey();
|
||||
|
||||
// 24.5.12 飞机盘 规则修改 需要固定UUID先请求会员接口, 再请求后续接口
|
||||
String url = StringUtils.isBlank(shareLinkInfo.getSharePassword()) ? FIRST_REQUEST_URL
|
||||
: (FIRST_REQUEST_URL + "&code=" + shareLinkInfo.getSharePassword());
|
||||
|
||||
client.postAbs(UriTemplate.of(VIP_REQUEST_URL))
|
||||
.setTemplateParam("uuid", uuid)
|
||||
.setTemplateParam("ts", tsEncode)
|
||||
.send().onSuccess(r0 -> { // 忽略res
|
||||
|
||||
// 第一次请求 获取文件信息
|
||||
// POST https://api.feijipan.com/ws/recommend/list?devType=6&devModel=Chrome&extra=2&shareId=146731&type=0&offset=1&limit=60
|
||||
client.postAbs(UriTemplate.of(url))
|
||||
.putHeaders(header)
|
||||
.setTemplateParam("shareId", shareId)
|
||||
.setTemplateParam("uuid", uuid)
|
||||
.setTemplateParam("ts", tsEncode)
|
||||
.send().onSuccess(res -> {
|
||||
JsonObject resJson = asJson(res);
|
||||
if (resJson.getInteger("code") != 200) {
|
||||
fail(FIRST_REQUEST_URL + " 返回异常: " + resJson);
|
||||
return;
|
||||
}
|
||||
if (resJson.getJsonArray("list").isEmpty()) {
|
||||
fail(FIRST_REQUEST_URL + " 解析文件列表为空: " + resJson);
|
||||
return;
|
||||
}
|
||||
if (!resJson.containsKey("list") || resJson.getJsonArray("list").isEmpty()) {
|
||||
fail(FIRST_REQUEST_URL + " 解析文件列表为空: " + resJson);
|
||||
return;
|
||||
}
|
||||
// 文件Id
|
||||
JsonObject fileInfo = resJson.getJsonArray("list").getJsonObject(0);
|
||||
// 如果是目录返回目录ID
|
||||
if (!fileInfo.containsKey("fileList") || fileInfo.getJsonArray("fileList").isEmpty()) {
|
||||
fail(FIRST_REQUEST_URL + " 文件列表为空: " + fileInfo);
|
||||
return;
|
||||
}
|
||||
JsonObject fileList = fileInfo.getJsonArray("fileList").getJsonObject(0);
|
||||
if (fileList.getInteger("fileType") == 2) {
|
||||
promise.complete(fileList.getInteger("folderId").toString());
|
||||
return;
|
||||
}
|
||||
|
||||
String fileId = fileInfo.getString("fileIds");
|
||||
String userId = fileInfo.getString("userId");
|
||||
// 其他参数
|
||||
long nowTs2 = System.currentTimeMillis();
|
||||
String tsEncode2 = AESUtils.encrypt2Hex(Long.toString(nowTs2));
|
||||
String fidEncode = AESUtils.encrypt2Hex(fileId + "|" + userId);
|
||||
String auth = AESUtils.encrypt2Hex(fileId + "|" + nowTs2);
|
||||
|
||||
// 第二次请求
|
||||
HttpRequest<Buffer> httpRequest =
|
||||
clientNoRedirects.getAbs(UriTemplate.of(SECOND_REQUEST_URL))
|
||||
.putHeaders(header)
|
||||
.setTemplateParam("fidEncode", fidEncode)
|
||||
.setTemplateParam("uuid", uuid)
|
||||
.setTemplateParam("ts", tsEncode2)
|
||||
.setTemplateParam("auth", auth)
|
||||
.setTemplateParam("dataKey", shareId);
|
||||
// System.out.println(httpRequest.toString());
|
||||
httpRequest.send().onSuccess(res2 -> {
|
||||
MultiMap headers = res2.headers();
|
||||
if (!headers.contains("Location")) {
|
||||
fail(SECOND_REQUEST_URL + " 未找到重定向URL: \n" + res.headers());
|
||||
return;
|
||||
}
|
||||
promise.complete(headers.get("Location"));
|
||||
}).onFailure(handleFail(SECOND_REQUEST_URL));
|
||||
}).onFailure(handleFail(FIRST_REQUEST_URL));
|
||||
|
||||
}).onFailure(handleFail(FIRST_REQUEST_URL));
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<List<FileInfo>> parseFileList() {
|
||||
Promise<List<FileInfo>> promise = Promise.promise();
|
||||
|
||||
String shareId = shareLinkInfo.getShareKey(); // String.valueOf(AESUtils.idEncrypt(dataKey));
|
||||
|
||||
// 如果参数里的目录ID不为空,则直接解析目录
|
||||
String dirId = (String) shareLinkInfo.getOtherParam().get("dirId");
|
||||
if (dirId != null && !dirId.isEmpty()) {
|
||||
uuid = shareLinkInfo.getOtherParam().get("uuid").toString();
|
||||
parserDir(dirId, shareId, promise);
|
||||
return promise.future();
|
||||
}
|
||||
parse().onSuccess(id -> {
|
||||
if (id != null && id.matches("^[a-zA-Z0-9]+$")) {
|
||||
parserDir(id, shareId, promise);
|
||||
} else {
|
||||
promise.fail("解析目录ID失败");
|
||||
}
|
||||
}).onFailure(failRes -> {
|
||||
log.error("解析目录失败: {}", failRes.getMessage());
|
||||
promise.fail(failRes);
|
||||
});
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private void parserDir(String id, String shareId, Promise<List<FileInfo>> promise) {
|
||||
log.debug("开始解析目录: {}, shareId: {}, uuid: {}, ts: {}", id, shareId, uuid, tsEncode);
|
||||
// 开始解析目录: 164312216, shareId: bPMsbg5K, uuid: 0fmVWTx2Ea4zFwkpd7KXf, ts: 20865d7b7f00828279f437cd1f097860
|
||||
// 拿到目录ID
|
||||
client.postAbs(UriTemplate.of(FILE_LIST_URL))
|
||||
.putHeaders(header)
|
||||
.setTemplateParam("shareId", shareId)
|
||||
.setTemplateParam("uuid", uuid)
|
||||
.setTemplateParam("ts", tsEncode)
|
||||
.setTemplateParam("folderId", id)
|
||||
.send().onSuccess(res -> {
|
||||
JsonObject jsonObject;
|
||||
try {
|
||||
jsonObject = asJson(res);
|
||||
} catch (Exception e) {
|
||||
promise.fail(FIRST_REQUEST_URL + " 解析JSON失败: " + res.bodyAsString());
|
||||
return;
|
||||
}
|
||||
// System.out.println(jsonObject.encodePrettily());
|
||||
JsonArray list = jsonObject.getJsonArray("list");
|
||||
ArrayList<FileInfo> result = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
JsonObject fileJson = (JsonObject) item;
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
|
||||
// 映射已知字段fileInfo
|
||||
String fileId = fileJson.getString("fileId");
|
||||
String userId = fileJson.getString("userId");
|
||||
|
||||
// 其他参数
|
||||
long nowTs2 = System.currentTimeMillis();
|
||||
String tsEncode2 = AESUtils.encrypt2Hex(Long.toString(nowTs2));
|
||||
String fidEncode = AESUtils.encrypt2Hex(fileId + "|" + userId);
|
||||
String auth = AESUtils.encrypt2Hex(fileId + "|" + nowTs2);
|
||||
|
||||
// 回传用到的参数
|
||||
//"fidEncode", paramJson.getString("fidEncode"))
|
||||
//"uuid", paramJson.getString("uuid"))
|
||||
//"ts", paramJson.getString("ts"))
|
||||
//"auth", paramJson.getString("auth"))
|
||||
//"shareId", paramJson.getString("shareId"))
|
||||
JsonObject entries = JsonObject.of(
|
||||
"fidEncode", fidEncode,
|
||||
"uuid", uuid,
|
||||
"ts", tsEncode2,
|
||||
"auth", auth,
|
||||
"shareId", shareId);
|
||||
byte[] encode = Base64.getEncoder().encode(entries.encode().getBytes());
|
||||
String param = new String(encode);
|
||||
|
||||
if (fileJson.getInteger("fileType") == 2) {
|
||||
// 如果是目录
|
||||
fileInfo.setFileName(fileJson.getString("name"))
|
||||
.setFileId(fileJson.getString("folderId"))
|
||||
.setCreateTime(fileJson.getString("updTime"))
|
||||
.setFileType("folder")
|
||||
.setSize(0L)
|
||||
.setSizeStr("0B")
|
||||
.setCreateBy(fileJson.getLong("userId").toString())
|
||||
.setDownloadCount(fileJson.getInteger("fileDownloads"))
|
||||
.setCreateTime(fileJson.getString("updTime"))
|
||||
.setFileIcon(fileJson.getString("fileIcon"))
|
||||
.setPanType(shareLinkInfo.getType())
|
||||
// 设置目录解析的URL
|
||||
.setParserUrl(String.format("%s/v2/getFileList?url=%s&dirId=%s&uuid=%s", getDomainName(),
|
||||
shareLinkInfo.getShareUrl(), fileJson.getString("folderId"), uuid));
|
||||
result.add(fileInfo);
|
||||
return;
|
||||
}
|
||||
long fileSize = fileJson.getLong("fileSize") * 1024;
|
||||
fileInfo.setFileName(fileJson.getString("fileName"))
|
||||
.setFileId(fileJson.getString("fileId"))
|
||||
.setCreateTime(fileJson.getString("createTime"))
|
||||
.setFileType("file")
|
||||
.setSize(fileSize)
|
||||
.setSizeStr(FileSizeConverter.convertToReadableSize(fileSize))
|
||||
.setCreateBy(fileJson.getLong("userId").toString())
|
||||
.setDownloadCount(fileJson.getInteger("fileDownloads"))
|
||||
.setCreateTime(fileJson.getString("updTime"))
|
||||
.setFileIcon(fileJson.getString("fileIcon"))
|
||||
.setPanType(shareLinkInfo.getType())
|
||||
.setParserUrl(String.format("%s/v2/redirectUrl/%s/%s", getDomainName(),
|
||||
shareLinkInfo.getType(), param))
|
||||
.setPreviewUrl(String.format("%s/v2/viewUrl/%s/%s", getDomainName(),
|
||||
shareLinkInfo.getType(), param));
|
||||
result.add(fileInfo);
|
||||
});
|
||||
promise.complete(result);
|
||||
}).onFailure(failRes -> {
|
||||
log.error("解析目录请求失败: {}", failRes.getMessage());
|
||||
promise.fail(failRes);
|
||||
});;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parseById() {
|
||||
// 第二次请求
|
||||
JsonObject paramJson = (JsonObject)shareLinkInfo.getOtherParam().get("paramJson");
|
||||
clientNoRedirects.getAbs(UriTemplate.of(SECOND_REQUEST_URL))
|
||||
.setTemplateParam("fidEncode", paramJson.getString("fidEncode"))
|
||||
.setTemplateParam("uuid", paramJson.getString("uuid"))
|
||||
.setTemplateParam("ts", paramJson.getString("ts"))
|
||||
.setTemplateParam("auth", paramJson.getString("auth"))
|
||||
.setTemplateParam("dataKey", paramJson.getString("shareId"))
|
||||
.putHeaders(header).send().onSuccess(res2 -> {
|
||||
MultiMap headers = res2.headers();
|
||||
if (!headers.contains("Location")) {
|
||||
fail(SECOND_REQUEST_URL + " 未找到重定向URL: \n" + res2.headers());
|
||||
return;
|
||||
}
|
||||
promise.complete(headers.get("Location"));
|
||||
}).onFailure(handleFail(SECOND_REQUEST_URL));
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
132
parser/src/main/java/cn/qaiu/parser/impl/GenShortUrl.java
Normal file
132
parser/src/main/java/cn/qaiu/parser/impl/GenShortUrl.java
Normal file
@@ -0,0 +1,132 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.netty.handler.codec.http.cookie.Cookie;
|
||||
import io.netty.handler.codec.http.cookie.DefaultCookie;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.http.impl.headers.HeadersMultiMap;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* t.cn 短链生成 //
|
||||
*/
|
||||
public class GenShortUrl extends PanBase {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GenShortUrl.class);
|
||||
|
||||
private static final String COMMENT_URL = "https://www.weibo.com/aj/v6/comment/add";
|
||||
private static final String DELETE_COMMENT_URL = "https://www.weibo.com/aj/comment/del";
|
||||
|
||||
private static final String WRAPPER_URL = "https://www.so.com/link?m=ewgUSYiFWXIoTybC3fJH8YoJy8y10iRquo6cazgINwWjTn3HvVJ92TrCJu0PmMUR0RMDfOAucP3wa4G8j64SrhNH9Z0Cr0PEyn9ASuvpkUGmAjjUEGJkO5%2BIDGWVrEkPHsL7UsoKO6%2BlT%2BD6r&ccc=";
|
||||
private static final String MID = "5095144728824883"; // 微博的mid
|
||||
|
||||
private static final MultiMap HEADER = HeadersMultiMap.headers()
|
||||
.add("Content-Type", "application/x-www-form-urlencoded")
|
||||
.add("Referer", "https://www.weibo.com")
|
||||
.add("Content-Type", "application/x-www-form-urlencoded")
|
||||
.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36");
|
||||
|
||||
Cookie cookie = new DefaultCookie("SUB", "_2A25KJE5vDeRhGeRJ6lsR9SjJzDuIHXVpWM-nrDV8PUJbkNAbLVPlkW1NUmJm3GjYtRHBsHdMUKafkdTL_YheMEmu");
|
||||
public GenShortUrl(ShareLinkInfo build) {
|
||||
super(build);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
String longUrl = shareLinkInfo.getShareUrl();
|
||||
|
||||
String url = WRAPPER_URL + Base64.getEncoder().encodeToString(longUrl.getBytes());
|
||||
|
||||
String payload = "mid=" + MID + "&content=" + URLEncoder.encode(url, StandardCharsets.UTF_8);
|
||||
clientSession.cookieStore().put(cookie);
|
||||
|
||||
clientSession.postAbs(COMMENT_URL)
|
||||
.putHeaders(HEADER)
|
||||
.sendBuffer(Buffer.buffer(payload))
|
||||
.onSuccess(res -> {
|
||||
JsonObject data = asJson(res).getJsonObject("data");
|
||||
if (data.isEmpty()) {
|
||||
fail(asJson(res).getString("msg"));
|
||||
return;
|
||||
}
|
||||
String comment = data.getString("comment");
|
||||
String shortUrl = extractShortUrl(comment);
|
||||
if (shortUrl != null) {
|
||||
log.info("生成的短链:{}", shortUrl);
|
||||
String commentId = extractCommentId(comment);
|
||||
if (commentId != null) {
|
||||
deleteComment(commentId);
|
||||
} else {
|
||||
promise.fail("未能提取评论ID");
|
||||
}
|
||||
} else {
|
||||
promise.fail("未能生成短链");
|
||||
}
|
||||
})
|
||||
.onFailure(err -> {
|
||||
log.error("添加评论失败", err);
|
||||
promise.fail(err);
|
||||
});
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
|
||||
private void deleteComment(String commentId) {
|
||||
String payload = "mid=" + MID + "&cid=" + commentId;
|
||||
|
||||
clientSession.postAbs(DELETE_COMMENT_URL)
|
||||
.putHeaders(HEADER)
|
||||
.sendBuffer(Buffer.buffer(payload))
|
||||
.onSuccess(res -> {
|
||||
JsonObject responseJson = res.bodyAsJsonObject();
|
||||
if (responseJson.getString("code").equals("100000")) {
|
||||
log.info("评论已删除: {}", commentId);
|
||||
} else {
|
||||
log.error("删除评论失败: {}", responseJson.encode());
|
||||
}
|
||||
})
|
||||
.onFailure(err -> {
|
||||
log.error("删除评论失败", err);
|
||||
});
|
||||
}
|
||||
|
||||
private String extractShortUrl(String comment) {
|
||||
Pattern pattern = Pattern.compile("(https?)://t.cn/\\w+");
|
||||
Matcher matcher = pattern.matcher(comment);
|
||||
if (matcher.find()) {
|
||||
return matcher.group(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String extractCommentId(String comment) {
|
||||
Pattern pattern = Pattern.compile("comment_id=\"(\\d+)\"");
|
||||
Matcher matcher = pattern.matcher(comment);
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// http://t.cn/A6nfZn86
|
||||
// http://t.cn/A6nfZn86
|
||||
|
||||
new GenShortUrl(ShareLinkInfo.newBuilder().shareUrl("https://qaiu.top/sdfsdf").build()).parse().onSuccess(
|
||||
System.out::println
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
283
parser/src/main/java/cn/qaiu/parser/impl/IzTool.java
Normal file
283
parser/src/main/java/cn/qaiu/parser/impl/IzTool.java
Normal file
@@ -0,0 +1,283 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.FileInfo;
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.AESUtils;
|
||||
import cn.qaiu.util.FileSizeConverter;
|
||||
import cn.qaiu.util.UUIDUtil;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 蓝奏云优享
|
||||
*
|
||||
*/
|
||||
public class IzTool extends PanBase {
|
||||
|
||||
private static final String API_URL_PREFIX = "https://api.ilanzou.com/unproved/";
|
||||
|
||||
private static final String FIRST_REQUEST_URL = API_URL_PREFIX + "recommend/list?devType=6&devModel=Chrome" +
|
||||
"&uuid={uuid}&extra=2×tamp={ts}&shareId={shareId}&type=0&offset=1&limit=60";
|
||||
|
||||
private static final String SECOND_REQUEST_URL = API_URL_PREFIX + "file/redirect?downloadId={fidEncode}&enable=1" +
|
||||
"&devType=6&uuid={uuid}×tamp={ts}&auth={auth}&shareId={dataKey}";
|
||||
// downloadId=x&enable=1&devType=6&uuid=x×tamp=x&auth=x&shareId=lGFndCM
|
||||
|
||||
private static final String VIP_REQUEST_URL = API_URL_PREFIX + "/buy/vip/list?devType=6&devModel=Chrome&uuid" +
|
||||
"={uuid}&extra=2×tamp={ts}";
|
||||
|
||||
private static final String FILE_LIST_URL = API_URL_PREFIX + "/share/list?devType=6&devModel=Chrome&uuid" +
|
||||
"={uuid}&extra=2×tamp={ts}&shareId={shareId}&folderId" +
|
||||
"={folderId}&offset=1&limit=60";
|
||||
|
||||
long nowTs = System.currentTimeMillis();
|
||||
String tsEncode = AESUtils.encrypt2HexIz(Long.toString(nowTs));
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
||||
private static final MultiMap header;
|
||||
|
||||
static {
|
||||
header = MultiMap.caseInsensitiveMultiMap();
|
||||
header.set("Accept", "application/json, text/plain, */*");
|
||||
header.set("Accept-Encoding", "gzip, deflate, br, zstd");
|
||||
header.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
|
||||
header.set("Cache-Control", "no-cache");
|
||||
header.set("Connection", "keep-alive");
|
||||
header.set("Content-Length", "0");
|
||||
header.set("DNT", "1");
|
||||
header.set("Host", "api.ilanzou.com");
|
||||
header.set("Origin", "https://www.ilanzou.com/");
|
||||
header.set("Pragma", "no-cache");
|
||||
header.set("Referer", "https://www.ilanzou.com/");
|
||||
header.set("Sec-Fetch-Dest", "empty");
|
||||
header.set("Sec-Fetch-Mode", "cors");
|
||||
header.set("Sec-Fetch-Site", "cross-site");
|
||||
header.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
|
||||
header.set("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
|
||||
header.set("sec-ch-ua-mobile", "?0");
|
||||
header.set("sec-ch-ua-platform", "\"Windows\"");
|
||||
}
|
||||
|
||||
public IzTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
String shareId = shareLinkInfo.getShareKey();
|
||||
|
||||
// 24.5.12 ilanzou改规则无需计算shareId
|
||||
// String shareId = String.valueOf(AESUtils.idEncryptIz(dataKey));
|
||||
|
||||
// 第一次请求 获取文件信息
|
||||
// POST https://api.ilanzou.com/ws/recommend/list?devType=6&devModel=Chrome&extra=2&shareId=146731&type=0&offset=1&limit=60
|
||||
String url = StringUtils.isBlank(shareLinkInfo.getSharePassword()) ? FIRST_REQUEST_URL
|
||||
: (FIRST_REQUEST_URL + "&code=" + shareLinkInfo.getSharePassword());
|
||||
client.postAbs(UriTemplate.of(VIP_REQUEST_URL))
|
||||
.setTemplateParam("uuid", uuid)
|
||||
.setTemplateParam("ts", tsEncode)
|
||||
.send().onSuccess(r0 -> { // 忽略res
|
||||
// 第一次请求 获取文件信息
|
||||
// POST https://api.feijipan.com/ws/recommend/list?devType=6&devModel=Chrome&extra=2&shareId=146731&type=0&offset=1&limit=60
|
||||
client.postAbs(UriTemplate.of(url))
|
||||
.putHeaders(header)
|
||||
.setTemplateParam("shareId", shareId)
|
||||
.setTemplateParam("uuid", uuid)
|
||||
.setTemplateParam("ts", tsEncode)
|
||||
.send().onSuccess(res -> {
|
||||
JsonObject resJson = asJson(res);
|
||||
if (resJson.getInteger("code") != 200) {
|
||||
fail(FIRST_REQUEST_URL + " 返回异常: " + resJson);
|
||||
return;
|
||||
}
|
||||
if (resJson.getJsonArray("list").isEmpty()) {
|
||||
fail(FIRST_REQUEST_URL + " 解析文件列表为空: " + resJson);
|
||||
return;
|
||||
}
|
||||
if (!resJson.containsKey("list") || resJson.getJsonArray("list").isEmpty()) {
|
||||
fail(FIRST_REQUEST_URL + " 解析文件列表为空: " + resJson);
|
||||
return;
|
||||
}
|
||||
// 文件Id
|
||||
JsonObject fileInfo = resJson.getJsonArray("list").getJsonObject(0);
|
||||
// 如果是目录返回目录ID
|
||||
if (!fileInfo.containsKey("fileList") || fileInfo.getJsonArray("fileList").isEmpty()) {
|
||||
fail(FIRST_REQUEST_URL + " 文件列表为空: " + fileInfo);
|
||||
return;
|
||||
}
|
||||
JsonObject fileList = fileInfo.getJsonArray("fileList").getJsonObject(0);
|
||||
if (fileList.getInteger("fileType") == 2) {
|
||||
promise.complete(fileList.getInteger("folderId").toString());
|
||||
return;
|
||||
}
|
||||
|
||||
String fileId = fileInfo.getString("fileIds");
|
||||
String userId = fileInfo.getString("userId");
|
||||
// 其他参数
|
||||
// String fidEncode = AESUtils.encrypt2HexIz(fileId + "|");
|
||||
String fidEncode = AESUtils.encrypt2HexIz(fileId + "|" + userId);
|
||||
String auth = AESUtils.encrypt2HexIz(fileId + "|" + nowTs);
|
||||
// 第二次请求
|
||||
clientNoRedirects.getAbs(UriTemplate.of(SECOND_REQUEST_URL))
|
||||
.setTemplateParam("fidEncode", fidEncode)
|
||||
.setTemplateParam("uuid", uuid)
|
||||
.setTemplateParam("ts", tsEncode)
|
||||
.setTemplateParam("auth", auth)
|
||||
.setTemplateParam("shareId", shareId)
|
||||
.putHeaders(header).send().onSuccess(res2 -> {
|
||||
MultiMap headers = res2.headers();
|
||||
if (!headers.contains("Location")) {
|
||||
fail(SECOND_REQUEST_URL + " 未找到重定向URL: \n" + headers);
|
||||
return;
|
||||
}
|
||||
promise.complete(headers.get("Location"));
|
||||
}).onFailure(handleFail(SECOND_REQUEST_URL));
|
||||
}).onFailure(handleFail(FIRST_REQUEST_URL));
|
||||
});
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<List<FileInfo>> parseFileList() {
|
||||
Promise<List<FileInfo>> promise = Promise.promise();
|
||||
|
||||
String shareId = shareLinkInfo.getShareKey(); // String.valueOf(AESUtils.idEncrypt(dataKey));
|
||||
|
||||
// 如果参数里的目录ID不为空,则直接解析目录
|
||||
String dirId = (String) shareLinkInfo.getOtherParam().get("dirId");
|
||||
if (dirId != null && !dirId.isEmpty()) {
|
||||
uuid = shareLinkInfo.getOtherParam().get("uuid").toString();
|
||||
parserDir(dirId, shareId, promise);
|
||||
return promise.future();
|
||||
}
|
||||
parse().onSuccess(id -> {
|
||||
if (id != null && id.matches("^[a-zA-Z0-9]+$")) {
|
||||
parserDir(id, shareId, promise);
|
||||
} else {
|
||||
promise.fail("解析目录ID失败");
|
||||
}
|
||||
}).onFailure(failRes -> {
|
||||
log.error("解析目录失败: {}", failRes.getMessage());
|
||||
promise.fail(failRes);
|
||||
});
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private void parserDir(String id, String shareId, Promise<List<FileInfo>> promise) {
|
||||
log.debug("开始解析目录: {}, shareId: {}, uuid: {}, ts: {}", id, shareId, uuid, tsEncode);
|
||||
// 开始解析目录: 164312216, shareId: bPMsbg5K, uuid: 0fmVWTx2Ea4zFwkpd7KXf, ts: 20865d7b7f00828279f437cd1f097860
|
||||
// 拿到目录ID
|
||||
client.postAbs(UriTemplate.of(FILE_LIST_URL))
|
||||
.putHeaders(header)
|
||||
.setTemplateParam("shareId", shareId)
|
||||
.setTemplateParam("uuid", uuid)
|
||||
.setTemplateParam("ts", tsEncode)
|
||||
.setTemplateParam("folderId", id)
|
||||
.send().onSuccess(res -> {
|
||||
JsonObject jsonObject;
|
||||
try {
|
||||
jsonObject = asJson(res);
|
||||
} catch (Exception e) {
|
||||
promise.fail(FIRST_REQUEST_URL + " 解析JSON失败: " + res.bodyAsString());
|
||||
return;
|
||||
}
|
||||
// System.out.println(jsonObject.encodePrettily());
|
||||
JsonArray list = jsonObject.getJsonArray("list");
|
||||
ArrayList<FileInfo> result = new ArrayList<>();
|
||||
list.forEach(item->{
|
||||
JsonObject fileJson = (JsonObject) item;
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
|
||||
// 映射已知字段
|
||||
String fileId = fileJson.getString("fileId");
|
||||
String userId = fileJson.getString("userId");
|
||||
|
||||
// 回传用到的参数
|
||||
//"fidEncode", paramJson.getString("fidEncode"))
|
||||
//"uuid", paramJson.getString("uuid"))
|
||||
//"ts", paramJson.getString("ts"))
|
||||
//"auth", paramJson.getString("auth"))
|
||||
//"shareId", paramJson.getString("shareId"))
|
||||
String fidEncode = AESUtils.encrypt2HexIz(fileId + "|" + userId);
|
||||
String auth = AESUtils.encrypt2HexIz(fileId + "|" + nowTs);
|
||||
JsonObject entries = JsonObject.of(
|
||||
"fidEncode", fidEncode,
|
||||
"uuid", uuid,
|
||||
"ts", tsEncode,
|
||||
"auth", auth,
|
||||
"shareId", shareId);
|
||||
byte[] encode = Base64.getEncoder().encode(entries.encode().getBytes());
|
||||
String param = new String(encode);
|
||||
|
||||
if (fileJson.getInteger("fileType") == 2) {
|
||||
// 如果是目录
|
||||
fileInfo.setFileName(fileJson.getString("name"))
|
||||
.setFileId(fileJson.getString("folderId"))
|
||||
.setCreateTime(fileJson.getString("updTime"))
|
||||
.setFileType("folder")
|
||||
.setSize(0L)
|
||||
.setSizeStr("0B")
|
||||
.setCreateBy(fileJson.getLong("userId").toString())
|
||||
.setDownloadCount(fileJson.getInteger("fileDownloads"))
|
||||
.setCreateTime(fileJson.getString("updTime"))
|
||||
.setFileIcon(fileJson.getString("fileIcon"))
|
||||
.setPanType(shareLinkInfo.getType())
|
||||
// 设置目录解析的URL
|
||||
.setParserUrl(String.format("%s/v2/getFileList?url=%s&dirId=%s&uuid=%s", getDomainName(),
|
||||
shareLinkInfo.getShareUrl(), fileJson.getString("folderId"), uuid));
|
||||
result.add(fileInfo);
|
||||
return;
|
||||
}
|
||||
long fileSize = fileJson.getLong("fileSize") * 1024;
|
||||
fileInfo.setFileName(fileJson.getString("fileName"))
|
||||
.setFileId(fileId)
|
||||
.setCreateTime(fileJson.getString("createTime"))
|
||||
.setFileType("file")
|
||||
.setSize(fileSize)
|
||||
.setSizeStr(FileSizeConverter.convertToReadableSize(fileSize))
|
||||
.setCreateBy(fileJson.getLong("userId").toString())
|
||||
.setDownloadCount(fileJson.getInteger("fileDownloads"))
|
||||
.setCreateTime(fileJson.getString("updTime"))
|
||||
.setFileIcon(fileJson.getString("fileIcon"))
|
||||
.setPanType(shareLinkInfo.getType())
|
||||
.setParserUrl(String.format("%s/v2/redirectUrl/%s/%s", getDomainName(),
|
||||
shareLinkInfo.getType(), param))
|
||||
.setPreviewUrl(String.format("%s/v2/viewUrl/%s/%s", getDomainName(),
|
||||
shareLinkInfo.getType(), param));
|
||||
result.add(fileInfo);
|
||||
});
|
||||
promise.complete(result);
|
||||
}).onFailure(failRes -> {
|
||||
log.error("解析目录请求失败: {}", failRes.getMessage());
|
||||
promise.fail(failRes);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parseById() {
|
||||
// 第二次请求
|
||||
JsonObject paramJson = (JsonObject)shareLinkInfo.getOtherParam().get("paramJson");
|
||||
clientNoRedirects.getAbs(UriTemplate.of(SECOND_REQUEST_URL))
|
||||
.setTemplateParam("fidEncode", paramJson.getString("fidEncode"))
|
||||
.setTemplateParam("uuid", paramJson.getString("uuid"))
|
||||
.setTemplateParam("ts", paramJson.getString("ts"))
|
||||
.setTemplateParam("auth", paramJson.getString("auth"))
|
||||
.setTemplateParam("shareId", paramJson.getString("shareId"))
|
||||
.putHeaders(header).send().onSuccess(res2 -> {
|
||||
MultiMap headers = res2.headers();
|
||||
if (!headers.contains("Location")) {
|
||||
fail(SECOND_REQUEST_URL + " 未找到重定向URL: \n" + res2.headers());
|
||||
return;
|
||||
}
|
||||
promise.complete(headers.get("Location"));
|
||||
}).onFailure(handleFail(SECOND_REQUEST_URL));
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
26
parser/src/main/java/cn/qaiu/parser/impl/KdTool.java
Normal file
26
parser/src/main/java/cn/qaiu/parser/impl/KdTool.java
Normal file
@@ -0,0 +1,26 @@
|
||||
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.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* <a href="https://kodcloud.com/">可道云</a>
|
||||
*/
|
||||
public class KdTool extends PanBase {
|
||||
private static final String API_URL_PREFIX = "";
|
||||
|
||||
public KdTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
nextParser();
|
||||
// TODO
|
||||
return future();
|
||||
}
|
||||
}
|
||||
92
parser/src/main/java/cn/qaiu/parser/impl/LeTool.java
Normal file
92
parser/src/main/java/cn/qaiu/parser/impl/LeTool.java
Normal file
@@ -0,0 +1,92 @@
|
||||
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.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* <a href="https://lecloud.lenovo.com/">联想乐云</a>
|
||||
*/
|
||||
public class LeTool extends PanBase {
|
||||
private static final String API_URL_PREFIX = "https://lecloud.lenovo.com/share/api/clouddiskapi/share/public/v1/";
|
||||
|
||||
public LeTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
final String dataKey = shareLinkInfo.getShareKey();
|
||||
final String pwd = shareLinkInfo.getSharePassword();
|
||||
// {"shareId":"xxx","password":"xxx","directoryId":"-1"}
|
||||
String apiUrl1 = API_URL_PREFIX + "shareInfo";
|
||||
client.postAbs(apiUrl1)
|
||||
.sendJsonObject(JsonObject.of("shareId", dataKey, "password", pwd, "directoryId", -1))
|
||||
.onSuccess(res -> {
|
||||
JsonObject resJson = asJson(res);
|
||||
if (resJson.containsKey("result")) {
|
||||
if (resJson.getBoolean("result")) {
|
||||
JsonObject dataJson = resJson.getJsonObject("data");
|
||||
// 密码验证失败
|
||||
if (!dataJson.getBoolean("passwordVerified")) {
|
||||
fail("密码验证失败, 分享key: {}, 密码: {}", dataKey, pwd);
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取文件信息
|
||||
JsonArray files = dataJson.getJsonArray("files");
|
||||
if (files == null || files.size() == 0) {
|
||||
fail("Result JSON数据异常: files字段不存在或jsonArray长度为空");
|
||||
return;
|
||||
}
|
||||
JsonObject fileInfoJson = files.getJsonObject(0);
|
||||
if (fileInfoJson != null) {
|
||||
// TODO 文件大小fileSize和文件名fileName
|
||||
String fileId = fileInfoJson.getString("fileId");
|
||||
// 根据文件ID获取跳转链接
|
||||
getDownURL(dataKey, fileId);
|
||||
}
|
||||
} else {
|
||||
fail("{}: {}", resJson.getString("errcode"), resJson.getString("errmsg"));
|
||||
}
|
||||
} else {
|
||||
fail("Result JSON数据异常: result字段不存在");
|
||||
}
|
||||
}).onFailure(handleFail(apiUrl1));
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private void getDownURL(String key, String fileId) {
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
JsonArray fileIds = JsonArray.of(fileId);
|
||||
String apiUrl2 = API_URL_PREFIX + "packageDownloadWithFileIds";
|
||||
// {"fileIds":[123],"shareId":"xxx","browserId":"uuid"}
|
||||
client.postAbs(apiUrl2)
|
||||
.sendJsonObject(JsonObject.of("fileIds", fileIds, "shareId", key, "browserId", uuid))
|
||||
.onSuccess(res -> {
|
||||
JsonObject resJson = asJson(res);
|
||||
if (resJson.containsKey("result")) {
|
||||
if (resJson.getBoolean("result")) {
|
||||
JsonObject dataJson = resJson.getJsonObject("data");
|
||||
// 获取重定向链接跳转链接
|
||||
String downloadUrl = dataJson.getString("downloadUrl");
|
||||
if (downloadUrl == null) {
|
||||
fail("Result JSON数据异常: downloadUrl不存在");
|
||||
return;
|
||||
}
|
||||
// 获取重定向链接跳转链接
|
||||
clientNoRedirects.getAbs(downloadUrl).send()
|
||||
.onSuccess(res2 -> promise.complete(res2.headers().get("Location")))
|
||||
.onFailure(handleFail(downloadUrl));
|
||||
} else {
|
||||
fail("{}: {}", resJson.getString("errcode"), resJson.getString("errmsg"));
|
||||
}
|
||||
} else {
|
||||
fail("Result JSON数据异常: result字段不存在");
|
||||
}
|
||||
}).onFailure(handleFail(apiUrl2));
|
||||
}
|
||||
}
|
||||
239
parser/src/main/java/cn/qaiu/parser/impl/LzTool.java
Normal file
239
parser/src/main/java/cn/qaiu/parser/impl/LzTool.java
Normal file
@@ -0,0 +1,239 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.FileInfo;
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.CastUtil;
|
||||
import cn.qaiu.util.FileSizeConverter;
|
||||
import cn.qaiu.util.HeaderUtils;
|
||||
import cn.qaiu.util.JsExecUtils;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.client.WebClient;
|
||||
import org.openjdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 蓝奏云解析工具
|
||||
*
|
||||
* @author QAIU
|
||||
*/
|
||||
public class LzTool extends PanBase {
|
||||
|
||||
public static final String SHARE_URL_PREFIX = "https://wwww.lanzoup.com";
|
||||
|
||||
|
||||
public LzTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
String sUrl = shareLinkInfo.getStandardUrl();
|
||||
String pwd = shareLinkInfo.getSharePassword();
|
||||
|
||||
WebClient client = clientNoRedirects;
|
||||
client.getAbs(sUrl).send().onSuccess(res -> {
|
||||
String html = res.bodyAsString();
|
||||
// 匹配iframe
|
||||
Pattern compile = Pattern.compile("src=\"(/fn\\?[a-zA-Z\\d_+/=]{16,})\"");
|
||||
Matcher matcher = compile.matcher(html);
|
||||
// 没有Iframe说明是加密分享, 匹配sign通过密码请求下载页面
|
||||
if (!matcher.find()) {
|
||||
try {
|
||||
String jsText = getJsByPwd(pwd, html, "document.getElementById('rpt')");
|
||||
ScriptObjectMirror scriptObjectMirror = JsExecUtils.executeDynamicJs(jsText, "down_p");
|
||||
getDownURL(sUrl, client, scriptObjectMirror);
|
||||
} catch (Exception e) {
|
||||
fail(e, "js引擎执行失败");
|
||||
}
|
||||
} else {
|
||||
// 没有密码
|
||||
String iframePath = matcher.group(1);
|
||||
client.getAbs(SHARE_URL_PREFIX + iframePath).send().onSuccess(res2 -> {
|
||||
String html2 = res2.bodyAsString();
|
||||
|
||||
// 去TMD正则
|
||||
// Matcher matcher2 = Pattern.compile("'sign'\s*:\s*'(\\w+)'").matcher(html2);
|
||||
String jsText = getJsText(html2);
|
||||
if (jsText == null) {
|
||||
fail(SHARE_URL_PREFIX + iframePath + " -> " + sUrl + ": js脚本匹配失败, 可能分享已失效");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ScriptObjectMirror scriptObjectMirror = JsExecUtils.executeDynamicJs(jsText, null);
|
||||
getDownURL(sUrl, client, scriptObjectMirror);
|
||||
} catch (ScriptException | NoSuchMethodException e) {
|
||||
fail(e, "js引擎执行失败");
|
||||
}
|
||||
}).onFailure(handleFail(SHARE_URL_PREFIX));
|
||||
}
|
||||
}).onFailure(handleFail(sUrl));
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private String getJsByPwd(String pwd, String html, String subText) {
|
||||
String jsText = getJsText(html);
|
||||
|
||||
if (jsText == null) {
|
||||
throw new RuntimeException("js脚本匹配失败, 可能分享已失效");
|
||||
}
|
||||
jsText = jsText.replace("document.getElementById('pwd').value", "\"" + pwd + "\"");
|
||||
int i = jsText.indexOf(subText);
|
||||
if (i > 0) {
|
||||
jsText = jsText.substring(0, i);
|
||||
}
|
||||
return jsText;
|
||||
}
|
||||
|
||||
private String getJsText(String html) {
|
||||
String jsTagStart = "<script type=\"text/javascript\">";
|
||||
String jsTagEnd = "</script>";
|
||||
int index = html.lastIndexOf(jsTagStart);
|
||||
if (index == -1) {
|
||||
return null;
|
||||
}
|
||||
int startPos = index + jsTagStart.length();
|
||||
int endPos = html.indexOf(jsTagEnd, startPos);
|
||||
return html.substring(startPos, endPos).replaceAll("<!--.*-->", "");
|
||||
}
|
||||
|
||||
private void getDownURL(String key, WebClient client, Map<String, ?> obj) {
|
||||
if (obj == null) {
|
||||
fail("需要访问密码");
|
||||
return;
|
||||
}
|
||||
Map<?, ?> signMap = (Map<?, ?>)obj.get("data");
|
||||
String url0 = obj.get("url").toString();
|
||||
MultiMap map = MultiMap.caseInsensitiveMultiMap();
|
||||
signMap.forEach((k, v) -> {
|
||||
map.add((String) k, v.toString());
|
||||
});
|
||||
MultiMap headers = HeaderUtils.parseHeaders("""
|
||||
Accept: application/json, text/javascript, */*
|
||||
Accept-Encoding: gzip, deflate, br, zstd
|
||||
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6
|
||||
Cache-Control: no-cache
|
||||
Connection: keep-alive
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Pragma: no-cache
|
||||
Sec-Fetch-Dest: empty
|
||||
Sec-Fetch-Mode: cors
|
||||
Sec-Fetch-Site: same-origin
|
||||
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0
|
||||
X-Requested-With: XMLHttpRequest
|
||||
sec-ch-ua: "Chromium";v="134", "Not:A-Brand";v="24", "Microsoft Edge";v="134"
|
||||
sec-ch-ua-mobile: ?0
|
||||
sec-ch-ua-platform: "Windows"
|
||||
""");
|
||||
|
||||
headers.set("referer", key);
|
||||
// action=downprocess&signs=%3Fctdf&websignkey=I5gl&sign=BWMGOF1sBTRWXwI9BjZdYVA7BDhfNAIyUG9UawJtUGMIPlAhACkCa1UyUTAAYFxvUj5XY1E7UGFXaFVq&websign=&kd=1&ves=1
|
||||
String url = SHARE_URL_PREFIX + url0;
|
||||
client.postAbs(url).putHeaders(headers).sendForm(map).onSuccess(res2 -> {
|
||||
try {
|
||||
JsonObject urlJson = asJson(res2);
|
||||
if (urlJson.getInteger("zt") != 1) {
|
||||
fail(urlJson.getString("inf"));
|
||||
return;
|
||||
}
|
||||
String downUrl = urlJson.getString("dom") + "/file/" + urlJson.getString("url");
|
||||
headers.remove("Referer");
|
||||
client.getAbs(downUrl).putHeaders(headers).send()
|
||||
.onSuccess(res3 -> promise.complete(res3.headers().get("Location")))
|
||||
.onFailure(handleFail(downUrl));
|
||||
} catch (Exception e) {
|
||||
fail("解析异常");
|
||||
}
|
||||
}).onFailure(handleFail(url));
|
||||
}
|
||||
|
||||
private static MultiMap getHeaders(String key) {
|
||||
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
|
||||
var userAgent2 = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, " +
|
||||
"like " +
|
||||
"Gecko) Chrome/111.0.0.0 Mobile Safari/537.36";
|
||||
headers.set("User-Agent", userAgent2);
|
||||
headers.set("referer", key);
|
||||
headers.set("sec-ch-ua-platform", "Android");
|
||||
headers.set("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
|
||||
headers.set("sec-ch-ua-mobile", "sec-ch-ua-mobile");
|
||||
return headers;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Future<List<FileInfo>> parseFileList() {
|
||||
Promise<List<FileInfo>> promise = Promise.promise();
|
||||
|
||||
String sUrl = shareLinkInfo.getShareUrl();
|
||||
String pwd = shareLinkInfo.getSharePassword();
|
||||
|
||||
WebClient client = clientNoRedirects;
|
||||
client.getAbs(sUrl).send().onSuccess(res -> {
|
||||
String html = res.bodyAsString();
|
||||
try {
|
||||
String jsText = getJsByPwd(pwd, html, "var urls =window.location.href");
|
||||
ScriptObjectMirror scriptObjectMirror = JsExecUtils.executeDynamicJs(jsText, "file");
|
||||
Map<String, Object> data = CastUtil.cast(scriptObjectMirror.get("data"));
|
||||
MultiMap map = MultiMap.caseInsensitiveMultiMap();
|
||||
data.forEach((k, v) -> map.set(k, v.toString()));
|
||||
log.debug("解析参数: {}", map);
|
||||
MultiMap headers = getHeaders(sUrl);
|
||||
|
||||
String url = SHARE_URL_PREFIX + "/filemoreajax.php?file=" + data.get("fid");
|
||||
client.postAbs(url).putHeaders(headers).sendForm(map).onSuccess(res2 -> {
|
||||
JsonObject fileListJson = asJson(res2);
|
||||
if (fileListJson.getInteger("zt") != 1) {
|
||||
promise.fail(baseMsg() + fileListJson.getString("info"));
|
||||
return;
|
||||
}
|
||||
List<FileInfo> list = new ArrayList<>();
|
||||
fileListJson.getJsonArray("text").forEach(item -> {
|
||||
/*
|
||||
{
|
||||
"icon": "apk",
|
||||
"t": 0,
|
||||
"id": "iULV2n4361c",
|
||||
"name_all": "xx.apk",
|
||||
"size": "49.8 M",
|
||||
"time": "2021-03-19",
|
||||
"duan": "in4361",
|
||||
"p_ico": 0
|
||||
}
|
||||
*/
|
||||
JsonObject fileJson = (JsonObject) item;
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
String size = fileJson.getString("size");
|
||||
Long sizeNum = FileSizeConverter.convertToBytes(size);
|
||||
String panType = shareLinkInfo.getType();
|
||||
String id = fileJson.getString("id");
|
||||
fileInfo.setFileName(fileJson.getString("name_all"))
|
||||
.setFileId(id)
|
||||
.setCreateTime(fileJson.getString("time"))
|
||||
.setFileType(fileJson.getString("icon"))
|
||||
.setSizeStr(fileJson.getString("size"))
|
||||
.setSize(sizeNum)
|
||||
.setPanType(panType)
|
||||
.setParserUrl(getDomainName() + "/d/" + panType + "/" + id)
|
||||
.setPreviewUrl(String.format("%s/v2/view/%s/%s", getDomainName(),
|
||||
shareLinkInfo.getType(), id));
|
||||
log.debug("文件信息: {}", fileInfo);
|
||||
list.add(fileInfo);
|
||||
});
|
||||
promise.complete(list);
|
||||
});
|
||||
} catch (ScriptException | NoSuchMethodException e) {
|
||||
promise.fail(e);
|
||||
}
|
||||
});
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
125
parser/src/main/java/cn/qaiu/parser/impl/MkgsTool.java
Normal file
125
parser/src/main/java/cn/qaiu/parser/impl/MkgsTool.java
Normal file
@@ -0,0 +1,125 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 酷狗音乐分享
|
||||
* <a href="https://t1.kugou.com/song.html?id=2bi8Fe9CSV3">分享链接1</a>
|
||||
* <a href="https://www.kugou.com/share/2bi8Fe9CSV3.html?id=2bi8Fe9CSV3#6ed9gna4">分享链接2</a>
|
||||
* <a href="https://www.kugou.com/share/2bi8Fe9CSV3.html">分享链接3</a>
|
||||
* <a href="https://www.kugou.com/mixsong/8odv4ef8.html">歌曲链接1</a>
|
||||
*/
|
||||
public class MkgsTool extends PanBase {
|
||||
|
||||
public static final String API_URL = "https://m.kugou.com/app/i/getSongInfo.php?cmd=playInfo&hash={hash}";
|
||||
|
||||
private static final MultiMap headers = MultiMap.caseInsensitiveMultiMap();
|
||||
static {
|
||||
// 设置 User-Agent
|
||||
headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0");
|
||||
|
||||
// 设置 Accept
|
||||
headers.set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
|
||||
|
||||
// 设置 If-Modified-Since
|
||||
headers.set("If-Modified-Since", "Mon, 21 Oct 2024 08:45:50 GMT");
|
||||
|
||||
// 设置 Priority
|
||||
headers.set("Priority", "u=0, i");
|
||||
|
||||
// 设置 Sec-CH-UA
|
||||
headers.set("Sec-CH-UA", "\"Microsoft Edge\";v=\"129\", \"Not=A?Brand\";v=\"8\", \"Chromium\";v=\"129\"");
|
||||
|
||||
// 设置 Sec-CH-UA-Mobile
|
||||
headers.set("Sec-CH-UA-Mobile", "?0");
|
||||
|
||||
// 设置 Sec-CH-UA-Platform
|
||||
headers.set("Sec-CH-UA-Platform", "\"Windows\"");
|
||||
|
||||
// 设置 Sec-Fetch-Dest
|
||||
headers.set("Sec-Fetch-Dest", "document");
|
||||
|
||||
// 设置 Sec-Fetch-Mode
|
||||
headers.set("Sec-Fetch-Mode", "navigate");
|
||||
|
||||
// 设置 Sec-Fetch-Site
|
||||
headers.set("Sec-Fetch-Site", "none");
|
||||
|
||||
// 设置 Sec-Fetch-User
|
||||
headers.set("Sec-Fetch-User", "?1");
|
||||
|
||||
// 设置 Upgrade-Insecure-Requests
|
||||
headers.set("Upgrade-Insecure-Requests", "1");
|
||||
};
|
||||
|
||||
public MkgsTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
String shareUrl = shareLinkInfo.getStandardUrl();
|
||||
// String shareUrl = "https://t1.kugou.com/song.html?id=2bi8Fe9CSV3";
|
||||
clientNoRedirects.getAbs(shareUrl).send().onSuccess(res -> {
|
||||
String locationURL = res.headers().get("Location");
|
||||
downUrl(locationURL);
|
||||
}).onFailure(handleFail(shareUrl));
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
protected void downUrl(String locationURL) {
|
||||
client.getAbs(locationURL).putHeaders(headers).send().onSuccess(res2->{
|
||||
String body = res2.bodyAsString();
|
||||
// 正则表达式匹配 hash 字段
|
||||
String regex = "\"hash\"\s*:\s*\"([A-F0-9]+)\"";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(body);
|
||||
|
||||
// 查找并输出 hash 字段的值
|
||||
if (matcher.find()) {
|
||||
String hashValue = matcher.group(1); // 获取第一个捕获组
|
||||
System.out.println(hashValue);
|
||||
client.getAbs(UriTemplate.of(API_URL)).setTemplateParam("hash", hashValue).send().onSuccess(res3 -> {
|
||||
JsonObject jsonObject = asJson(res3);
|
||||
System.out.println(jsonObject.encodePrettily());
|
||||
if (jsonObject.containsKey("url")) {
|
||||
promise.complete(jsonObject.getString("url"));
|
||||
} else {
|
||||
fail("下载链接不存在");
|
||||
}
|
||||
}).onFailure(handleFail(API_URL.replace("{hash}", hashValue)));
|
||||
} else {
|
||||
fail("歌曲hash匹配失败, 可能分享已失效");
|
||||
}
|
||||
}).onFailure(handleFail(locationURL));
|
||||
}
|
||||
|
||||
public static class MkgTool extends MkgsTool {
|
||||
|
||||
public MkgTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
downUrl(shareLinkInfo.getStandardUrl());
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
public static class Mkgs2Tool extends MkgTool {
|
||||
public Mkgs2Tool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
parser/src/main/java/cn/qaiu/parser/impl/MkwTool.java
Normal file
68
parser/src/main/java/cn/qaiu/parser/impl/MkwTool.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.JsExecUtils;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 酷我音乐分享
|
||||
* <a href="https://kuwo.cn/play_detail/395500809">分享示例</a>
|
||||
* <a href="https://m.kuwo.cn/newh5app/play_detail/318448522">分享示例</a>
|
||||
*/
|
||||
public class MkwTool extends PanBase {
|
||||
|
||||
public static final String API_URL = "https://www.kuwo.cn/api/v1/www/music/playUrl?mid={mid}&type=music&httpsStatus=1&reqId=&plat=web_www&from=";
|
||||
|
||||
|
||||
public MkwTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
String shareUrl = shareLinkInfo.getStandardUrl();
|
||||
clientSession.getAbs(shareUrl).send().onSuccess(result -> {
|
||||
String cookie = result.headers().get("set-cookie");
|
||||
|
||||
if (!cookie.isEmpty()) {
|
||||
|
||||
String regex = "([A-Za-z0-9_]+)=([A-Za-z0-9]+)";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(cookie);
|
||||
if (matcher.find()) {
|
||||
System.out.println(matcher.group(1));
|
||||
System.out.println(matcher.group(2));
|
||||
|
||||
var key = matcher.group(1);
|
||||
var token = matcher.group(2);
|
||||
String sign = JsExecUtils.getKwSign(token, key);
|
||||
System.out.println(sign);
|
||||
clientSession.getAbs(UriTemplate.of(API_URL)).setTemplateParam("mid", shareLinkInfo.getShareKey())
|
||||
.putHeader("Secret", sign).send().onSuccess(res -> {
|
||||
JsonObject json = asJson(res);
|
||||
log.debug(json.encodePrettily());
|
||||
try {
|
||||
if (json.getInteger("code") == 200) {
|
||||
complete(json.getJsonObject("data").getString("url"));
|
||||
} else {
|
||||
fail("链接已失效/需要VIP");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("解析失败");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
26
parser/src/main/java/cn/qaiu/parser/impl/MmgTool.java
Normal file
26
parser/src/main/java/cn/qaiu/parser/impl/MmgTool.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
|
||||
/**
|
||||
* 咪咕音乐分享
|
||||
*/
|
||||
public class MmgTool extends PanBase {
|
||||
|
||||
public static final String API_URL = "";
|
||||
|
||||
|
||||
public MmgTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
String shareUrl = shareLinkInfo.getStandardUrl();
|
||||
|
||||
// TODO
|
||||
promise.complete("暂未实现, 敬请期待");
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
59
parser/src/main/java/cn/qaiu/parser/impl/MnesTool.java
Normal file
59
parser/src/main/java/cn/qaiu/parser/impl/MnesTool.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.URLUtil;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
/**
|
||||
* 网易云音乐, 单歌曲直链解析
|
||||
* <a href="http://163cn.tv/ykLZJJT">示例分享1</a>
|
||||
* <a href="https://music.163.com/#/song?id=472194327">示例分享2</a>
|
||||
*/
|
||||
public class MnesTool extends PanBase {
|
||||
|
||||
|
||||
public static final String API_URL = "https://music.163.com/song/media/outer/url?id={id}";
|
||||
|
||||
|
||||
public MnesTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
String shareUrl = shareLinkInfo.getStandardUrl();
|
||||
clientNoRedirects.getAbs(shareUrl).send().onSuccess(res -> {
|
||||
String locationURL = res.headers().get("Location");
|
||||
downUrl(locationURL);
|
||||
}).onFailure(handleFail(shareUrl));
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
protected void downUrl(String locationURL) {
|
||||
String id = URLUtil.from(locationURL).getParam("id");
|
||||
clientNoRedirects.getAbs(UriTemplate.of(API_URL)).setTemplateParam("id", id).send()
|
||||
.onSuccess(res2 -> {
|
||||
String location = res2.headers().get("Location");
|
||||
if (location.endsWith("/404")) {
|
||||
fail("链接已失效: id={}", id);
|
||||
} else {
|
||||
promise.complete(location);
|
||||
}
|
||||
}).onFailure(handleFail(API_URL.replace("{id}", id)));
|
||||
}
|
||||
|
||||
|
||||
public static class MneTool extends MnesTool{
|
||||
|
||||
public MneTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
downUrl(shareLinkInfo.getStandardUrl());
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
}
|
||||
78
parser/src/main/java/cn/qaiu/parser/impl/MqqsTool.java
Normal file
78
parser/src/main/java/cn/qaiu/parser/impl/MqqsTool.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.URLUtil;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* QQ音乐分享解析
|
||||
* <a href="https://c6.y.qq.com/base/fcgi-bin/u?__=w3lqEpOHACLO">分享示例</a>
|
||||
* <a href="https://y.qq.com/n/ryqq/songDetail/000XjcLg0fbRjv?songtype=0">详情页</a>
|
||||
*/
|
||||
public class MqqsTool extends PanBase {
|
||||
|
||||
public static final String API_URL = "https://u.y.qq.com/cgi-bin/musicu" +
|
||||
".fcg?-=getplaysongvkey2682247447678878&g_tk=5381&loginUin=956581739&hostUin=0&format=json&inCharset=utf8" +
|
||||
"&outCharset=utf-8¬ice=0&platform=yqq.json&needNewCode=0&data=%7B%22req_0%22%3A%7B%22module%22%3A" +
|
||||
"%22vkey.GetVkeyServer%22%2C%22method%22%3A%22CgiGetVkey%22%2C%22param%22%3A%7B%22guid%22%3A%222796982635" +
|
||||
"%22%2C%22songmid%22%3A%5B%22{songmid}%22%5D%2C%22songtype%22%3A%5B1%5D%2C%22uin%22%3A%22956581739%22" +
|
||||
"%2C%22loginflag%22%3A1%2C%22platform%22%3A%2220%22%7D%7D%2C%22comm%22%3A%7B%22uin%22%3A956581739%2C" +
|
||||
"%22format%22%3A%22json%22%2C%22ct%22%3A24%2C%22cv%22%3A0%7D%7D";
|
||||
|
||||
public MqqsTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
String shareUrl = shareLinkInfo.getStandardUrl();
|
||||
// https://c6.y.qq.com/base/fcgi-bin/u?__=uXXtsB
|
||||
// String shareUrl = "https://c6.y.qq.com/base/fcgi-bin/u?__=k8gafY6HAQ5Y";
|
||||
|
||||
clientNoRedirects.getAbs(shareUrl).send().onSuccess(res -> {
|
||||
String locationURL = res.headers().get("Location");
|
||||
String id = URLUtil.from(locationURL).getParam("songmid");
|
||||
downUrl(id);
|
||||
}).onFailure(handleFail(shareUrl));
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
protected void downUrl(String id) {
|
||||
clientNoRedirects.getAbs(UriTemplate.of(API_URL)).setTemplateParam("songmid", id).send().onSuccess(res2 -> {
|
||||
JsonObject jsonObject = asJson(res2);
|
||||
log.debug(jsonObject.encodePrettily());
|
||||
try {
|
||||
JsonObject data = jsonObject.getJsonObject("req_0").getJsonObject("data");
|
||||
String path = data.getJsonArray("midurlinfo").getJsonObject(0).getString("purl");
|
||||
if (path.isEmpty()) {
|
||||
fail("暂不支持VIP音乐");
|
||||
return;
|
||||
}
|
||||
String downURL = data.getJsonArray("sip").getString(0)
|
||||
.replace("http://", "https://") + path;
|
||||
promise.complete(downURL);
|
||||
} catch (Exception e) {
|
||||
fail("获取失败");
|
||||
}
|
||||
}).onFailure(handleFail(API_URL.replace("{id}", id)));
|
||||
}
|
||||
|
||||
|
||||
public static class MqqTool extends MqqsTool{
|
||||
|
||||
public MqqTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
downUrl(shareLinkInfo.getShareKey());
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
}
|
||||
22
parser/src/main/java/cn/qaiu/parser/impl/OtherTool.java
Normal file
22
parser/src/main/java/cn/qaiu/parser/impl/OtherTool.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
|
||||
/**
|
||||
* 其他网盘解析
|
||||
*/
|
||||
public class OtherTool extends PanBase {
|
||||
private static final String API_URL_PREFIX = "";
|
||||
|
||||
public OtherTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
// TODO
|
||||
fail("暂未实现, 敬请期待");
|
||||
return future();
|
||||
}
|
||||
}
|
||||
90
parser/src/main/java/cn/qaiu/parser/impl/P115Tool.java
Normal file
90
parser/src/main/java/cn/qaiu/parser/impl/P115Tool.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
/**
|
||||
* 115网盘
|
||||
*
|
||||
* 需要请求API的UA和请求下载链接的UA保持一致,安卓Chrome需要访问电脑版才能下载
|
||||
*/
|
||||
public class P115Tool extends PanBase {
|
||||
private static final String API_URL_PREFIX = "https://115cdn.com/webapi/";
|
||||
|
||||
private static final String FIRST_REQUEST_URL = API_URL_PREFIX + "share/snap?share_code={dataKey}&offset=0" +
|
||||
"&limit=20&receive_code={dataPwd}&cid=";
|
||||
|
||||
private static final String SECOND_REQUEST_URL = API_URL_PREFIX + "share/skip_login_downurl";
|
||||
|
||||
|
||||
private static final MultiMap header;
|
||||
|
||||
static {
|
||||
header = MultiMap.caseInsensitiveMultiMap();
|
||||
header.set("Accept", "application/json, text/plain, */*");
|
||||
header.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8");
|
||||
header.set("Cache-Control", "no-cache");
|
||||
header.set("Connection", "keep-alive");
|
||||
header.set("Content-Length", "0");
|
||||
header.set("DNT", "1");
|
||||
header.set("Host", "115cdn.com");
|
||||
header.set("Origin", "https://115cdn.com");
|
||||
header.set("Pragma", "no-cache");
|
||||
header.set("Referer", "https://115cdn.com");
|
||||
header.set("Sec-Fetch-Dest", "empty");
|
||||
header.set("Sec-Fetch-Mode", "cors");
|
||||
header.set("Sec-Fetch-Site", "cross-site");
|
||||
header.set("sec-ch-ua", "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
|
||||
header.set("sec-ch-ua-mobile", "?0");
|
||||
header.set("sec-ch-ua-platform", "\"Windows\"");
|
||||
}
|
||||
|
||||
public P115Tool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
// 第一次请求 获取文件信息
|
||||
client.getAbs(UriTemplate.of(FIRST_REQUEST_URL))
|
||||
.putHeaders(header)
|
||||
.putHeader("User-Agent", shareLinkInfo.getOtherParam().get("UA").toString())
|
||||
.setTemplateParam("dataKey", shareLinkInfo.getShareKey())
|
||||
.setTemplateParam("dataPwd", shareLinkInfo.getSharePassword())
|
||||
.send().onSuccess(res -> {
|
||||
JsonObject resJson = asJson(res);
|
||||
if (!resJson.getBoolean("state")) {
|
||||
fail(FIRST_REQUEST_URL + " 解析错误: " + resJson);
|
||||
return;
|
||||
}
|
||||
// 文件Id: data.list[0].fid
|
||||
JsonObject fileInfo = resJson.getJsonObject("data").getJsonArray("list").getJsonObject(0);
|
||||
String fileId = fileInfo.getString("fid");
|
||||
|
||||
// 第二次请求
|
||||
// share_code={dataKey}&receive_code={dataPwd}&file_id={file_id}
|
||||
client.postAbs(SECOND_REQUEST_URL)
|
||||
.putHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
||||
.putHeader("User-Agent", shareLinkInfo.getOtherParam().get("UA").toString())
|
||||
.sendForm(MultiMap.caseInsensitiveMultiMap()
|
||||
.set("share_code", shareLinkInfo.getShareKey())
|
||||
.set("receive_code", shareLinkInfo.getSharePassword())
|
||||
.set("file_id", fileId))
|
||||
.onSuccess(res2 -> {
|
||||
JsonObject resJson2 = asJson(res2);
|
||||
if (!resJson2.getBoolean("state")) {
|
||||
fail(FIRST_REQUEST_URL + " 解析错误: " + resJson2);
|
||||
return;
|
||||
}
|
||||
// data.url.url
|
||||
promise.complete(resJson2.getJsonObject("data").getJsonObject("url").getString("url"));
|
||||
}).onFailure(handleFail(SECOND_REQUEST_URL));
|
||||
}).onFailure(handleFail(FIRST_REQUEST_URL));
|
||||
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
50
parser/src/main/java/cn/qaiu/parser/impl/P118Tool.java
Normal file
50
parser/src/main/java/cn/qaiu/parser/impl/P118Tool.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 118网盘解析
|
||||
*/
|
||||
public class P118Tool extends PanBase {
|
||||
|
||||
private static final String API_URL_PREFIX = "https://qaiu.118pan.com/ajax.php";
|
||||
|
||||
// private static final String
|
||||
|
||||
public P118Tool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
|
||||
client.postAbs(API_URL_PREFIX)
|
||||
.putHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
||||
.sendBuffer(Buffer.buffer("action=load_down_addr1&file_id=" + shareLinkInfo.getShareKey()))
|
||||
.onSuccess(res -> {
|
||||
System.out.println(res.headers());
|
||||
Pattern compile = Pattern.compile("href=\"([^\"]+)\"");
|
||||
Matcher matcher = compile.matcher(res.bodyAsString());
|
||||
if (matcher.find()) {
|
||||
//c: 0x63
|
||||
//o: 0x6F
|
||||
//m: 0x6D
|
||||
//1: 0x31
|
||||
///: 0x2F
|
||||
char[] chars1 = new char[]{99, 111, 109, 49, 47};
|
||||
char[] chars2 = new char[]{99, 111, 109, 47};
|
||||
String group = matcher.group(1).replace(String.valueOf(chars1), String.valueOf(chars2));
|
||||
System.out.println(group);
|
||||
complete(group);
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}).onFailure(handleFail(""));
|
||||
return future();
|
||||
}
|
||||
}
|
||||
109
parser/src/main/java/cn/qaiu/parser/impl/P360Tool.java
Normal file
109
parser/src/main/java/cn/qaiu/parser/impl/P360Tool.java
Normal file
@@ -0,0 +1,109 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <a href="https://yunpan.360.cn">360AI云盘</a>
|
||||
* 360AI云盘解析
|
||||
* 下载链接需要Referer: https://link.yunpan.com/
|
||||
*/
|
||||
public class P360Tool extends PanBase {
|
||||
public P360Tool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
// https://www.yunpan.com/surl_yD7jK9d4W6D 获取302跳转地址
|
||||
clientNoRedirects.getAbs(shareLinkInfo.getShareUrl()).send()
|
||||
.onSuccess(res -> {
|
||||
String location = res.getHeader("Location");
|
||||
if (location != null) {
|
||||
down302(location);
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}).onFailure(handleFail(""));
|
||||
|
||||
|
||||
return future();
|
||||
}
|
||||
|
||||
private void down302(String url) {
|
||||
// 获取URL前缀 https://214004.link.yunpan.com/lk/surl_yD7ZU4WreR8 -> https://214004.link.yunpan.com/
|
||||
String urlPrefix = url.substring(0, url.indexOf("/", 8));
|
||||
|
||||
clientSession.getAbs(url)
|
||||
.send()
|
||||
.onSuccess(res -> {
|
||||
// find "nid": "17402043311959599"
|
||||
Pattern compile = Pattern.compile("\"nid\": \"([^\"]+)\"");
|
||||
Matcher matcher = compile.matcher(res.bodyAsString());
|
||||
AtomicReference<String> nid = new AtomicReference<>();
|
||||
if (matcher.find()) {
|
||||
nid.set(matcher.group(1));
|
||||
} else {
|
||||
// 需要验证密码
|
||||
/*
|
||||
* POST https://4aec17.link.yunpan.com/share/verifyPassword
|
||||
* Content-type: application/x-www-form-urlencoded UTF-8
|
||||
* Referer: https://4aec17.link.yunpan.com/lk/surl_yD7jK9d4W6D
|
||||
*
|
||||
* shorturl=surl_yD7jK9d4W6D&linkpassword=d969
|
||||
*/
|
||||
clientSession.postAbs(urlPrefix + "/share/verifyPassword")
|
||||
.putHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
.putHeader("Referer", urlPrefix)
|
||||
.sendBuffer(Buffer.buffer("shorturl=" + shareLinkInfo.getShareKey() + "&linkpassword" +
|
||||
"=" + shareLinkInfo.getSharePassword()))
|
||||
.onSuccess(res2 -> {
|
||||
JsonObject entries = asJson(res2);
|
||||
if (entries.getInteger("errno") == 0) {
|
||||
clientSession.getAbs(url)
|
||||
.send()
|
||||
.onSuccess(res3 -> {
|
||||
Matcher matcher1 = compile.matcher(res3.bodyAsString());
|
||||
if (matcher1.find()) {
|
||||
nid.set(matcher1.group(1));
|
||||
} else {
|
||||
fail();
|
||||
return;
|
||||
}
|
||||
down(urlPrefix, nid.get());
|
||||
}).onFailure(handleFail(""));
|
||||
} else {
|
||||
fail(entries.encode());
|
||||
}
|
||||
}).onFailure(handleFail(""));
|
||||
return;
|
||||
}
|
||||
down(urlPrefix, nid.get());
|
||||
}).onFailure(handleFail(""));
|
||||
}
|
||||
|
||||
private void down(String urlPrefix, String nid) {
|
||||
clientSession.postAbs(urlPrefix + "/share/downloadfile")
|
||||
.putHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
.putHeader("Referer", urlPrefix)
|
||||
.sendBuffer(Buffer.buffer("shorturl=" + shareLinkInfo.getShareKey() + "&nid=" + nid))
|
||||
.onSuccess(res2 -> {
|
||||
JsonObject entries = asJson(res2);
|
||||
String downloadurl = entries.getJsonObject("data").getString("downloadurl");
|
||||
complete(downloadurl);
|
||||
}).onFailure(handleFail(""));
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// String s = new P360Tool(ShareLinkInfo.newBuilder().shareUrl("https://www.yunpan.com/surl_yD7ZU4WreR8")
|
||||
// .shareKey("surl_yD7ZU4WreR8")
|
||||
// .build()).parseSync();
|
||||
// System.out.println(s);
|
||||
// }
|
||||
}
|
||||
47
parser/src/main/java/cn/qaiu/parser/impl/PcxTool.java
Normal file
47
parser/src/main/java/cn/qaiu/parser/impl/PcxTool.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
/**
|
||||
* <a href="https://passport2.chaoxing.com">超星云盘</a>
|
||||
*/
|
||||
public class PcxTool extends PanBase {
|
||||
|
||||
public PcxTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
client.getAbs(shareLinkInfo.getShareUrl())
|
||||
.send().onSuccess(res -> {
|
||||
// 'download': 'https://d0.ananas.chaoxing.com/download/de08dcf546e4dd88a17bead86ff6338d?at_=1740211698795&ak_=d62a3acbd5ce43e1e8565b67990691e4&ad_=8c4ef22e980ee0dd9532ec3757ab19f8&fn=33.c'
|
||||
String body = res.bodyAsString();
|
||||
// 获取download
|
||||
String str = "var fileinfo = {";
|
||||
String fileInfo = res.bodyAsString().substring(res.bodyAsString().indexOf(str) + str.length() - 1
|
||||
, res.bodyAsString().indexOf("};") + 1);
|
||||
fileInfo = fileInfo.replace("'", "\"");
|
||||
JsonObject jsonObject = new JsonObject(fileInfo);
|
||||
String download = jsonObject.getString("download");
|
||||
if (download.contains("fn=")) {
|
||||
complete(download);
|
||||
} else {
|
||||
fail("获取下载链接失败: 不支持的文件类型: {}", jsonObject.getString("suffix"));
|
||||
}
|
||||
}).onFailure(handleFail(shareLinkInfo.getShareUrl()));
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// String s = new PcxTool(ShareLinkInfo.newBuilder().shareUrl("https://pan-yz.cldisk.com/external/m/file/953658049102462976")
|
||||
// .shareKey("953658049102462976")
|
||||
// .build()).parseSync();
|
||||
// System.out.println(s);
|
||||
// }
|
||||
}
|
||||
95
parser/src/main/java/cn/qaiu/parser/impl/PdbTool.java
Normal file
95
parser/src/main/java/cn/qaiu/parser/impl/PdbTool.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.IPanTool;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.URLUtil;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.net.ProxyOptions;
|
||||
import io.vertx.ext.web.client.HttpRequest;
|
||||
import io.vertx.ext.web.client.HttpResponse;
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <a href="https://www.dropbox.com/">dropbox</a>
|
||||
* Dropbox网盘--不支持大陆地区
|
||||
*/
|
||||
public class PdbTool extends PanBase implements IPanTool {
|
||||
|
||||
private static final String API_URL =
|
||||
"https://www.dropbox.com/sharing/fetch_user_content_link";
|
||||
static final String COOKIE_KEY = "__Host-js_csrf=";
|
||||
|
||||
public PdbTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
// https://www.dropbox.com/scl/fi/cwnbms1yn8u6rcatzyta7/emqx-5.0.26-el7-amd64.tar.gz?rlkey=3uoi4bxz5mv93jmlaws0nlol1&e=8&st=fe0lclc2&dl=0
|
||||
// https://www.dropbox.com/scl/fi/()/Get-Started-with-Dropbox.pdf?rlkey=yrddd6s9gxsq967pmbgtzvfl3&st=2trcc1f3&dl=0
|
||||
//
|
||||
clientSession.getAbs(shareLinkInfo.getShareUrl())
|
||||
.send()
|
||||
.onSuccess(res->{
|
||||
List<String> collect =
|
||||
res.cookies().stream().filter(key -> key.contains(COOKIE_KEY)).toList();
|
||||
if (collect.isEmpty()) {
|
||||
fail("cookie未找到");
|
||||
return;
|
||||
}
|
||||
Matcher matcher = Pattern.compile(COOKIE_KEY + "([\\w-]+);").matcher(collect.get(0));
|
||||
String _t;
|
||||
if (matcher.find()) {
|
||||
_t = matcher.group(1);
|
||||
} else {
|
||||
fail("cookie未找到");
|
||||
return;
|
||||
}
|
||||
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
|
||||
headers.set("accept", "*/*");
|
||||
headers.set("accept-language", "zh-CN,zh;q=0.9");
|
||||
headers.set("cache-control", "no-cache");
|
||||
headers.set("dnt", "1");
|
||||
headers.set("origin", "https://www.dropbox.com");
|
||||
headers.set("pragma", "no-cache");
|
||||
headers.set("priority", "u=1, i");
|
||||
headers.set("referer", shareLinkInfo.getShareUrl());
|
||||
headers.set("sec-ch-ua", "\"Chromium\";v=\"130\", \"Microsoft Edge\";v=\"130\", \"Not?A_Brand\";v=\"99\"");
|
||||
headers.set("sec-ch-ua-mobile", "?0");
|
||||
headers.set("sec-ch-ua-platform", "\"Windows\"");
|
||||
headers.set("sec-fetch-dest", "empty");
|
||||
headers.set("sec-fetch-mode", "cors");
|
||||
headers.set("sec-fetch-site", "same-origin");
|
||||
headers.set("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0");
|
||||
headers.set("x-dropbox-client-yaps-attribution", "edison_atlasservlet.file_viewer-edison:prod");
|
||||
headers.set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
try {
|
||||
URL url = new URL(shareLinkInfo.getShareUrl());
|
||||
// https://www.dropbox.com/scl/fi/cwnbms1yn8u6rcatzyta7/xxx?rlkey=xx&dl=0
|
||||
String u0 = URLEncoder.encode((url.getProtocol() + "://" + url.getHost() + url.getPath() + "?rlkey=%s&dl=0")
|
||||
.formatted(URLUtil.from(shareLinkInfo.getShareUrl()).getParam("rlkey")), StandardCharsets.UTF_8);
|
||||
clientSession.postAbs(API_URL)
|
||||
.sendBuffer(Buffer.buffer("is_xhr=true&t=%s&url=%s&origin=PREVIEW_PAGE".formatted(_t, u0)))
|
||||
.onSuccess(res2 -> {
|
||||
complete(res2.bodyAsString());
|
||||
})
|
||||
.onFailure(handleFail());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
})
|
||||
.onFailure(handleFail("请求下载链接失败"));
|
||||
return future();
|
||||
}
|
||||
}
|
||||
98
parser/src/main/java/cn/qaiu/parser/impl/PgdTool.java
Normal file
98
parser/src/main/java/cn/qaiu/parser/impl/PgdTool.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.IPanTool;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.net.ProxyOptions;
|
||||
import io.vertx.ext.web.client.HttpRequest;
|
||||
import io.vertx.ext.web.client.HttpResponse;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <a href="https://drive.google.com/">GoogleDrive</a>
|
||||
* Google Drive文件解析工具.
|
||||
*/
|
||||
public class PgdTool extends PanBase implements IPanTool {
|
||||
|
||||
private static final String DOWN_URL_TEMPLATE =
|
||||
"https://drive.usercontent.google.com/download";
|
||||
|
||||
private String downloadUrl;
|
||||
|
||||
public PgdTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
downloadUrl = DOWN_URL_TEMPLATE + "?id=" + shareLinkInfo.getShareKey() + "&export=download";
|
||||
|
||||
if (shareLinkInfo.getOtherParam().containsKey("proxy")) {
|
||||
// if (shareLinkInfo.getOtherParam().containsKey("bypassCheck")
|
||||
// && "true".equalsIgnoreCase(shareLinkInfo.getOtherParam().get("bypassCheck").toString())) {
|
||||
// 发起请求但不真正下载文件, 只检查响应头
|
||||
client.headAbs(downloadUrl).send()
|
||||
.onSuccess(this::handleResponse)
|
||||
.onFailure(handleFail("请求下载链接失败"));
|
||||
return future();
|
||||
}
|
||||
complete(downloadUrl);
|
||||
return future();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理下载链接的响应.
|
||||
*/
|
||||
private void handleResponse(HttpResponse<Buffer> response) {
|
||||
String contentType = response.getHeader("Content-Type");
|
||||
if (contentType != null && !contentType.contains("text/html")) {
|
||||
complete(downloadUrl);
|
||||
} else {
|
||||
// 如果不是文件流类型,从 HTML 中解析出真实下载链接
|
||||
client.getAbs(downloadUrl)
|
||||
.send()
|
||||
.onSuccess(res0 -> {
|
||||
parseHtmlForRealLink(res0.bodyAsString());
|
||||
})
|
||||
.onFailure(handleFail("请求下载链接失败"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从HTML内容中解析真实下载链接.
|
||||
*/
|
||||
private void parseHtmlForRealLink(String html) {
|
||||
// 使用正则表达式匹配 id、export、confirm、uuid、at 等参数
|
||||
String id = extractHiddenInputValue(html, "id");
|
||||
String confirm = extractHiddenInputValue(html, "confirm");
|
||||
String uuid = extractHiddenInputValue(html, "uuid");
|
||||
String at = extractHiddenInputValue(html, "at");
|
||||
|
||||
if (id != null && confirm != null && uuid != null) {
|
||||
String realDownloadLink = DOWN_URL_TEMPLATE +
|
||||
"?id=" + id +
|
||||
"&export=download" +
|
||||
"&confirm=" + confirm +
|
||||
"&uuid=" + uuid;
|
||||
if (at != null) {
|
||||
realDownloadLink += ( "&at=" + at);
|
||||
}
|
||||
complete(realDownloadLink);
|
||||
} else {
|
||||
fail("无法找到完整的下载链接参数");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 辅助方法: 从HTML中提取指定name的input隐藏字段的value
|
||||
*/
|
||||
private String extractHiddenInputValue(String html, String name) {
|
||||
Pattern pattern = Pattern.compile("<input[^>]*name=\"" + name + "\"[^>]*value=\"([^\"]*)\"");
|
||||
Matcher matcher = pattern.matcher(html);
|
||||
return matcher.find() ? matcher.group(1) : null;
|
||||
}
|
||||
}
|
||||
58
parser/src/main/java/cn/qaiu/parser/impl/PicTool.java
Normal file
58
parser/src/main/java/cn/qaiu/parser/impl/PicTool.java
Normal file
@@ -0,0 +1,58 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* <a href="https://www.icloud.com.cn/">iCloud云盘(pic)</a>
|
||||
*/
|
||||
public class PicTool extends PanBase {
|
||||
|
||||
|
||||
private static final String api = "https://ckdatabasews.icloud.com.cn/database/1/com.apple.cloudkit/production/public/records/resolve";
|
||||
|
||||
public PicTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
// {"shortGUIDs":[{"value":"xxx"}]}
|
||||
JsonObject jsonObject =
|
||||
new JsonObject("{\"shortGUIDs\":[{\"value\":\"%s\"}]}".formatted(shareLinkInfo.getShareKey()));
|
||||
|
||||
client.postAbs(api).sendJsonObject(jsonObject).onSuccess(res -> {
|
||||
// results->rootRecord->fields->fileContent->value->downloadURL // ${f}->fileName
|
||||
// fileName: results->share->fields->cloudkit.title->value + "." + results->rootRecord->fields->extension->value
|
||||
JsonObject json = asJson(res);
|
||||
try {
|
||||
JsonObject result = json.getJsonArray("results").getJsonObject(0);
|
||||
JsonObject fileInfo = result
|
||||
.getJsonObject("rootRecord")
|
||||
.getJsonObject("fields");
|
||||
|
||||
String downURL = fileInfo
|
||||
.getJsonObject("fileContent")
|
||||
.getJsonObject("value")
|
||||
.getString("downloadURL");
|
||||
|
||||
String extension = fileInfo
|
||||
.getJsonObject("extension")
|
||||
.getString("value");
|
||||
|
||||
String fileTitle = result
|
||||
.getJsonObject("share")
|
||||
.getJsonObject("fields")
|
||||
.getJsonObject("cloudkit.title")
|
||||
.getString("value");
|
||||
complete(downURL.replace("${f}", fileTitle + "." + extension));
|
||||
} catch (Exception e) {
|
||||
fail(e, "json解析失败");
|
||||
}
|
||||
|
||||
}).onFailure(handleFail());
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
231
parser/src/main/java/cn/qaiu/parser/impl/PodTool.java
Normal file
231
parser/src/main/java/cn/qaiu/parser/impl/PodTool.java
Normal file
@@ -0,0 +1,231 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.WebClientVertxInit;
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.WorkerExecutor;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* <a href="https://onedrive.live.com/">onedrive分享(od)</a>
|
||||
*/
|
||||
public class PodTool extends PanBase {
|
||||
|
||||
/*
|
||||
* https://1drv.ms/w/s!Alg0feQmCv2rnRFd60DQOmMa-Oh_?e=buaRtp --302->
|
||||
* https://api.onedrive.com/v1.0/drives/abfd0a26e47d3458/items/ABFD0A26E47D3458!3729?authkey=!AF3rQNA6Yxr46H8
|
||||
* https://onedrive.live.com/redir?resid=(?<cid>)!(?<cid2>)&authkey=(?<authkey>)&e=hV98W1
|
||||
* cid: abfd0a26e47d3458, cid2: ABFD0A26E47D3458!3729 authkey: !AF3rQNA6Yxr46H8
|
||||
* -> @content.downloadUrl
|
||||
*/
|
||||
|
||||
|
||||
// https://onedrive.live.com/redir?resid=ABFD0A26E47D3458!4699&e=OggA4s&migratedtospo=true&redeem=aHR0cHM6Ly8xZHJ2Lm1zL3UvcyFBbGcwZmVRbUN2MnJwRnZ1NDQ0aGc1eVZxRGNLP2U9T2dnQTRz
|
||||
private static final String API_TEMPLATE = "https://onedrive.live.com/embed" +
|
||||
"?id={resid}&resid={resid1}" +
|
||||
"&cid={cid}" +
|
||||
"&redeem={redeem}" +
|
||||
"&migratedtospo=true&embed=1";
|
||||
|
||||
private static final String TOKEN_API = "https://api-badgerp.svc.ms/v1.0/token";
|
||||
|
||||
|
||||
private static final Pattern redirectUrlRegex =
|
||||
Pattern.compile("resid=(?<cid1>[^!]+)!(?<cid2>[^&]+).+&redeem=(?<redeem>.+).*");
|
||||
|
||||
public PodTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
|
||||
|
||||
/*
|
||||
* POST https://api-badgerp.svc.ms/v1.0/token
|
||||
* Content-Type: application/json
|
||||
*
|
||||
* {
|
||||
* "appid": "00000000-0000-0000-0000-0000481710a4"
|
||||
* }
|
||||
*/
|
||||
// https://my.microsoftpersonalcontent.com/_api/v2.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL3UvcyFBbGcwZmVRbUN2MnJwRnZ1NDQ0aGc1eVZxRGNLP2U9T2dnQTRz/driveitem?%24select=*%2Cocr%2CwebDavUrl
|
||||
// https://onedrive.live.com/embed?id=ABFD0A26E47D3458!4698&resid=ABFD0A26E47D3458!4698&cid=abfd0a26e47d3458&redeem=aHR0cHM6Ly8xZHJ2Lm1zL3UvYy9hYmZkMGEyNmU0N2QzNDU4L0lRUllOSDNrSmdyOUlJQ3JXaElBQUFBQUFTWGlubWZ2WmNxYUQyMXJUQjIxVmg4&migratedtospo=true&embed=1
|
||||
|
||||
|
||||
clientNoRedirects.getAbs(shareLinkInfo.getShareUrl() == null ? shareLinkInfo.getStandardUrl() :
|
||||
shareLinkInfo.getShareUrl()).send().onSuccess(r0 -> {
|
||||
String location = r0.getHeader("Location");
|
||||
Matcher matcher = redirectUrlRegex.matcher(location);
|
||||
if (!matcher.find()) {
|
||||
fail("Location格式错误");
|
||||
return;
|
||||
}
|
||||
String redeem = matcher.group("redeem");
|
||||
String cid1 = matcher.group("cid1");
|
||||
String cid2 = cid1 + "!" + matcher.group("cid2");
|
||||
|
||||
clientNoRedirects.getAbs(UriTemplate.of(API_TEMPLATE))
|
||||
.setTemplateParam("resid", cid2)
|
||||
.setTemplateParam("resid1", cid2)
|
||||
.setTemplateParam("cid", cid1.toLowerCase())
|
||||
.setTemplateParam("redeem", redeem)
|
||||
.send()
|
||||
.onSuccess(r1 -> {
|
||||
String auth =
|
||||
r1.cookies().stream().filter(c -> c.startsWith("BadgerAuth=")).findFirst().orElse("");
|
||||
if (auth.isEmpty()) {
|
||||
fail("Error BadgerAuth not fount");
|
||||
return;
|
||||
}
|
||||
String token = auth.split(";")[0].split("=")[1];
|
||||
|
||||
try {
|
||||
|
||||
String url = matcherUrl(r1.bodyAsString());
|
||||
|
||||
sendHttpRequest(url, token).onSuccess(body -> {
|
||||
Matcher matcher1 =
|
||||
Pattern.compile("\"downloadUrl\":\"(?<url>https?://[^\s\"]+)").matcher(body);
|
||||
if (matcher1.find()) {
|
||||
complete(matcher1.group("url"));
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}).onFailure(handleFail());
|
||||
} catch (Exception ignored) {
|
||||
sendHttpRequest2(token, redeem).onSuccess(res -> {
|
||||
try {
|
||||
complete(new JsonObject(res).getString("@content.downloadUrl"));
|
||||
} catch (Exception ignored1) {
|
||||
fail();
|
||||
}
|
||||
}).onFailure(handleFail());
|
||||
}
|
||||
|
||||
}).onFailure(handleFail());
|
||||
}).onFailure(handleFail());
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private String matcherUrl(String html) {
|
||||
|
||||
// 正则表达式来匹配 URL
|
||||
String urlRegex = "'action'.+(?<url>https://.+)'\\)";
|
||||
Pattern urlPattern = Pattern.compile(urlRegex);
|
||||
Matcher urlMatcher = urlPattern.matcher(html);
|
||||
|
||||
if (urlMatcher.find()) {
|
||||
String url = urlMatcher.group("url");
|
||||
System.out.println("URL: " + url);
|
||||
return url;
|
||||
}
|
||||
throw new RuntimeException("URL匹配失败");
|
||||
}
|
||||
|
||||
|
||||
private String matcherToken(String html) {
|
||||
// 正则表达式来匹配 inputElem.value 中的 Token
|
||||
String tokenRegex = "inputElem\\.value\\s*=\\s*'([^']+)'";
|
||||
Pattern tokenPattern = Pattern.compile(tokenRegex);
|
||||
Matcher tokenMatcher = tokenPattern.matcher(html);
|
||||
|
||||
if (tokenMatcher.find()) {
|
||||
String token = tokenMatcher.group(1);
|
||||
System.out.println("Token: " + token);
|
||||
return token;
|
||||
}
|
||||
throw new RuntimeException("token匹配失败");
|
||||
}
|
||||
|
||||
public Future<String> sendHttpRequest2(String token, String redeem) {
|
||||
Promise<String> promise = Promise.promise();
|
||||
// 构造 HttpClient
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
|
||||
// 构造请求的 URI 和头部信息
|
||||
// https://onedrive.live.com/redir?cid=abfd0a26e47d3458&resid=ABFD0A26E47D3458!4465&ithint=file%2cxlsx&e=Ao2uSU&migratedtospo=true&redeem=aHR0cHM6Ly8xZHJ2Lm1zL3gvYy9hYmZkMGEyNmU0N2QzNDU4L0VWZzBmZVFtQ3YwZ2dLdHhFUUFBQUFBQlRQRWVDMTZfZk1EYk5FTjhEdTRta1E_ZT1BbzJ1U1U
|
||||
String url = ("https://my.microsoftpersonalcontent.com/_api/v2.0/shares/u!%s/driveItem?$select=content" +
|
||||
".downloadUrl").formatted(redeem);
|
||||
String authorizationHeader = "Badger " + token;
|
||||
|
||||
// 构建请求
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url))
|
||||
.header("Authorization", authorizationHeader)
|
||||
.build();
|
||||
|
||||
// 发送请求并处理响应
|
||||
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
||||
.thenApply(response -> {
|
||||
System.out.println("Response Status Code: " + response.statusCode());
|
||||
System.out.println("Response Body: " + response.body());
|
||||
promise.complete(response.body());
|
||||
return null;
|
||||
});
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
public Future<String> sendHttpRequest(String url, String token) {
|
||||
// 创建一个 WorkerExecutor 用于异步执行阻塞的 HTTP 请求
|
||||
WorkerExecutor executor = WebClientVertxInit.get().createSharedWorkerExecutor("http-client-worker");
|
||||
|
||||
Promise<String> promise = Promise.promise();
|
||||
executor.executeBlocking(() -> {
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = null;
|
||||
|
||||
try {
|
||||
// 构造请求
|
||||
request = HttpRequest.newBuilder()
|
||||
.uri(new URI(url))
|
||||
.header("accept", "text/html,application/xhtml+xml,application/xml;q=0.9," +
|
||||
"image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;" +
|
||||
"v=b3;q=0.7")
|
||||
.header("accept-language", "zh-CN,zh;q=0.9")
|
||||
.header("cache-control", "no-cache")
|
||||
.header("content-type", "application/x-www-form-urlencoded")
|
||||
.header("dnt", "1")
|
||||
.header("origin", "https://onedrive.live.com")
|
||||
.header("pragma", "no-cache")
|
||||
.header("priority", "u=0, i")
|
||||
.header("referer", "https://onedrive.live.com/")
|
||||
.header("sec-ch-ua", "\"Chromium\";v=\"130\", \"Google Chrome\";v=\"130\", " +
|
||||
"\"Not?A_Brand\";v=\"99\"")
|
||||
.header("sec-ch-ua-mobile", "?0")
|
||||
.header("sec-ch-ua-platform", "\"Windows\"")
|
||||
.header("sec-fetch-dest", "iframe")
|
||||
.header("sec-fetch-mode", "navigate")
|
||||
.header("sec-fetch-site", "cross-site")
|
||||
.header("upgrade-insecure-requests", "1")
|
||||
.header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537" +
|
||||
".36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36")
|
||||
.POST(HttpRequest.BodyPublishers.ofString("badger_token=" + token))
|
||||
.build();
|
||||
|
||||
// 发起请求并获取响应
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
// 返回响应体
|
||||
promise.complete(response.body());
|
||||
return null;
|
||||
} catch (URISyntaxException | IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
221
parser/src/main/java/cn/qaiu/parser/impl/PvyyTool.java
Normal file
221
parser/src/main/java/cn/qaiu/parser/impl/PvyyTool.java
Normal file
@@ -0,0 +1,221 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.WebClientVertxInit;
|
||||
import cn.qaiu.entity.FileInfo;
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.FileSizeConverter;
|
||||
import cn.qaiu.util.HeaderUtils;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.json.pointer.JsonPointer;
|
||||
import io.vertx.ext.web.client.WebClient;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 微雨云
|
||||
*/
|
||||
public class PvyyTool extends PanBase {
|
||||
private static final String API_URL_PREFIX1 = "https://www.vyuyun.com/apiv1/share/file/{key}?password={pwd}";
|
||||
private static final String API_URL_PREFIX2 = "https://www.vyuyun.com/apiv1/share/getShareDownUrl/{key}/{id}?password={pwd}";
|
||||
|
||||
byte[] hexArray = {
|
||||
0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x31, 0x31, 0x36, 0x2e, 0x32, 0x30, 0x35, 0x2e,
|
||||
0x39, 0x36, 0x2e, 0x31, 0x39, 0x38, 0x3a, 0x33, 0x30, 0x30, 0x30, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x2f
|
||||
};
|
||||
|
||||
private static final MultiMap header = HeaderUtils.parseHeaders("""
|
||||
accept-language: zh-CN,zh;q=0.9,en;q=0.8
|
||||
cache-control: no-cache
|
||||
dnt: 1
|
||||
origin: https://www.vyuyun.com
|
||||
pragma: no-cache
|
||||
priority: u=1, i
|
||||
referer: https://www.vyuyun.com/
|
||||
sec-ch-ua: "Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"
|
||||
sec-ch-ua-mobile: ?0
|
||||
sec-ch-ua-platform: "Windows"
|
||||
sec-fetch-dest: empty
|
||||
sec-fetch-mode: cors
|
||||
sec-fetch-site: same-site
|
||||
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
|
||||
""");
|
||||
|
||||
private final String api;
|
||||
public PvyyTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
api = new String(hexArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
// 请求downcode
|
||||
WebClient.create(WebClientVertxInit.get())
|
||||
.getAbs(api + shareLinkInfo.getShareKey())
|
||||
.send()
|
||||
.onSuccess(res -> {
|
||||
if (res.statusCode() == 200) {
|
||||
String code = res.bodyAsString();
|
||||
log.info("vyy url:{}, code:{}", shareLinkInfo.getStandardUrl(), code);
|
||||
String downApi = API_URL_PREFIX2 + "&downcode=" + code;
|
||||
getDownUrl(downApi);
|
||||
} else {
|
||||
fail("code获取失败");
|
||||
}
|
||||
}).onFailure(handleFail("code服务异常"));
|
||||
return future();
|
||||
}
|
||||
|
||||
private void getDownUrl(String apiUrl) {
|
||||
client.getAbs(UriTemplate.of(API_URL_PREFIX1))
|
||||
.setTemplateParam("key", shareLinkInfo.getShareKey())
|
||||
.setTemplateParam("pwd", shareLinkInfo.getSharePassword())
|
||||
.putHeaders(header)
|
||||
.send().onSuccess(res -> {
|
||||
try {
|
||||
JsonObject resJson = asJson(res);
|
||||
if (!resJson.containsKey("code") || resJson.getInteger("code") != 0) {
|
||||
fail("获取文件信息失败: " + resJson.getString("message"));
|
||||
return;
|
||||
}
|
||||
JsonObject fileData = resJson.getJsonObject("data").getJsonObject("data");
|
||||
if (fileData == null) {
|
||||
fail("文件数据为空");
|
||||
return;
|
||||
}
|
||||
setFileInfo(fileData);
|
||||
String id = fileData.getString("id");
|
||||
|
||||
client.getAbs(UriTemplate.of(apiUrl))
|
||||
.setTemplateParam("key", shareLinkInfo.getShareKey())
|
||||
.setTemplateParam("pwd", shareLinkInfo.getSharePassword())
|
||||
.setTemplateParam("id", id)
|
||||
.putHeaders(header).send().onSuccess(res2 -> {
|
||||
try {
|
||||
// data->downInfo->url
|
||||
String url =
|
||||
asJson(res2).getJsonObject("data").getJsonObject("downInfo").getString("url");
|
||||
complete(url);
|
||||
} catch (Exception ignored) {
|
||||
fail(asJson(res2).encodePrettily());
|
||||
}
|
||||
});
|
||||
} catch (Exception ignored) {
|
||||
fail();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setFileInfo(JsonObject fileData) {
|
||||
JsonObject attributes = fileData.getJsonObject("attributes");
|
||||
JsonObject user = (JsonObject)(JsonPointer.from("/relationships/user/data").queryJson(fileData));
|
||||
int downCount = (Integer)(JsonPointer.from("/relationships/shared/data/attributes/down").queryJson(fileData));
|
||||
String filesize = attributes.getString("filesize");
|
||||
FileInfo fileInfo = new FileInfo()
|
||||
.setFileId(fileData.getString("id"))
|
||||
.setFileName(attributes.getString("basename"))
|
||||
.setFileType(attributes.getString("mimetype"))
|
||||
.setPanType(shareLinkInfo.getType())
|
||||
.setCreateBy(user.getString("email"))
|
||||
.setDownloadCount(downCount)
|
||||
.setSize(FileSizeConverter.convertToBytes(filesize))
|
||||
.setSizeStr(filesize);
|
||||
shareLinkInfo.getOtherParam().put("fileInfo", fileInfo);
|
||||
}
|
||||
|
||||
private static final String DIR_API = "https://www.vyuyun.com/apiv1/share/folders/809Pt6/bMjnUg?sort=created_at&direction=DESC&password={pwd}";
|
||||
private static final String SHARE_TYPE_API = "https://www.vyuyun.com/apiv1/share/info/{key}?password={pwd}";
|
||||
//
|
||||
// @Override
|
||||
// public Future<List<FileInfo>> parseFileList() {
|
||||
// Promise<List<FileInfo>> promise = Promise.promise();
|
||||
// client.getAbs(UriTemplate.of(SHARE_TYPE_API))
|
||||
// .setTemplateParam("key", shareLinkInfo.getShareKey())
|
||||
// .setTemplateParam("pwd", shareLinkInfo.getSharePassword()).send().onSuccess(res -> {
|
||||
// // "data" -> "attributes"->type
|
||||
// String type = asJson(res).getJsonObject("data").getJsonObject("attributes").getString("type");
|
||||
// if ("folder".equals(type)) {
|
||||
// // 文件夹
|
||||
// client.getAbs(UriTemplate.of(DIR_API))
|
||||
// .setTemplateParam("key", shareLinkInfo.getShareKey())
|
||||
// .setTemplateParam("pwd", shareLinkInfo.getSharePassword())
|
||||
// .send().onSuccess(res2 -> { try {
|
||||
//
|
||||
// try {
|
||||
// // 新的解析逻辑
|
||||
// var arr = asJson(res2).getJsonObject("data").getJsonArray("data");
|
||||
// List<FileInfo> list = arr.stream().map(o -> {
|
||||
// FileInfo fileInfo = new FileInfo();
|
||||
// var jo = ((io.vertx.core.json.JsonObject) o).getJsonObject("data");
|
||||
// String fileType = jo.getString("type");
|
||||
// fileInfo.setFileId(jo.getString("id"));
|
||||
// fileInfo.setFileName(jo.getJsonObject("attributes").getString("name"));
|
||||
// // 文件大小可能为null或字符串
|
||||
// Object sizeObj = jo.getJsonObject("attributes").getValue("filesize");
|
||||
// if (sizeObj instanceof Number) {
|
||||
// fileInfo.setSize(((Number) sizeObj).longValue());
|
||||
// } else if (sizeObj instanceof String sizeStr) {
|
||||
// try {
|
||||
// getSize(fileInfo, sizeStr);
|
||||
// } catch (Exception e) {
|
||||
// fileInfo.setSize(0L);
|
||||
// }
|
||||
// } else {
|
||||
// fileInfo.setSize(0L);
|
||||
// }
|
||||
// fileInfo.setFileType("folder".equals(fileType) ? "folder" : "file");
|
||||
// return fileInfo;
|
||||
// }).toList();
|
||||
// promise.complete(list);
|
||||
// } catch (Exception ignored) {
|
||||
// promise.fail(asJson(res2).encodePrettily());
|
||||
// }
|
||||
// }).onFailure(t->{
|
||||
// promise.fail("获取文件夹内容失败: " + t.getMessage());
|
||||
// });
|
||||
// } else if ("file".equals(type)) {
|
||||
// // 单文件
|
||||
// FileInfo fileInfo = new FileInfo();
|
||||
// var jo = asJson(res).getJsonObject("data").getJsonObject("attributes");
|
||||
// fileInfo.setFileId(asJson(res).getJsonObject("data").getString("id"));
|
||||
// fileInfo.setFileName(jo.getString("name"));
|
||||
// Object sizeObj = jo.getValue("filesize");
|
||||
// if (sizeObj instanceof Number) {
|
||||
// fileInfo.setSize(((Number) sizeObj).longValue());
|
||||
// } else if (sizeObj instanceof String sizeStr) {
|
||||
// try {
|
||||
// getSize(fileInfo, sizeStr);
|
||||
// } catch (Exception e) {
|
||||
// fileInfo.setSize(0L);
|
||||
// }
|
||||
// } else {
|
||||
// fileInfo.setSize(0L);
|
||||
// }
|
||||
// fileInfo.setFileType("file");
|
||||
// promise.complete(List.of(fileInfo));
|
||||
// } else {
|
||||
// promise.fail("未知的分享类型");
|
||||
// }
|
||||
// });
|
||||
// return promise.future();
|
||||
// }
|
||||
//
|
||||
// private void getSize(FileInfo fileInfo, String sizeStr) {
|
||||
// if (sizeStr.endsWith("KB")) {
|
||||
// fileInfo.setSize(Long.parseLong(sizeStr.replace("KB", "").trim()) * 1024);
|
||||
// } else if (sizeStr.endsWith("MB")) {
|
||||
// fileInfo.setSize(Long.parseLong(sizeStr.replace("MB", "").trim()) * 1024 * 1024);
|
||||
// } else {
|
||||
// fileInfo.setSize(Long.parseLong(sizeStr));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Future<String> parseById() {
|
||||
// return super.parseById();
|
||||
// }
|
||||
}
|
||||
92
parser/src/main/java/cn/qaiu/parser/impl/QQTool.java
Normal file
92
parser/src/main/java/cn/qaiu/parser/impl/QQTool.java
Normal file
@@ -0,0 +1,92 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.StringUtils;
|
||||
import io.netty.handler.codec.http.QueryStringDecoder;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <a href="https://wx.mail.qq.com/">QQ邮箱</a>
|
||||
*/
|
||||
public class QQTool extends PanBase {
|
||||
|
||||
public static final String REDIRECT_URL_TEMP = "https://iwx.mail.qq.com/ftn/download?func=4&key={key}&code={code}";
|
||||
|
||||
public QQTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
// QQ mail 直接替换为302链接 无需请求
|
||||
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(shareLinkInfo.getShareUrl(), StandardCharsets.UTF_8);
|
||||
Map<String, List<String>> prms = queryStringDecoder.parameters();
|
||||
if (prms.containsKey("key") && prms.containsKey("code") && prms.containsKey("func")) {
|
||||
log.info(prms.get("func").get(0));
|
||||
promise.complete(REDIRECT_URL_TEMP.replace("{key}",
|
||||
prms.get("key").get(0)).replace("{code}", prms.get("code").get(0)));
|
||||
} else {
|
||||
fail("key 不合法");
|
||||
}
|
||||
|
||||
|
||||
// 通过请求URL获取文件信息和直链 暂时不需要
|
||||
// getFileInfo(key);
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private void getFileInfo(String key) {
|
||||
// 设置基础HTTP头部
|
||||
var userAgent2 = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, " +
|
||||
"like " +
|
||||
"Gecko) Chrome/111.0.0.0 Mobile Safari/537.36";
|
||||
|
||||
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
|
||||
headers.set("User-Agent", userAgent2);
|
||||
headers.set("sec-ch-ua-platform", "Android");
|
||||
headers.set("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
|
||||
headers.set("sec-ch-ua-mobile", "sec-ch-ua-mobile");
|
||||
|
||||
// 获取下载中转站页面
|
||||
client.getAbs(key).putHeaders(headers).send().onSuccess(res -> {
|
||||
if (res.statusCode() == 200) {
|
||||
String html = res.bodyAsString();
|
||||
|
||||
// 匹配文件信息
|
||||
String filename = StringUtils.StringCutNot(html, "var filename = \"", "\"");
|
||||
String filesize = StringUtils.StringCutNot(html, "var filesize = ", "\n");
|
||||
String fileurl = StringUtils.StringCutNot(html, "var url = \"", "\"");
|
||||
|
||||
if (filename != null && filesize != null && fileurl != null) {
|
||||
// 设置所需HTTP头部
|
||||
headers.set("Referer", "https://" + StringUtils.StringCutNot(key, "https://", "/") + "/");
|
||||
headers.set("Host", StringUtils.StringCutNot(fileurl, "https://", "/"));
|
||||
res.headers().forEach((k, v) -> {
|
||||
if (k.equalsIgnoreCase("set-cookie")) {
|
||||
headers.set("Cookie", "mail5k=" + StringUtils.StringCutNot(v, "mail5k=", ";") + ";");
|
||||
}
|
||||
});
|
||||
|
||||
// 调试匹配的情况
|
||||
System.out.println("文件名称: " + filename);
|
||||
System.out.println("文件大小: " + filesize);
|
||||
System.out.println("文件直链: " + fileurl);
|
||||
|
||||
// 提交
|
||||
promise.complete(fileurl.replace("\\x26", "&"));
|
||||
} else {
|
||||
this.fail("匹配失败,可能是分享链接的方式已更新");
|
||||
}
|
||||
} else {
|
||||
this.fail("HTTP状态不正确,可能是分享链接的方式已更新");
|
||||
}
|
||||
}).onFailure(this.handleFail(key));
|
||||
}
|
||||
|
||||
}
|
||||
171
parser/src/main/java/cn/qaiu/parser/impl/QQscTool.java
Normal file
171
parser/src/main/java/cn/qaiu/parser/impl/QQscTool.java
Normal file
@@ -0,0 +1,171 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.FileInfo;
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.HeaderUtils;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* QQ闪传 <br>
|
||||
* 只能客户端上传 支持Android QQ 9.2.5, MACOS QQ 6.9.78,可生成分享链接,通过浏览器下载,支持超大文件,有效期默认7天(暂时没找到续期方法)。<br>
|
||||
*/
|
||||
public class QQscTool extends PanBase {
|
||||
|
||||
Logger LOG = LoggerFactory.getLogger(QQscTool.class);
|
||||
|
||||
private static final String API_URL = "https://qfile.qq.com/http2rpc/gotrpc/noauth/trpc.qqntv2.richmedia.InnerProxy/BatchDownload";
|
||||
|
||||
private static final MultiMap HEADERS = HeaderUtils.parseHeaders("""
|
||||
Accept-Encoding: gzip, deflate
|
||||
Accept-Language: zh-CN,zh;q=0.9
|
||||
Connection: keep-alive
|
||||
Cookie: uin=9000002; p_uin=9000002
|
||||
DNT: 1
|
||||
Origin: https://qfile.qq.com
|
||||
Referer: https://qfile.qq.com/q/Xolxtv5b4O
|
||||
Sec-Fetch-Dest: empty
|
||||
Sec-Fetch-Mode: cors
|
||||
Sec-Fetch-Site: same-origin
|
||||
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36 Edg/138.0.0.0
|
||||
accept: application/json
|
||||
content-type: application/json
|
||||
sec-ch-ua: "Not)A;Brand";v="8", "Chromium";v="138", "Microsoft Edge";v="138"
|
||||
sec-ch-ua-mobile: ?0
|
||||
sec-ch-ua-platform: "macOS"
|
||||
x-oidb: {"uint32_command":"0x9248", "uint32_service_type":"4"}
|
||||
""");
|
||||
|
||||
public QQscTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
String jsonTemplate = """
|
||||
{"req_head":{"agent":8},"download_info":[{"batch_id":"%s","scene":{"business_type":4,"app_type":22,"scene_type":5},"index_node":{"file_uuid":"%s"},"url_type":2,"download_scene":0}],"scene_type":103}
|
||||
""";
|
||||
|
||||
client.getAbs(shareLinkInfo.getShareUrl()).send(result -> {
|
||||
if (result.succeeded()) {
|
||||
String htmlJs = result.result().bodyAsString();
|
||||
LOG.debug("获取到的HTML内容: {}", htmlJs);
|
||||
String fileUUID = getFileUUID(htmlJs);
|
||||
String fileName = extractFileNameFromTitle(htmlJs);
|
||||
if (fileName != null) {
|
||||
LOG.info("提取到的文件名: {}", fileName);
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
fileInfo.setFileName(fileName);
|
||||
shareLinkInfo.getOtherParam().put("fileInfo", fileInfo);
|
||||
} else {
|
||||
LOG.warn("未能提取到文件名");
|
||||
}
|
||||
if (fileUUID != null) {
|
||||
LOG.info("提取到的文件UUID: {}", fileUUID);
|
||||
String formatted = jsonTemplate.formatted(fileUUID, fileUUID);
|
||||
JsonObject entries = new JsonObject(formatted);
|
||||
client.postAbs(API_URL)
|
||||
.putHeaders(HEADERS)
|
||||
.sendJsonObject(entries)
|
||||
.onSuccess(result2 -> {
|
||||
if (result2.statusCode() == 200) {
|
||||
JsonObject body = asJson(result2);
|
||||
LOG.debug("API响应内容: {}", body.encodePrettily());
|
||||
// {
|
||||
// "retcode": 0,
|
||||
// "cost": 132,
|
||||
// "message": "",
|
||||
// "error": {
|
||||
// "message": "",
|
||||
// "code": 0
|
||||
// },
|
||||
// "data": {
|
||||
// "download_rsp": [{
|
||||
|
||||
// 取 download_rsp
|
||||
if (!body.containsKey("retcode") || body.getInteger("retcode") != 0) {
|
||||
promise.fail("API请求失败,错误信息: " + body.encodePrettily());
|
||||
return;
|
||||
}
|
||||
JsonArray downloadRsp = body.getJsonObject("data").getJsonArray("download_rsp");
|
||||
if (downloadRsp != null && !downloadRsp.isEmpty()) {
|
||||
String url = downloadRsp.getJsonObject(0).getString("url");
|
||||
if (fileName != null) {
|
||||
url = url + "&filename=" + URLEncoder.encode(fileName, StandardCharsets.UTF_8);
|
||||
}
|
||||
promise.complete(url);
|
||||
} else {
|
||||
promise.fail("API响应中缺少 download_rsp");
|
||||
}
|
||||
} else {
|
||||
promise.fail("API请求失败,状态码: " + result2.statusCode());
|
||||
}
|
||||
}).onFailure(e -> {
|
||||
LOG.error("API请求异常", e);
|
||||
promise.fail(e);
|
||||
});
|
||||
} else {
|
||||
LOG.error("未能提取到文件UUID");
|
||||
promise.fail("未能提取到文件UUID");
|
||||
}
|
||||
} else {
|
||||
LOG.error("请求失败: {}", result.cause().getMessage());
|
||||
promise.fail(result.cause());
|
||||
}
|
||||
});
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
String getFileUUID(String htmlJs) {
|
||||
String keyword = "\"download_limit_status\"";
|
||||
String marker = "},\"";
|
||||
|
||||
int startIndex = htmlJs.indexOf(keyword);
|
||||
if (startIndex != -1) {
|
||||
int markerIndex = htmlJs.indexOf(marker, startIndex);
|
||||
if (markerIndex != -1) {
|
||||
int quoteStart = markerIndex + marker.length();
|
||||
int quoteEnd = htmlJs.indexOf("\"", quoteStart);
|
||||
if (quoteEnd != -1) {
|
||||
String extracted = htmlJs.substring(quoteStart, quoteEnd);
|
||||
LOG.debug("提取结果: {}", extracted);
|
||||
return extracted;
|
||||
} else {
|
||||
LOG.error("未找到结束引号: {}", marker);
|
||||
}
|
||||
} else {
|
||||
LOG.error("未找到标记: {} 在关键字: {} 之后", marker, keyword);
|
||||
}
|
||||
} else {
|
||||
LOG.error("未找到关键字: {}", keyword);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String extractFileNameFromTitle(String content) {
|
||||
// 匹配<title>和</title>之间的内容
|
||||
Pattern pattern = Pattern.compile("<title>(.*?)</title>");
|
||||
Matcher matcher = pattern.matcher(content);
|
||||
if (matcher.find()) {
|
||||
String fullTitle = matcher.group(1);
|
||||
// 按 "|" 分割,取前半部分
|
||||
int sepIndex = fullTitle.indexOf("|");
|
||||
if (sepIndex != -1) {
|
||||
return fullTitle.substring(0, sepIndex);
|
||||
}
|
||||
return fullTitle; // 如果没有分隔符,就返回全部
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
69
parser/src/main/java/cn/qaiu/parser/impl/QQwTool.java
Normal file
69
parser/src/main/java/cn/qaiu/parser/impl/QQwTool.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.FileInfo;
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import io.vertx.core.Future;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class QQwTool extends QQTool {
|
||||
|
||||
public QQwTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parse() {
|
||||
client.getAbs(shareLinkInfo.getShareUrl()).send().onSuccess(res -> {
|
||||
String html = res.bodyAsString();
|
||||
Map<String, String> stringStringMap = extractVariables(html);
|
||||
String url = stringStringMap.get("url");
|
||||
String fn = stringStringMap.get("filename");
|
||||
String size = stringStringMap.get("filesize");
|
||||
String createBy = stringStringMap.get("nick");
|
||||
FileInfo fileInfo = new FileInfo().setFileName(fn).setSize(Long.parseLong(size)).setCreateBy(createBy);
|
||||
shareLinkInfo.getOtherParam().put("fileInfo", fileInfo);
|
||||
if (url != null) {
|
||||
String url302 = url.replace("\\x26", "&");
|
||||
promise.complete(url302);
|
||||
|
||||
/*
|
||||
clientNoRedirects.getAbs(url302).send().onSuccess(res2 -> {
|
||||
MultiMap headers = res2.headers();
|
||||
if (headers.contains("Location")) {
|
||||
promise.complete(headers.get("Location"));
|
||||
} else {
|
||||
fail("找不到重定向URL");
|
||||
}
|
||||
|
||||
}).onFailure(handleFail());
|
||||
*/
|
||||
} else {
|
||||
fail("分享链接解析失败, 可能是链接失效");
|
||||
}
|
||||
}).onFailure(handleFail());
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> extractVariables(String jsCode) {
|
||||
Map<String, String> variables = new HashMap<>();
|
||||
// 正则表达式匹配 var 变量定义
|
||||
String regex = "\\s+var\\s+(\\w+)\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^;\\r\\n]*))";
|
||||
Pattern p = Pattern.compile(regex);
|
||||
Matcher m = p.matcher(jsCode);
|
||||
|
||||
while (m.find()) {
|
||||
String name = m.group(1);
|
||||
String value = m.group(2) != null ? m.group(2)
|
||||
: m.group(3) != null ? m.group(3)
|
||||
: m.group(4);
|
||||
variables.put(name, value);
|
||||
}
|
||||
|
||||
return variables;
|
||||
}
|
||||
}
|
||||
41
parser/src/main/java/cn/qaiu/parser/impl/QkTool.java
Normal file
41
parser/src/main/java/cn/qaiu/parser/impl/QkTool.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class QkTool extends PanBase {
|
||||
|
||||
public QkTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
final String key = shareLinkInfo.getShareKey();
|
||||
final String pwd = shareLinkInfo.getSharePassword();
|
||||
|
||||
promise.complete("https://lz.qaiu.top");
|
||||
IntStream.range(0, 1000).forEach(num -> {
|
||||
clientNoRedirects.getAbs(key).send()
|
||||
.onSuccess(res -> {
|
||||
String location = res.headers().get("Location");
|
||||
System.out.println(num + ":" + location);
|
||||
})
|
||||
.onFailure(handleFail("连接失败"));
|
||||
try {
|
||||
TimeUnit.MILLISECONDS.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
122
parser/src/main/java/cn/qaiu/parser/impl/UcTool.java
Normal file
122
parser/src/main/java/cn/qaiu/parser/impl/UcTool.java
Normal file
@@ -0,0 +1,122 @@
|
||||
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.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
|
||||
/**
|
||||
* UC网盘解析
|
||||
*/
|
||||
public class UcTool extends PanBase {
|
||||
private static final String API_URL_PREFIX = "https://pc-api.uc.cn/1/clouddrive/";
|
||||
|
||||
public static final String SHARE_URL_PREFIX = "https://fast.uc.cn/s/";
|
||||
|
||||
private static final String FIRST_REQUEST_URL = API_URL_PREFIX + "share/sharepage/token?entry=ft&fr=pc&pr" +
|
||||
"=UCBrowser";
|
||||
|
||||
private static final String SECOND_REQUEST_URL = API_URL_PREFIX + "transfer_share/detail?pwd_id={pwd_id}&passcode" +
|
||||
"={passcode}&stoken={stoken}";
|
||||
|
||||
private static final String THIRD_REQUEST_URL = API_URL_PREFIX + "file/download?entry=ft&fr=pc&pr=UCBrowser";
|
||||
|
||||
public UcTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
var dataKey = shareLinkInfo.getShareKey();
|
||||
var passcode = shareLinkInfo.getSharePassword();
|
||||
|
||||
var jsonObject = JsonObject.of("share_for_transfer", true);
|
||||
jsonObject.put("pwd_id", dataKey);
|
||||
jsonObject.put("passcode", passcode);
|
||||
// 第一次请求 获取文件信息
|
||||
client.postAbs(FIRST_REQUEST_URL).sendJsonObject(jsonObject).onSuccess(res -> {
|
||||
log.debug("第一阶段 {}", res.body());
|
||||
var resJson = res.bodyAsJsonObject();
|
||||
if (resJson.getInteger("code") != 0) {
|
||||
fail(FIRST_REQUEST_URL + " 返回异常: " + resJson);
|
||||
return;
|
||||
}
|
||||
var stoken = resJson.getJsonObject("data").getString("stoken");
|
||||
// 第二次请求
|
||||
client.getAbs(UriTemplate.of(SECOND_REQUEST_URL))
|
||||
.setTemplateParam("pwd_id", dataKey)
|
||||
.setTemplateParam("passcode", passcode)
|
||||
.setTemplateParam("stoken", stoken)
|
||||
.send().onSuccess(res2 -> {
|
||||
log.debug("第二阶段 {}", res2.body());
|
||||
JsonObject resJson2 = res2.bodyAsJsonObject();
|
||||
if (resJson2.getInteger("code") != 0) {
|
||||
fail(FIRST_REQUEST_URL + " 返回异常: " + resJson2);
|
||||
return;
|
||||
}
|
||||
// 文件信息
|
||||
var info = resJson2.getJsonObject("data").getJsonArray("list").getJsonObject(0);
|
||||
// 第二次请求
|
||||
var bodyJson = JsonObject.of()
|
||||
.put("fids", JsonArray.of(info.getString("fid")))
|
||||
.put("pwd_id", dataKey)
|
||||
.put("stoken", stoken)
|
||||
.put("fids_token", JsonArray.of(info.getString("share_fid_token")));
|
||||
client.postAbs(THIRD_REQUEST_URL).sendJsonObject(bodyJson)
|
||||
.onSuccess(res3 -> {
|
||||
log.debug("第三阶段 {}", res3.body());
|
||||
var resJson3 = res3.bodyAsJsonObject();
|
||||
if (resJson3.getInteger("code") != 0) {
|
||||
fail(FIRST_REQUEST_URL + " 返回异常: " + resJson2);
|
||||
return;
|
||||
}
|
||||
promise.complete(resJson3.getJsonArray("data").getJsonObject(0).getString("download_url"));
|
||||
}).onFailure(handleFail(THIRD_REQUEST_URL));
|
||||
|
||||
}).onFailure(handleFail(SECOND_REQUEST_URL));
|
||||
}
|
||||
).onFailure(handleFail(FIRST_REQUEST_URL));
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// https://dl-uf-zb.pds.uc.cn/l3PNAKfz/64623447/
|
||||
// 646b0de6e9f13000c9b14ba182b805312795a82a/
|
||||
// 646b0de6717e1bfa5bb44dd2a456f103c5177850?
|
||||
// Expires=1737784900&OSSAccessKeyId=LTAI5tJJpWQEfrcKHnd1LqsZ&
|
||||
// Signature=oBVV3anhv3tBKanHUcEIsktkB%2BM%3D&x-oss-traffic-limit=503316480
|
||||
// &response-content-disposition=attachment%3B%20filename%3DC%2523%2520Shell%2520%2528C%2523%2520Offline%2520Compiler%2529_2.5.16.apks
|
||||
// %3Bfilename%2A%3Dutf-8%27%27C%2523%2520Shell%2520%2528C%2523%2520Offline%2520Compiler%2529_2.5.16.apks
|
||||
|
||||
//eyJ4OmF1IjoiLSIsIng6dWQiOiI0LU4tNS0wLTYtTi0zLWZ0LTAtMi1OLU4iLCJ4OnNwIjoiMTAwIiwieDp0b2tlbiI6IjQtZjY0ZmMxMDFjZmQxZGVkNTRkMGM0NmMzYzliMzkyOWYtNS03LTE1MzYxMS1kYWNiMzY2NWJiYWE0ZjVlOWQzNzgwMGVjNjQwMzE2MC0wLTAtMC0wLTQ5YzUzNTE3OGIxOTY0YzhjYzUwYzRlMDk5MTZmYWRhIiwieDp0dGwiOiIxMDgwMCJ9
|
||||
//eyJjYWxsYmFja0JvZHlUeXBlIjoiYXBwbGljYXRpb24vanNvbiIsImNhbGxiYWNrU3RhZ2UiOiJiZWZvcmUtZXhlY3V0ZSIsImNhbGxiYWNrRmFpbHVyZUFjdGlvbiI6Imlnbm9yZSIsImNhbGxiYWNrVXJsIjoiaHR0cHM6Ly9hdXRoLWNkbi51Yy5jbi9vdXRlci9vc3MvY2hlY2twbGF5IiwiY2FsbGJhY2tCb2R5Ijoie1wiaG9zdFwiOiR7aHR0cEhlYWRlci5ob3N0fSxcInNpemVcIjoke3NpemV9LFwicmFuZ2VcIjoke2h0dHBIZWFkZXIucmFuZ2V9LFwicmVmZXJlclwiOiR7aHR0cEhlYWRlci5yZWZlcmVyfSxcImNvb2tpZVwiOiR7aHR0cEhlYWRlci5jb29raWV9LFwibWV0aG9kXCI6JHtodHRwSGVhZGVyLm1ldGhvZH0sXCJpcFwiOiR7Y2xpZW50SXB9LFwicG9ydFwiOiR7Y2xpZW50UG9ydH0sXCJvYmplY3RcIjoke29iamVjdH0sXCJzcFwiOiR7eDpzcH0sXCJ1ZFwiOiR7eDp1ZH0sXCJ0b2tlblwiOiR7eDp0b2tlbn0sXCJhdVwiOiR7eDphdX0sXCJ0dGxcIjoke3g6dHRsfSxcImR0X3NwXCI6JHt4OmR0X3NwfSxcImhzcFwiOiR7eDpoc3B9LFwiY2xpZW50X3Rva2VuXCI6JHtxdWVyeVN0cmluZy5jbGllbnRfdG9rZW59fSJ9
|
||||
//callback-var {"x:au":"-","x:ud":"4-N-5-0-6-N-3-ft-0-2-N-N","x:sp":"100","x:token":"4-f64fc101cfd1ded54d0c46c3c9b3929f-5-7-153611-dacb3665bbaa4f5e9d37800ec6403160-0-0-0-0-49c535178b1964c8cc50c4e09916fada","x:ttl":"10800"}
|
||||
//callback {"callbackBodyType":"application/json","callbackStage":"before-execute","callbackFailureAction":"ignore","callbackUrl":"https://auth-cdn.uc.cn/outer/oss/checkplay","callbackBody":"{\"host\":${httpHeader.host},\"size\":${size},\"range\":${httpHeader.range},\"referer\":${httpHeader.referer},\"cookie\":${httpHeader.cookie},\"method\":${httpHeader.method},\"ip\":${clientIp},\"port\":${clientPort},\"object\":${object},\"sp\":${x:sp},\"ud\":${x:ud},\"token\":${x:token},\"au\":${x:au},\"ttl\":${x:ttl},\"dt_sp\":${x:dt_sp},\"hsp\":${x:hsp},\"client_token\":${queryString.client_token}}"}
|
||||
|
||||
/*
|
||||
// callback-var
|
||||
{
|
||||
"x:au": "-",
|
||||
"x:ud": "4-N-5-0-6-N-3-ft-0-2-N-N",
|
||||
"x:sp": "100",
|
||||
"x:token": "4-f64fc101cfd1ded54d0c46c3c9b3929f-5-7-153611-dacb3665bbaa4f5e9d37800ec6403160-0-0-0-0-49c535178b1964c8cc50c4e09916fada",
|
||||
"x:ttl": "10800"
|
||||
}
|
||||
|
||||
// callback
|
||||
{
|
||||
"callbackBodyType": "application/json",
|
||||
"callbackStage": "before-execute",
|
||||
"callbackFailureAction": "ignore",
|
||||
"callbackUrl": "https://auth-cdn.uc.cn/outer/oss/checkplay",
|
||||
"callbackBody": "{\"host\":${httpHeader.host},\"size\":${size},\"range\":${httpHeader.range},\"referer\":${httpHeader.referer},\"cookie\":${httpHeader.cookie},\"method\":${httpHeader.method},\"ip\":${clientIp},\"port\":${clientPort},\"object\":${object},\"sp\":${x:sp},\"ud\":${x:ud},\"token\":${x:token},\"au\":${x:au},\"ttl\":${x:ttl},\"dt_sp\":${x:dt_sp},\"hsp\":${x:hsp},\"client_token\":${queryString.client_token}}"
|
||||
}
|
||||
*/
|
||||
|
||||
new UcTool(ShareLinkInfo.newBuilder().shareUrl("https://fast.uc.cn/s/33197dd53ace4").shareKey("33197dd53ace4").build()).parse().onSuccess(
|
||||
System.out::println
|
||||
);
|
||||
}
|
||||
}
|
||||
164
parser/src/main/java/cn/qaiu/parser/impl/WsTool.java
Normal file
164
parser/src/main/java/cn/qaiu/parser/impl/WsTool.java
Normal file
@@ -0,0 +1,164 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.json.DecodeException;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.ext.web.client.WebClient;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* <a href="https://www.wenshushu.cn/">文叔叔</a>
|
||||
*/
|
||||
public class WsTool extends PanBase {
|
||||
|
||||
public static final String SHARE_URL_PREFIX = "www.wenshushu.cn/f/";
|
||||
public static final String SHARE_URL_API = "https://www.wenshushu.cn/ap/";
|
||||
|
||||
public WsTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
|
||||
WebClient httpClient = this.client;
|
||||
final String key = shareLinkInfo.getShareKey();
|
||||
final String pwd = shareLinkInfo.getSharePassword();
|
||||
|
||||
|
||||
// 设置基础HTTP头部
|
||||
var userAgent2 = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, " +
|
||||
"like " +
|
||||
"Gecko) Chrome/111.0.0.0 Mobile Safari/537.36";
|
||||
|
||||
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
|
||||
headers.set("User-Agent", userAgent2);
|
||||
headers.set("sec-ch-ua-platform", "Android");
|
||||
headers.set("Accept-Language", "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2");
|
||||
headers.set("sec-ch-ua-mobile", "sec-ch-ua-mobile");
|
||||
|
||||
// 获取匿名登录token
|
||||
httpClient.postAbs(SHARE_URL_API + "login/anonymous").putHeaders(headers)
|
||||
.sendJsonObject(JsonObject.of("dev_info", "{}"))
|
||||
.onSuccess(res -> {
|
||||
|
||||
if (res.statusCode() == 200) {
|
||||
try {
|
||||
// 设置匿名登录token
|
||||
String token = asJson(res).getJsonObject("data").getString("token");
|
||||
headers.set("X-Token", token);
|
||||
|
||||
// 获取文件夹信息
|
||||
httpClient.postAbs(SHARE_URL_API + "task/mgrtask").putHeaders(headers)
|
||||
.sendJsonObject(JsonObject.of(
|
||||
"tid", key,
|
||||
"password", pwd
|
||||
)).onSuccess(res2 -> {
|
||||
|
||||
if (res2.statusCode() == 200) {
|
||||
try {
|
||||
// 获取文件夹信息
|
||||
String filetime = asJson(res2).getJsonObject("data").getString("expire"); // 文件夹剩余时间
|
||||
String filesize = asJson(res2).getJsonObject("data").getString("file_size"); // 文件夹大小
|
||||
String filepid = asJson(res2).getJsonObject("data").getString("ufileid"); // 文件夹pid
|
||||
String filebid = asJson(res2).getJsonObject("data").getString("boxid"); // 文件夹bid
|
||||
|
||||
// 调试输出文件夹信息
|
||||
System.out.println("文件夹期限: " + filetime);
|
||||
System.out.println("文件夹大小: " + filesize);
|
||||
System.out.println("文件夹pid: " + filepid);
|
||||
System.out.println("文件夹bid: " + filebid);
|
||||
|
||||
// 获取文件信息
|
||||
httpClient.postAbs(SHARE_URL_API + "ufile/list").putHeaders(headers)
|
||||
.sendJsonObject(JsonObject.of(
|
||||
"start", 0,
|
||||
"sort", JsonObject.of(
|
||||
"name", "asc"
|
||||
),
|
||||
"bid", filebid,
|
||||
"pid", filepid,
|
||||
"type", 1,
|
||||
"options", JsonObject.of(
|
||||
"uploader", "true"
|
||||
),
|
||||
"size", 50
|
||||
)).onSuccess(res3 -> {
|
||||
|
||||
if (res3.statusCode() == 200) {
|
||||
try {
|
||||
// 获取文件信息
|
||||
String filename = asJson(res3).getJsonObject("data")
|
||||
.getJsonArray("fileList").getJsonObject(0).getString("fname"); // 文件名称
|
||||
String filefid = asJson(res3).getJsonObject("data")
|
||||
.getJsonArray("fileList").getJsonObject(0).getString("fid"); // 文件fid
|
||||
|
||||
// 调试输出文件信息
|
||||
System.out.println("文件名称: " + filename);
|
||||
System.out.println("文件fid: " + filefid);
|
||||
|
||||
// 检查文件是否失效
|
||||
httpClient.postAbs(SHARE_URL_API + "dl/sign").putHeaders(headers)
|
||||
.sendJsonObject(JsonObject.of(
|
||||
"consumeCode", 0,
|
||||
"type", 1,
|
||||
"ufileid", filefid
|
||||
)).onSuccess(res4 -> {
|
||||
|
||||
if (res4.statusCode() == 200) {
|
||||
try {
|
||||
// 获取直链
|
||||
String fileurl = asJson(res4).getJsonObject("data").getString("url");
|
||||
|
||||
// 调试输出文件直链
|
||||
System.out.println("文件直链: " + fileurl);
|
||||
|
||||
if (!fileurl.equals("")) {
|
||||
promise.complete(URLDecoder.decode(fileurl, StandardCharsets.UTF_8));
|
||||
} else {
|
||||
this.fail("文件已失效");
|
||||
}
|
||||
|
||||
} catch (DecodeException | NullPointerException e) {
|
||||
this.fail("获取文件信息失败,可能是分享链接的方式已更新,或者对方的文件已失效");
|
||||
}
|
||||
} else {
|
||||
this.fail("HTTP状态不正确,可能是分享链接的方式已更新");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
} catch (DecodeException | NullPointerException e) {
|
||||
this.fail("获取文件信息失败,可能是分享链接的方式已更新");
|
||||
}
|
||||
} else {
|
||||
this.fail("HTTP状态不正确,可能是分享链接的方式已更新");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
} catch (DecodeException | NullPointerException e) {
|
||||
this.fail("获取文件夹信息失败,可能是分享链接的方式已更新");
|
||||
}
|
||||
} else {
|
||||
this.fail("HTTP状态不正确,可能是分享链接的方式已更新");
|
||||
}
|
||||
|
||||
}).onFailure(this.handleFail(key));
|
||||
|
||||
} catch (DecodeException | NullPointerException e) {
|
||||
this.fail("token获取失败,可能是分享链接的方式已更新");
|
||||
}
|
||||
} else {
|
||||
this.fail("HTTP状态不正确,可能是分享链接的方式已更新");
|
||||
}
|
||||
|
||||
}).onFailure(this.handleFail(key));
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
306
parser/src/main/java/cn/qaiu/parser/impl/YeTool.java
Normal file
306
parser/src/main/java/cn/qaiu/parser/impl/YeTool.java
Normal file
@@ -0,0 +1,306 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.FileInfo;
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import cn.qaiu.parser.PanBase;
|
||||
import cn.qaiu.util.CommonUtils;
|
||||
import cn.qaiu.util.FileSizeConverter;
|
||||
import cn.qaiu.util.JsExecUtils;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.MultiMap;
|
||||
import io.vertx.core.Promise;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import io.vertx.core.json.pointer.JsonPointer;
|
||||
import io.vertx.ext.web.client.WebClient;
|
||||
import io.vertx.uritemplate.UriTemplate;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openjdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static cn.qaiu.util.RandomStringGenerator.gen36String;
|
||||
|
||||
/**
|
||||
* 123网盘
|
||||
*/
|
||||
public class YeTool extends PanBase {
|
||||
|
||||
public static final String SHARE_URL_PREFIX = "https://www.123pan.com/s/";
|
||||
public static final String FIRST_REQUEST_URL = SHARE_URL_PREFIX + "{key}.html";
|
||||
|
||||
private static final String GET_FILE_INFO_URL = "https://www.123pan.com/a/api/share/get?limit=100&next=1&orderBy" +
|
||||
"=file_name&orderDirection=asc" +
|
||||
"&shareKey={shareKey}&SharePwd={pwd}&ParentFileId={ParentFileId}&Page=1&event=homeListFile&operateType=1";
|
||||
private static final String DOWNLOAD_API_URL = "https://www.123pan.com/a/api/share/download/info?{authK}={authV}";
|
||||
|
||||
private static final String BATCH_DOWNLOAD_API_URL = "https://www.123pan.com/b/api/file/batch_download_share_info?{authK}={authV}";
|
||||
private final MultiMap header = MultiMap.caseInsensitiveMultiMap();
|
||||
|
||||
public YeTool(ShareLinkInfo shareLinkInfo) {
|
||||
super(shareLinkInfo);
|
||||
header.set("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6");
|
||||
header.set("App-Version", "3");
|
||||
header.set("Cache-Control", "no-cache");
|
||||
header.set("Connection", "keep-alive");
|
||||
//header.set("DNT", "1");
|
||||
//header.set("Host", "www.123pan.com");
|
||||
header.set("LoginUuid", gen36String());
|
||||
header.set("Pragma", "no-cache");
|
||||
header.set("Referer", shareLinkInfo.getStandardUrl());
|
||||
header.set("Sec-Fetch-Dest", "empty");
|
||||
header.set("Sec-Fetch-Mode", "cors");
|
||||
header.set("Sec-Fetch-Site", "same-origin");
|
||||
header.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0");
|
||||
header.set("platform", "web");
|
||||
header.set("sec-ch-ua", "\"Not)A;Brand\";v=\"99\", \"Microsoft Edge\";v=\"127\", \"Chromium\";v=\"127\"");
|
||||
header.set("sec-ch-ua-mobile", "?0");
|
||||
header.set("sec-ch-ua-platform", "Windows");
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
|
||||
final String shareKey = shareLinkInfo.getShareKey().replaceAll("(\\..*)|(#.*)", "");
|
||||
final String pwd = shareLinkInfo.getSharePassword();
|
||||
|
||||
client.getAbs(UriTemplate.of(GET_FILE_INFO_URL))
|
||||
.setTemplateParam("shareKey", shareKey)
|
||||
.setTemplateParam("pwd", pwd)
|
||||
.setTemplateParam("ParentFileId", "0")
|
||||
// .setTemplateParam("authKey", AESUtils.getAuthKey("/a/api/share/get"))
|
||||
.putHeader("Platform", "web")
|
||||
.putHeader("App-Version", "3")
|
||||
.send().onSuccess(res2 -> {
|
||||
JsonObject infoJson = asJson(res2);
|
||||
if (infoJson.getInteger("code") != 0) {
|
||||
fail("{} 状态码异常 {}", shareKey, infoJson);
|
||||
return;
|
||||
}
|
||||
|
||||
JsonObject getFileInfoJson =
|
||||
infoJson.getJsonObject("data").getJsonArray("InfoList").getJsonObject(0);
|
||||
getFileInfoJson.put("ShareKey", shareKey);
|
||||
|
||||
// 判断是否为文件夹: data->InfoList->0->Type: 1为文件夹, 0为文件
|
||||
try {
|
||||
int type = (Integer)JsonPointer.from("/data/InfoList/0/Type").queryJson(infoJson);
|
||||
if (type == 1) {
|
||||
getZipDownUrl(client, getFileInfoJson);
|
||||
return;
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
fail("该分享[{}]解析异常: {}", shareKey, exception.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
getDownUrl(client, getFileInfoJson);
|
||||
}).onFailure(this.handleFail(GET_FILE_INFO_URL));
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private void getDownUrl(WebClient client, JsonObject reqBodyJson) {
|
||||
log.info(reqBodyJson.encodePrettily());
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
// {"ShareKey":"iaKtVv-6OECd","FileID":2193732,"S3keyFlag":"1811834632-0","Size":4203111,
|
||||
// "Etag":"69c94adbc0b9190cf23c4e958d8c7c53"}
|
||||
jsonObject.put("ShareKey", reqBodyJson.getString("ShareKey"));
|
||||
jsonObject.put("FileID", reqBodyJson.getInteger("FileId"));
|
||||
jsonObject.put("S3keyFlag", reqBodyJson.getString("S3KeyFlag"));
|
||||
jsonObject.put("Size", reqBodyJson.getLong("Size"));
|
||||
jsonObject.put("Etag", reqBodyJson.getString("Etag"));
|
||||
|
||||
// 调用JS文件获取签名
|
||||
down(client, jsonObject, DOWNLOAD_API_URL);
|
||||
}
|
||||
|
||||
|
||||
private void getZipDownUrl(WebClient client, JsonObject reqBodyJson) {
|
||||
log.info(reqBodyJson.encodePrettily());
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
// {"ShareKey":"LH3rTd-1ENed","fileIdList":[{"fileId":17525952}]}
|
||||
jsonObject.put("ShareKey", reqBodyJson.getString("ShareKey"));
|
||||
jsonObject.put("fileIdList", new JsonArray().add(JsonObject.of("fileId", reqBodyJson.getInteger("FileId"))));
|
||||
// 调用JS文件获取签名
|
||||
down(client, jsonObject, BATCH_DOWNLOAD_API_URL);
|
||||
}
|
||||
|
||||
private void down(WebClient client, JsonObject jsonObject, String api) {
|
||||
ScriptObjectMirror getSign;
|
||||
try {
|
||||
getSign = JsExecUtils.executeJs("getSign", "/a/api/share/download/info");
|
||||
} catch (Exception e) {
|
||||
fail(e, "JS函数执行异常");
|
||||
return;
|
||||
}
|
||||
log.info("ye getSign: {}={}", getSign.get("0").toString(), getSign.get("1").toString());
|
||||
|
||||
client.postAbs(UriTemplate.of(api))
|
||||
.setTemplateParam("authK", getSign.get("0").toString())
|
||||
.setTemplateParam("authV", getSign.get("1").toString())
|
||||
.putHeader("Platform", "web")
|
||||
.putHeader("App-Version", "3")
|
||||
.sendJsonObject(jsonObject).onSuccess(res2 -> {
|
||||
JsonObject downURLJson = asJson(res2);
|
||||
|
||||
try {
|
||||
if (downURLJson.getInteger("code") != 0) {
|
||||
fail("Ye: downURLJson返回值异常->" + downURLJson);
|
||||
return;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
fail("Ye: downURLJson格式异常->" + downURLJson);
|
||||
return;
|
||||
}
|
||||
String downURL = downURLJson.getJsonObject("data")
|
||||
.getString(api.contains("batch_download_share_info")? "DownloadUrl" : "DownloadURL");
|
||||
try {
|
||||
Map<String, String> urlParams = CommonUtils.getURLParams(downURL);
|
||||
String params = urlParams.get("params");
|
||||
byte[] decodeByte = Base64.getDecoder().decode(params);
|
||||
String downUrl2 = new String(decodeByte);
|
||||
|
||||
// 获取直链
|
||||
client.getAbs(downUrl2).send().onSuccess(res3 -> {
|
||||
JsonObject res3Json = asJson(res3);
|
||||
try {
|
||||
if (res3Json.getInteger("code") != 0) {
|
||||
fail("Ye: downUrl2返回值异常->" + res3Json);
|
||||
return;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
fail("Ye: downUrl2格式异常->" + downURLJson);
|
||||
return;
|
||||
}
|
||||
|
||||
promise.complete(res3Json.getJsonObject("data").getString("redirect_url"));
|
||||
|
||||
}).onFailure(this.handleFail("获取直链失败"));
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
fail("urlParams解析异常" + e.getMessage());
|
||||
}
|
||||
}).onFailure(this.handleFail(DOWNLOAD_API_URL));
|
||||
}
|
||||
|
||||
|
||||
// dir parser
|
||||
@Override
|
||||
public Future<List<FileInfo>> parseFileList() {
|
||||
Promise<List<FileInfo>> promise = Promise.promise();
|
||||
|
||||
String shareKey = shareLinkInfo.getShareKey(); // 分享链接的唯一标识
|
||||
String pwd = shareLinkInfo.getSharePassword(); // 分享密码
|
||||
String parentFileId = "0"; // 根目录的文件ID
|
||||
|
||||
// 如果参数里的目录ID不为空,则直接解析目录
|
||||
String dirId = (String) shareLinkInfo.getOtherParam().get("dirId");
|
||||
if (StringUtils.isNotBlank(dirId)) {
|
||||
parentFileId = dirId;
|
||||
}
|
||||
|
||||
|
||||
// 构造文件列表接口的URL
|
||||
client.getAbs(UriTemplate.of(GET_FILE_INFO_URL))
|
||||
.setTemplateParam("shareKey", shareKey)
|
||||
.setTemplateParam("pwd", pwd)
|
||||
.setTemplateParam("ParentFileId", parentFileId)
|
||||
.putHeaders(header)
|
||||
.send().onSuccess(res -> {
|
||||
JsonObject response = asJson(res);
|
||||
if (response.getInteger("code") != 0) {
|
||||
promise.fail("API错误: " + response.getString("message"));
|
||||
return;
|
||||
}
|
||||
|
||||
JsonArray infoList = response.getJsonObject("data").getJsonArray("InfoList");
|
||||
List<FileInfo> result = new ArrayList<>();
|
||||
|
||||
// 遍历返回的文件和目录信息
|
||||
for (int i = 0; i < infoList.size(); i++) {
|
||||
JsonObject item = infoList.getJsonObject(i);
|
||||
FileInfo fileInfo = new FileInfo();
|
||||
// "FileId": 16603582,
|
||||
// "FileName": "pdf",
|
||||
// "Type": 1,
|
||||
// "Size": 0,
|
||||
// "ContentType": "0",
|
||||
// "S3KeyFlag": "",
|
||||
// "CreateAt": "2025-07-09T06:56:20+08:00",
|
||||
// "UpdateAt": "2025-07-09T06:56:20+08:00",
|
||||
// "Etag": "",
|
||||
// "DownloadUrl": "",
|
||||
// "Status": 0,
|
||||
// "ParentFileId": 16603579,
|
||||
// "Category": 0,
|
||||
// "PunishFlag": 0,
|
||||
// "StorageNode": "m0",
|
||||
// "PreviewType": 0
|
||||
|
||||
// =>
|
||||
// {
|
||||
// "ShareKey":"iaKtVv-FTaCd",
|
||||
// "FileID":16604189,
|
||||
// "S3keyFlag":"1815268665-0",
|
||||
// "Size":425929,
|
||||
// "Etag":"70049de67075ab2b269c62d690424601",
|
||||
// "OrderId":""}
|
||||
JsonObject postData = JsonObject.of()
|
||||
.put("ShareKey", shareKey)
|
||||
.put("FileID", item.getInteger("FileId"))
|
||||
.put("S3keyFlag", item.getString("S3KeyFlag"))
|
||||
.put("Size", item.getLong("Size"))
|
||||
.put("Etag", item.getString("Etag"));
|
||||
|
||||
byte[] encode = Base64.getEncoder().encode(postData.encode().getBytes());
|
||||
String param = new String(encode);
|
||||
|
||||
if (item.getInteger("Type") == 0) { // 文件
|
||||
fileInfo.setFileName(item.getString("FileName"))
|
||||
.setFileId(item.getString("FileId"))
|
||||
.setFileType("file")
|
||||
.setSize(item.getLong("Size"))
|
||||
.setCreateTime(item.getString("CreateAt"))
|
||||
.setUpdateTime(item.getString("UpdateAt"))
|
||||
.setSizeStr(FileSizeConverter.convertToReadableSize(item.getLong("Size")))
|
||||
.setParserUrl(String.format("%s/v2/redirectUrl/%s/%s", getDomainName(),
|
||||
shareLinkInfo.getType(), param))
|
||||
.setPreviewUrl(String.format("%s/v2/viewUrl/%s/%s", getDomainName(),
|
||||
shareLinkInfo.getType(), param));
|
||||
result.add(fileInfo);
|
||||
} else if (item.getInteger("Type") == 1) { // 目录
|
||||
fileInfo.setFileName(item.getString("FileName"))
|
||||
.setFileId(item.getString("FileId"))
|
||||
.setCreateTime(item.getString("CreateAt"))
|
||||
.setUpdateTime(item.getString("UpdateAt"))
|
||||
.setSize(0L)
|
||||
.setFileType("folder")
|
||||
.setParserUrl(
|
||||
String.format("%s/v2/getFileList?url=%s&dirId=%s&pwd=%s",
|
||||
getDomainName(),
|
||||
shareLinkInfo.getShareUrl(),
|
||||
item.getString("FileId"),
|
||||
pwd)
|
||||
);
|
||||
result.add(fileInfo);
|
||||
}
|
||||
}
|
||||
promise.complete(result);
|
||||
}).onFailure(promise::fail);
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<String> parseById() {
|
||||
JsonObject paramJson = (JsonObject) shareLinkInfo.getOtherParam().get("paramJson");
|
||||
// 调用下载接口获取直链
|
||||
down(client, paramJson, DOWNLOAD_API_URL);
|
||||
return promise.future();
|
||||
}
|
||||
}
|
||||
411
parser/src/main/java/cn/qaiu/util/AESUtils.java
Normal file
411
parser/src/main/java/cn/qaiu/util/AESUtils.java
Normal file
@@ -0,0 +1,411 @@
|
||||
package cn.qaiu.util;
|
||||
|
||||
import io.vertx.core.net.impl.URIDecoder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.crypto.*;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.math.BigInteger;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.*;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.HexFormat;
|
||||
import java.util.Random;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* AES加解密工具类
|
||||
*
|
||||
* @author qaiu
|
||||
**/
|
||||
public class AESUtils {
|
||||
|
||||
/**
|
||||
* AES密钥标识
|
||||
*/
|
||||
public static final String SIGN_AES = "AES";
|
||||
|
||||
/**
|
||||
* 密码器AES模式
|
||||
*/
|
||||
public static final String CIPHER_AES = "AES/ECB/PKCS5Padding";
|
||||
|
||||
public static final String CIPHER_AES2 = "YbQHZqK/PdQql2+7ATcPQHREAxt0Hn0Ob9v317QirZM=";
|
||||
|
||||
public static final String CIPHER_AES2_IZ = "1uQFS3sNeHd/bCrmrQpflXREAxt0Hn0Ob9v317QirZM=";
|
||||
|
||||
public static final String CIPHER_AES0;
|
||||
public static final String CIPHER_AES0_IZ;
|
||||
|
||||
|
||||
public static final String MG_PKEY2 = "D8jg+H2iNX94zvHhRLnSM3oy59dH2QQjxQ0GgKJSL+mJclbCcItjV3AmkPY6WcbV4hNQk5+hN2J1eTrxPQqF4p28e3FTsGRCXVN80CLS+XqpFNY/9xuyf2bvbeq5JJU1IBCXgSZmEo8zu0/VGS3YNeDsHtjg92QSrRY8i4A+shihZBSz0/0KOL1VPd/K4tAYvsI9YjVFOI7z9mJJ8Ek8rVUplurJyGkjevRfvReN7xQ67PR+yZovk72yTZKlHDz5jVpLGLOy2iwTTSTbTvtnOi9TSE6sSPtRHv16cxZYZQY=";
|
||||
public static final String MG_PKEY;
|
||||
|
||||
public static final String MG_KEY = "4ea5c508a6566e76240543f8feb06fd457777be39549c4016436afda65d2330e";
|
||||
|
||||
/**
|
||||
* 秘钥长度
|
||||
*/
|
||||
public static final int KEY_LENGTH = 16;
|
||||
|
||||
/**
|
||||
* 密钥长度128
|
||||
*/
|
||||
public static final int KEY_SIZE_128_LENGTH = 128;
|
||||
|
||||
/**
|
||||
* 密钥长度192
|
||||
*/
|
||||
public static final int KEY_SIZE_192_LENGTH = 192;
|
||||
|
||||
/**
|
||||
* 密钥长度256
|
||||
*/
|
||||
public static final int KEY_SIZE_256_LENGTH = 256;
|
||||
|
||||
static {
|
||||
try {
|
||||
CIPHER_AES0 = decryptByBase64AES(CIPHER_AES2, CIPHER_AES);
|
||||
CIPHER_AES0_IZ = decryptByBase64AES(CIPHER_AES2_IZ, CIPHER_AES);
|
||||
MG_PKEY = decryptByBase64AES(MG_PKEY2, CIPHER_AES2);
|
||||
} catch (IllegalBlockSizeException | BadPaddingException | NoSuchPaddingException | NoSuchAlgorithmException |
|
||||
InvalidKeyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成密钥,请使用合适的长度128 192 256
|
||||
*/
|
||||
public static Key createKeyString(int keySize) throws NoSuchAlgorithmException {
|
||||
KeyGenerator keyGenerator = KeyGenerator.getInstance(SIGN_AES);
|
||||
keyGenerator.init(keySize);
|
||||
SecretKey secretKey = keyGenerator.generateKey();
|
||||
return new SecretKeySpec(secretKey.getEncoded(), SIGN_AES);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成Key对象
|
||||
*/
|
||||
public static Key generateKey(String keyString) {
|
||||
if (keyString.length() > KEY_LENGTH) {
|
||||
keyString = keyString.substring(0, KEY_LENGTH);
|
||||
} else if (keyString.length() < KEY_LENGTH) {
|
||||
keyString = StringUtils.rightPad(keyString, 16, 'L');
|
||||
}
|
||||
return new SecretKeySpec(keyString.getBytes(), SIGN_AES);
|
||||
}
|
||||
|
||||
/**
|
||||
* AES加密
|
||||
*
|
||||
* @param source 原文
|
||||
* @param keyString 秘钥
|
||||
* @return byte arrays
|
||||
*/
|
||||
public static byte[] encryptByAES(String source, String keyString) throws NoSuchPaddingException,
|
||||
NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
||||
Cipher cipher = Cipher.getInstance(CIPHER_AES);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, generateKey(keyString));
|
||||
return cipher.doFinal(source.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static byte[] encryptByAES(String source, Key key) throws NoSuchPaddingException,
|
||||
NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
||||
Cipher cipher = Cipher.getInstance(CIPHER_AES);
|
||||
cipher.init(Cipher.ENCRYPT_MODE, key);
|
||||
return cipher.doFinal(source.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* AES加密Base64
|
||||
*
|
||||
* @param source 原文
|
||||
* @param keyString 秘钥
|
||||
* @return BASE64
|
||||
*/
|
||||
public static String encryptBase64ByAES(String source, String keyString) throws NoSuchPaddingException,
|
||||
NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
||||
byte[] encrypted = encryptByAES(source, keyString);
|
||||
return Base64.getEncoder().encodeToString(encrypted);
|
||||
}
|
||||
|
||||
public static String encryptBase64ByAES(String source, Key key) throws NoSuchPaddingException,
|
||||
NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
||||
byte[] encrypted = encryptByAES(source, key);
|
||||
return Base64.getEncoder().encodeToString(encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* AES加密Hex
|
||||
*
|
||||
* @param source 原文
|
||||
* @param keyString 秘钥
|
||||
*/
|
||||
public static String encryptHexByAES(String source, String keyString) throws NoSuchPaddingException,
|
||||
NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
||||
byte[] encrypted = encryptByAES(source, keyString);
|
||||
return HexFormat.of().formatHex(encrypted);
|
||||
}
|
||||
|
||||
public static String encryptHexByAES(String source, Key key) throws NoSuchPaddingException,
|
||||
NoSuchAlgorithmException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
|
||||
byte[] encrypted = encryptByAES(source, key);
|
||||
return HexFormat.of().formatHex(encrypted);
|
||||
}
|
||||
|
||||
public static String encrypt2Hex(String source) {
|
||||
try {
|
||||
return encryptHexByAES(source, CIPHER_AES0);
|
||||
} catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | IllegalBlockSizeException |
|
||||
BadPaddingException e) {
|
||||
throw new RuntimeException("加密失败: "+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static String encrypt2HexIz(String source) {
|
||||
try {
|
||||
return encryptHexByAES(source, CIPHER_AES0_IZ);
|
||||
} catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | IllegalBlockSizeException |
|
||||
BadPaddingException e) {
|
||||
throw new RuntimeException("加密失败: "+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AES解密
|
||||
*
|
||||
* @param encrypted 密文 byte
|
||||
* @param keyString 秘钥
|
||||
*/
|
||||
public static String decryptByAES(byte[] encrypted, String keyString) throws IllegalBlockSizeException,
|
||||
BadPaddingException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
|
||||
return decryptByAES(encrypted, generateKey(keyString));
|
||||
}
|
||||
|
||||
public static String decryptByAES(byte[] encrypted, Key key) throws IllegalBlockSizeException,
|
||||
BadPaddingException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
|
||||
Cipher cipher = Cipher.getInstance(CIPHER_AES);
|
||||
cipher.init(Cipher.DECRYPT_MODE, key);
|
||||
byte[] decrypted = cipher.doFinal(encrypted);
|
||||
return new String(decrypted, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* AES解密
|
||||
*
|
||||
* @param encrypted 密文 Hex
|
||||
* @param keyString 秘钥
|
||||
*/
|
||||
public static String decryptByHexAES(String encrypted, String keyString) throws IllegalBlockSizeException,
|
||||
BadPaddingException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
|
||||
return decryptByAES(HexFormat.of().parseHex(encrypted), keyString);
|
||||
}
|
||||
|
||||
public static String decryptByHexAES(String encrypted, Key key) throws IllegalBlockSizeException,
|
||||
BadPaddingException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
|
||||
return decryptByAES(HexFormat.of().parseHex(encrypted), key);
|
||||
}
|
||||
|
||||
/**
|
||||
* AES解密
|
||||
*
|
||||
* @param encrypted 密文 Base64
|
||||
* @param keyString 秘钥
|
||||
*/
|
||||
public static String decryptByBase64AES(String encrypted, String keyString) throws IllegalBlockSizeException,
|
||||
BadPaddingException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
|
||||
return decryptByAES(Base64.getDecoder().decode(encrypted), keyString);
|
||||
}
|
||||
|
||||
public static String decryptByBase64AES(String encrypted, Key key) throws IllegalBlockSizeException,
|
||||
BadPaddingException, InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
|
||||
return decryptByAES(Base64.getDecoder().decode(encrypted), key);
|
||||
}
|
||||
|
||||
// ================================飞机盘Id解密========================================== //
|
||||
private static final char[] array = {
|
||||
'T', 'U', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'0', 'M', 'N', 'O', 'P', 'X', 'Y', 'Z', 'V', 'W',
|
||||
'Q', '1', '2', '3', '4', 'a', 'b', 'c', 'd', 'e',
|
||||
'5', '6', '7', '8', '9', 'v', 'w', 'x', 'y', 'z',
|
||||
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||
'p', 'q', 'r', 's', 't', 'u', 'L', 'R', 'S', 'I',
|
||||
'J', 'K'};
|
||||
private static final char[] arrayIz =
|
||||
{'Y', 'y', '0', 'Z', 'z', 'N', 'n', 'M', 'I', '6', 'm', 'W', 'w', '1', 'X', 'x', 'L', 'l', 'K', '7', 'k',
|
||||
'i', 'U', 'u', '2', 'V', 'v', 'J', 'j', '8', 'G', 'g', 'F', 'S', 's', '3', 'T', 't', 'H', 'h',
|
||||
'f', 'E', 'e', 'D', 'Q', 'q', '4', 'R', 'r', '9', 'd', 'a', 'C', 'c', 'B', 'O', 'o', '5', 'P',
|
||||
'p', 'b', 'A'};
|
||||
private static int decodeChar(char c, char[] keys) {
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
if (c == keys[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// id解密
|
||||
public static int idEncrypt(String str) {
|
||||
return idEncrypt0(str, array, 2, 2);
|
||||
}
|
||||
|
||||
|
||||
// ================================蓝奏优享版Id解密========================================== //
|
||||
public static int idEncryptIz(String str) {
|
||||
// idEncrypt(e) {
|
||||
// let t = 1
|
||||
// , n = 0;
|
||||
// if ("" != e && e.length > 4) {
|
||||
// let r;
|
||||
// e = e.substring(3, e.length - 1);
|
||||
// for (let v = 0; v < e.length; v++)
|
||||
// r = e.charAt(e.length - v - 1),
|
||||
// n += this.decodeChar(r) * t,
|
||||
// t *= 62
|
||||
// }
|
||||
// return n
|
||||
// },
|
||||
|
||||
return idEncrypt0(str, arrayIz, 3, 1);
|
||||
}
|
||||
|
||||
public static int idEncrypt0(String str, char[] keys, int x1, int x2) {
|
||||
// 倍数
|
||||
int multiple = 1;
|
||||
int result = 0;
|
||||
if (StringUtils.isNotEmpty(str) && str.length() > 4) {
|
||||
str = str.substring(x1, str.length() - x2);
|
||||
char c;
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
c = str.charAt(str.length() - i - 1);
|
||||
result += decodeChar(c, keys) * multiple;
|
||||
multiple = multiple * 62;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ========================== musetransfer加密相关 ===========================
|
||||
|
||||
//length用户要求产生字符串的长度
|
||||
public static String getRandomString(int length){
|
||||
String str="abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
Random random=new Random();
|
||||
StringBuilder sb=new StringBuilder();
|
||||
for(int i=0;i<length;i++){
|
||||
int number=random.nextInt(36);
|
||||
sb.append(str.charAt(number));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getRandomString(){
|
||||
return getRandomString(10);
|
||||
}
|
||||
|
||||
|
||||
//=============================== 123pan加密相关 ===============================
|
||||
|
||||
public static String getMD5Str(String str) {
|
||||
byte[] digest;
|
||||
try {
|
||||
MessageDigest md5 = MessageDigest.getInstance("md5");
|
||||
digest = md5.digest(str.getBytes(StandardCharsets.UTF_8));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
//16是表示转换为16进制数
|
||||
return new BigInteger(1, digest).toString(16);
|
||||
}
|
||||
|
||||
public static String getAuthKey(String _0x2207af) {
|
||||
String _0x467baa = "web";
|
||||
int _0x4965f1 = 3;
|
||||
|
||||
String _0x430930 = String.valueOf(Math.round(0x989680 * Math.random()));
|
||||
String _0x53928f = String.valueOf(new Date().getTime() / 0x3e8);
|
||||
String _0x49ec94 = getMD5Str(_0x53928f + "|" + _0x430930 + "|" + _0x2207af + "|" + _0x467baa + "|" + _0x4965f1
|
||||
+ "|8-8D$sL8gPjom7bk#cY");
|
||||
|
||||
return _0x53928f + "-" + _0x430930 + "-" + _0x49ec94;
|
||||
}
|
||||
|
||||
|
||||
public static String encrypt(String str, String pwd) {
|
||||
if (pwd == null || pwd.length() <= 0) {
|
||||
throw new IllegalArgumentException("Please enter a password with which to encrypt the message.");
|
||||
}
|
||||
|
||||
// 生成 prand 值
|
||||
StringBuilder prand = new StringBuilder();
|
||||
for (int i = 0; i < pwd.length(); i++) {
|
||||
prand.append((int) pwd.charAt(i));
|
||||
}
|
||||
|
||||
// 计算 sPos, mult, incr, modu
|
||||
int sPos = prand.length() / 5;
|
||||
long mult = Long.parseLong(prand.substring(sPos, sPos + 1) +
|
||||
prand.substring(sPos * 2, sPos * 2 + 1) +
|
||||
prand.substring(sPos * 3, sPos * 3 + 1) +
|
||||
prand.substring(sPos * 4, sPos * 4 + 1) +
|
||||
prand.substring(sPos * 5, sPos * 5 + 1));
|
||||
int incr = (int) Math.ceil(pwd.length() / 2.0);
|
||||
long modu = (long) Math.pow(2, 31) - 1;
|
||||
|
||||
if (mult < 2) {
|
||||
throw new IllegalArgumentException("Algorithm cannot find a suitable hash. Please choose a different password.");
|
||||
}
|
||||
|
||||
// 生成 salt 并加到 prand 上
|
||||
long salt = Math.round(Math.random() * 1000000000) % 100000000;
|
||||
prand.append(salt);
|
||||
|
||||
// 使用 BigInteger 处理超过 Long 范围的 prand 值
|
||||
BigInteger prandValue = new BigInteger(prand.toString());
|
||||
while (prandValue.toString().length() > 10) {
|
||||
prandValue = prandValue.divide(BigInteger.TEN).add(prandValue.remainder(BigInteger.TEN));
|
||||
}
|
||||
|
||||
// 将 prand 转换为 long 进行后续处理
|
||||
prandValue = prandValue.multiply(BigInteger.valueOf(mult)).add(BigInteger.valueOf(incr)).mod(BigInteger.valueOf(modu));
|
||||
|
||||
// 加密过程
|
||||
StringBuilder encStr = new StringBuilder();
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
// 将字符和异或的结果强制转换为 int
|
||||
int encChr = (int) (str.charAt(i) ^ (int) ((prandValue.doubleValue() / modu) * 255));
|
||||
String hexStr = Integer.toHexString(encChr);
|
||||
if (hexStr.length() < 2) {
|
||||
encStr.append("0");
|
||||
}
|
||||
encStr.append(hexStr);
|
||||
|
||||
prandValue = prandValue.multiply(BigInteger.valueOf(mult)).add(BigInteger.valueOf(incr)).mod(BigInteger.valueOf(modu));
|
||||
}
|
||||
|
||||
// 将 salt 转换为 16 进制并追加到加密结果
|
||||
String saltHex = Long.toHexString(salt);
|
||||
while (saltHex.length() < 8) {
|
||||
saltHex = "0" + saltHex;
|
||||
}
|
||||
encStr.append(saltHex);
|
||||
|
||||
return encStr.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 示例
|
||||
String encrypted = encrypt("HelloWorld", "password123");
|
||||
System.out.println("Encrypted String: " + encrypted);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.qaiu.lz.common.util;
|
||||
package cn.qaiu.util;
|
||||
|
||||
public class ArrayUtil {
|
||||
|
||||
18
parser/src/main/java/cn/qaiu/util/CastUtil.java
Normal file
18
parser/src/main/java/cn/qaiu/util/CastUtil.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package cn.qaiu.util;
|
||||
|
||||
/**
|
||||
* 转换为任意类型 旨在消除泛型转换时的异常
|
||||
*/
|
||||
public interface CastUtil {
|
||||
|
||||
/**
|
||||
* 泛型转换
|
||||
* @param object 要转换的object
|
||||
* @param <T> T
|
||||
* @return T
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
static <T> T cast(Object object) {
|
||||
return (T) object;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user