Compare commits
7 Commits
1f11013ae0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 18a7c15a76 | |||
| d1e619d04c | |||
| 5e43c5fc4c | |||
| 8a633feb4f | |||
| 15fcfdad18 | |||
| d22be3a840 | |||
| 76924b008c |
12
package.json
12
package.json
@@ -44,15 +44,16 @@
|
|||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@kevisual/ai": "^0.0.19",
|
"@kevisual/ai": "^0.0.19",
|
||||||
"@kevisual/query": "^0.0.32",
|
"@kevisual/query": "^0.0.33",
|
||||||
"@types/busboy": "^1.5.4",
|
"@types/busboy": "^1.5.4",
|
||||||
"@types/send": "^1.2.1",
|
"@types/send": "^1.2.1",
|
||||||
"@types/ws": "^8.18.1",
|
"@types/ws": "^8.18.1",
|
||||||
"bullmq": "^5.66.0",
|
"bullmq": "^5.66.2",
|
||||||
"busboy": "^1.6.0",
|
"busboy": "^1.6.0",
|
||||||
"commander": "^14.0.2",
|
"commander": "^14.0.2",
|
||||||
"cookie": "^1.1.1",
|
"cookie": "^1.1.1",
|
||||||
"drizzle-orm": "^0.45.1",
|
"drizzle-orm": "^0.45.1",
|
||||||
|
"eventemitter3": "^5.0.1",
|
||||||
"ioredis": "^5.8.2",
|
"ioredis": "^5.8.2",
|
||||||
"minio": "^8.0.6",
|
"minio": "^8.0.6",
|
||||||
"pg": "^8.16.3",
|
"pg": "^8.16.3",
|
||||||
@@ -68,12 +69,12 @@
|
|||||||
"@kevisual/logger": "^0.0.4",
|
"@kevisual/logger": "^0.0.4",
|
||||||
"@kevisual/oss": "0.0.13",
|
"@kevisual/oss": "0.0.13",
|
||||||
"@kevisual/permission": "^0.0.3",
|
"@kevisual/permission": "^0.0.3",
|
||||||
"@kevisual/router": "0.0.37",
|
"@kevisual/router": "0.0.48",
|
||||||
"@kevisual/types": "^0.0.10",
|
"@kevisual/types": "^0.0.10",
|
||||||
"@kevisual/use-config": "^1.0.21",
|
"@kevisual/use-config": "^1.0.21",
|
||||||
"@types/archiver": "^7.0.0",
|
"@types/archiver": "^7.0.0",
|
||||||
|
"@types/bun": "^1.3.5",
|
||||||
"@types/crypto-js": "^4.2.2",
|
"@types/crypto-js": "^4.2.2",
|
||||||
"@types/formidable": "^3.4.6",
|
|
||||||
"@types/jsonwebtoken": "^9.0.10",
|
"@types/jsonwebtoken": "^9.0.10",
|
||||||
"@types/lodash-es": "^4.17.12",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@types/node": "^25.0.3",
|
"@types/node": "^25.0.3",
|
||||||
@@ -82,7 +83,6 @@
|
|||||||
"crypto-js": "^4.2.0",
|
"crypto-js": "^4.2.0",
|
||||||
"dayjs": "^1.11.19",
|
"dayjs": "^1.11.19",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"formidable": "3.5.4",
|
|
||||||
"ioredis": "^5.8.2",
|
"ioredis": "^5.8.2",
|
||||||
"jsonwebtoken": "^9.0.3",
|
"jsonwebtoken": "^9.0.3",
|
||||||
"lodash-es": "^4.17.22",
|
"lodash-es": "^4.17.22",
|
||||||
@@ -113,5 +113,5 @@
|
|||||||
"msgpackr-extract"
|
"msgpackr-extract"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@10.26.0"
|
"packageManager": "pnpm@10.26.1"
|
||||||
}
|
}
|
||||||
129
pnpm-lock.yaml
generated
129
pnpm-lock.yaml
generated
@@ -16,8 +16,8 @@ importers:
|
|||||||
specifier: ^0.0.19
|
specifier: ^0.0.19
|
||||||
version: 0.0.19
|
version: 0.0.19
|
||||||
'@kevisual/query':
|
'@kevisual/query':
|
||||||
specifier: ^0.0.32
|
specifier: ^0.0.33
|
||||||
version: 0.0.32
|
version: 0.0.33
|
||||||
'@types/busboy':
|
'@types/busboy':
|
||||||
specifier: ^1.5.4
|
specifier: ^1.5.4
|
||||||
version: 1.5.4
|
version: 1.5.4
|
||||||
@@ -28,8 +28,8 @@ importers:
|
|||||||
specifier: ^8.18.1
|
specifier: ^8.18.1
|
||||||
version: 8.18.1
|
version: 8.18.1
|
||||||
bullmq:
|
bullmq:
|
||||||
specifier: ^5.66.0
|
specifier: ^5.66.2
|
||||||
version: 5.66.0
|
version: 5.66.2
|
||||||
busboy:
|
busboy:
|
||||||
specifier: ^1.6.0
|
specifier: ^1.6.0
|
||||||
version: 1.6.0
|
version: 1.6.0
|
||||||
@@ -41,7 +41,10 @@ importers:
|
|||||||
version: 1.1.1
|
version: 1.1.1
|
||||||
drizzle-orm:
|
drizzle-orm:
|
||||||
specifier: ^0.45.1
|
specifier: ^0.45.1
|
||||||
version: 0.45.1(pg@8.16.3)
|
version: 0.45.1(bun-types@1.3.5)(pg@8.16.3)
|
||||||
|
eventemitter3:
|
||||||
|
specifier: ^5.0.1
|
||||||
|
version: 5.0.1
|
||||||
ioredis:
|
ioredis:
|
||||||
specifier: ^5.8.2
|
specifier: ^5.8.2
|
||||||
version: 5.8.2
|
version: 5.8.2
|
||||||
@@ -83,8 +86,8 @@ importers:
|
|||||||
specifier: ^0.0.3
|
specifier: ^0.0.3
|
||||||
version: 0.0.3
|
version: 0.0.3
|
||||||
'@kevisual/router':
|
'@kevisual/router':
|
||||||
specifier: 0.0.37
|
specifier: 0.0.48
|
||||||
version: 0.0.37
|
version: 0.0.48
|
||||||
'@kevisual/types':
|
'@kevisual/types':
|
||||||
specifier: ^0.0.10
|
specifier: ^0.0.10
|
||||||
version: 0.0.10
|
version: 0.0.10
|
||||||
@@ -94,6 +97,9 @@ importers:
|
|||||||
'@types/archiver':
|
'@types/archiver':
|
||||||
specifier: ^7.0.0
|
specifier: ^7.0.0
|
||||||
version: 7.0.0
|
version: 7.0.0
|
||||||
|
'@types/bun':
|
||||||
|
specifier: ^1.3.5
|
||||||
|
version: 1.3.5
|
||||||
'@types/crypto-js':
|
'@types/crypto-js':
|
||||||
specifier: ^4.2.2
|
specifier: ^4.2.2
|
||||||
version: 4.2.2
|
version: 4.2.2
|
||||||
@@ -161,6 +167,27 @@ importers:
|
|||||||
specifier: ^4.2.1
|
specifier: ^4.2.1
|
||||||
version: 4.2.1
|
version: 4.2.1
|
||||||
|
|
||||||
|
wxmsg/pack-dist:
|
||||||
|
dependencies:
|
||||||
|
'@kevisual/context':
|
||||||
|
specifier: ^0.0.4
|
||||||
|
version: 0.0.4
|
||||||
|
'@kevisual/query':
|
||||||
|
specifier: ^0.0.29
|
||||||
|
version: 0.0.29(@kevisual/ws@8.0.0)(zod@3.25.67)
|
||||||
|
'@kevisual/router':
|
||||||
|
specifier: 0.0.33
|
||||||
|
version: 0.0.33
|
||||||
|
'@types/node':
|
||||||
|
specifier: ^24.10.1
|
||||||
|
version: 24.10.4
|
||||||
|
crypto-js:
|
||||||
|
specifier: ^4.2.0
|
||||||
|
version: 4.2.0
|
||||||
|
xml2js:
|
||||||
|
specifier: ^0.6.2
|
||||||
|
version: 0.6.2
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
|
|
||||||
'@ioredis/commands@1.4.0':
|
'@ioredis/commands@1.4.0':
|
||||||
@@ -207,11 +234,14 @@ packages:
|
|||||||
'@kevisual/permission@0.0.3':
|
'@kevisual/permission@0.0.3':
|
||||||
resolution: {integrity: sha512-8JsA/5O5Ax/z+M+MYpFYdlioHE6jNmWMuFSokBWYs9CCAHNiSKMR01YLkoVDoPvncfH/Y8F5K/IEXRCbptuMNA==}
|
resolution: {integrity: sha512-8JsA/5O5Ax/z+M+MYpFYdlioHE6jNmWMuFSokBWYs9CCAHNiSKMR01YLkoVDoPvncfH/Y8F5K/IEXRCbptuMNA==}
|
||||||
|
|
||||||
|
'@kevisual/query@0.0.29':
|
||||||
|
resolution: {integrity: sha512-rQZk0J073UuC1QGzuyq+pb4Y0hu8/Qx/xYHs9NbsmslM+RuMnd1zpXmvhXNj7Kn1MdYTH90ng2MlFLBkkQFaIg==}
|
||||||
|
|
||||||
'@kevisual/query@0.0.31':
|
'@kevisual/query@0.0.31':
|
||||||
resolution: {integrity: sha512-bBdepjmMICLpcj/a9fnn82/0CGGYUZiCV+usWsJZKAwVlZcnj+WtKmbgKT09KpP6g3jjYzYOaXHiNFB8N0bQAQ==}
|
resolution: {integrity: sha512-bBdepjmMICLpcj/a9fnn82/0CGGYUZiCV+usWsJZKAwVlZcnj+WtKmbgKT09KpP6g3jjYzYOaXHiNFB8N0bQAQ==}
|
||||||
|
|
||||||
'@kevisual/query@0.0.32':
|
'@kevisual/query@0.0.33':
|
||||||
resolution: {integrity: sha512-9WN9cjmwSW8I5A0SqITdts9oxlLBGdPP7kJ8vwrxkaQteHS9FzxKuMBJxZzGKZdyte/zJDvdrE+lMf254BGbbg==}
|
resolution: {integrity: sha512-3w74bcLpwV3z483eg8n0DgkftfjWC6iLONXBvfyjW6IZf6jMOuouFaM4Rk+uEsTgElU6XGMKseNTp6dlQdWYkg==}
|
||||||
|
|
||||||
'@kevisual/router@0.0.21':
|
'@kevisual/router@0.0.21':
|
||||||
resolution: {integrity: sha512-XKTxbNO924cT18UOAGplWErZ+hMze8Y53F2jYCk18v4jsdsvjRho5uXXjJb6HSVsuITMtQR4R3rG0IcM3jkDKQ==}
|
resolution: {integrity: sha512-XKTxbNO924cT18UOAGplWErZ+hMze8Y53F2jYCk18v4jsdsvjRho5uXXjJb6HSVsuITMtQR4R3rG0IcM3jkDKQ==}
|
||||||
@@ -222,8 +252,11 @@ packages:
|
|||||||
'@kevisual/router@0.0.23':
|
'@kevisual/router@0.0.23':
|
||||||
resolution: {integrity: sha512-W6ehlhAzNe58vq4QeQt2XFoO84Qaw34A0PVOByJsJ2ICj4YKBTclAt+rOAoISCvUeSbeNOIuhUE3sLyPfplzUw==}
|
resolution: {integrity: sha512-W6ehlhAzNe58vq4QeQt2XFoO84Qaw34A0PVOByJsJ2ICj4YKBTclAt+rOAoISCvUeSbeNOIuhUE3sLyPfplzUw==}
|
||||||
|
|
||||||
'@kevisual/router@0.0.37':
|
'@kevisual/router@0.0.33':
|
||||||
resolution: {integrity: sha512-f/siDSqO0g6cQhBrWyPIVv8WMgxjC+olRS8GNxqzkBvAj5M4x3cmfAj1bxTn7neOejTjkGd+ZeoDQbhIpFKDZQ==}
|
resolution: {integrity: sha512-9z7TkSzCIGbXn9SuHPBdZpGwHlAuwA8iN5jNAZBUvbEvBRkBxlrbdCSe9fBYiAHueLm2AceFNrW74uulOiAkqA==}
|
||||||
|
|
||||||
|
'@kevisual/router@0.0.48':
|
||||||
|
resolution: {integrity: sha512-WsSvT+NpfC/bZbaAzE3WSKD2DRZP0JuPQJGr4YucSdO/lOLB4cEpOZRbPlV3l7G064ow8QJRAN2DUW+bRjrp1A==}
|
||||||
|
|
||||||
'@kevisual/types@0.0.10':
|
'@kevisual/types@0.0.10':
|
||||||
resolution: {integrity: sha512-Q73uzzjk9UidumnmCvOpgzqDDvQxsblz22bIFuoiioUFJWwaparx8bpd8ArRyFojicYL1YJoFDzDZ9j9NN8grA==}
|
resolution: {integrity: sha512-Q73uzzjk9UidumnmCvOpgzqDDvQxsblz22bIFuoiioUFJWwaparx8bpd8ArRyFojicYL1YJoFDzDZ9j9NN8grA==}
|
||||||
@@ -356,6 +389,9 @@ packages:
|
|||||||
'@types/archiver@7.0.0':
|
'@types/archiver@7.0.0':
|
||||||
resolution: {integrity: sha512-/3vwGwx9n+mCQdYZ2IKGGHEFL30I96UgBlk8EtRDDFQ9uxM1l4O5Ci6r00EMAkiDaTqD9DQ6nVrWRICnBPtzzg==}
|
resolution: {integrity: sha512-/3vwGwx9n+mCQdYZ2IKGGHEFL30I96UgBlk8EtRDDFQ9uxM1l4O5Ci6r00EMAkiDaTqD9DQ6nVrWRICnBPtzzg==}
|
||||||
|
|
||||||
|
'@types/bun@1.3.5':
|
||||||
|
resolution: {integrity: sha512-RnygCqNrd3srIPEWBd5LFeUYG7plCoH2Yw9WaZGyNmdTEei+gWaHqydbaIRkIkcbXwhBT94q78QljxN0Sk838w==}
|
||||||
|
|
||||||
'@types/busboy@1.5.4':
|
'@types/busboy@1.5.4':
|
||||||
resolution: {integrity: sha512-kG7WrUuAKK0NoyxfQHsVE6j1m01s6kMma64E+OZenQABMQyTJop1DumUWcLwAQ2JzpefU7PDYoRDKl8uZosFjw==}
|
resolution: {integrity: sha512-kG7WrUuAKK0NoyxfQHsVE6j1m01s6kMma64E+OZenQABMQyTJop1DumUWcLwAQ2JzpefU7PDYoRDKl8uZosFjw==}
|
||||||
|
|
||||||
@@ -392,6 +428,9 @@ packages:
|
|||||||
'@types/node-forge@1.3.11':
|
'@types/node-forge@1.3.11':
|
||||||
resolution: {integrity: sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==}
|
resolution: {integrity: sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==}
|
||||||
|
|
||||||
|
'@types/node@24.10.4':
|
||||||
|
resolution: {integrity: sha512-vnDVpYPMzs4wunl27jHrfmwojOGKya0xyM3sH+UE5iv5uPS6vX7UIoh6m+vQc5LGBq52HBKPIn/zcSZVzeDEZg==}
|
||||||
|
|
||||||
'@types/node@25.0.3':
|
'@types/node@25.0.3':
|
||||||
resolution: {integrity: sha512-W609buLVRVmeW693xKfzHeIV6nJGGz98uCPfeXI1ELMLXVeKYZ9m15fAMSaUPBHYLGFsVRcMmSCksQOrZV9BYA==}
|
resolution: {integrity: sha512-W609buLVRVmeW693xKfzHeIV6nJGGz98uCPfeXI1ELMLXVeKYZ9m15fAMSaUPBHYLGFsVRcMmSCksQOrZV9BYA==}
|
||||||
|
|
||||||
@@ -547,8 +586,11 @@ packages:
|
|||||||
buffer@6.0.3:
|
buffer@6.0.3:
|
||||||
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
|
resolution: {integrity: sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==}
|
||||||
|
|
||||||
bullmq@5.66.0:
|
bullmq@5.66.2:
|
||||||
resolution: {integrity: sha512-LSe8yEiVTllOOq97Q0C/EhczKS5Yd0AUJleGJCIh0cyJE5nWUqEpGC/uZQuuAYniBSoMT8LqwrxE7N5MZVrLoQ==}
|
resolution: {integrity: sha512-0PrkpIakIntkBcPLltPIRWdLC1FTLUa/VhJkmEfobb5YUQjoUwJdmmf7HX+o/vMonS5048JpP+abf9lVRUFEjA==}
|
||||||
|
|
||||||
|
bun-types@1.3.5:
|
||||||
|
resolution: {integrity: sha512-inmAYe2PFLs0SUbFOWSVD24sg1jFlMPxOjOSSCYqUgn4Hsc3rDc7dFvfVYjFPNHtov6kgUeulV4SxbuIV/stPw==}
|
||||||
|
|
||||||
busboy@1.6.0:
|
busboy@1.6.0:
|
||||||
resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==}
|
resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==}
|
||||||
@@ -1331,6 +1373,18 @@ packages:
|
|||||||
once@1.4.0:
|
once@1.4.0:
|
||||||
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
|
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
|
||||||
|
|
||||||
|
openai@5.23.2:
|
||||||
|
resolution: {integrity: sha512-MQBzmTulj+MM5O8SKEk/gL8a7s5mktS9zUtAkU257WjvobGc9nKcBuVwjyEEcb9SI8a8Y2G/mzn3vm9n1Jlleg==}
|
||||||
|
hasBin: true
|
||||||
|
peerDependencies:
|
||||||
|
ws: ^8.18.0
|
||||||
|
zod: ^3.23.8
|
||||||
|
peerDependenciesMeta:
|
||||||
|
ws:
|
||||||
|
optional: true
|
||||||
|
zod:
|
||||||
|
optional: true
|
||||||
|
|
||||||
p-queue@9.0.1:
|
p-queue@9.0.1:
|
||||||
resolution: {integrity: sha512-RhBdVhSwJb7Ocn3e8ULk4NMwBEuOxe+1zcgphUy9c2e5aR/xbEsdVXxHJ3lynw6Qiqu7OINEyHlZkiblEpaq7w==}
|
resolution: {integrity: sha512-RhBdVhSwJb7Ocn3e8ULk4NMwBEuOxe+1zcgphUy9c2e5aR/xbEsdVXxHJ3lynw6Qiqu7OINEyHlZkiblEpaq7w==}
|
||||||
engines: {node: '>=20'}
|
engines: {node: '>=20'}
|
||||||
@@ -1574,6 +1628,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-th5B4L2U+eGLq1TVh7zNRGBapioSORUeymIydxgFpwww9d2qyKvtuPU2jJuHvYAwwqi2Y596QBL3eEqcPEYL8Q==}
|
resolution: {integrity: sha512-th5B4L2U+eGLq1TVh7zNRGBapioSORUeymIydxgFpwww9d2qyKvtuPU2jJuHvYAwwqi2Y596QBL3eEqcPEYL8Q==}
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
|
|
||||||
|
selfsigned@4.0.1:
|
||||||
|
resolution: {integrity: sha512-QVGzJryYPB7ctpYxoK4DDvH4kFf23wtBl0s6km/wN+JCWLqjutdyWaiXHwSg3B3ftDOFfu0B7FWRVNH0xNn6rw==}
|
||||||
|
engines: {node: '>=10'}
|
||||||
|
|
||||||
selfsigned@5.2.0:
|
selfsigned@5.2.0:
|
||||||
resolution: {integrity: sha512-QKF6fsJgdKn5Cy1SekTuwUQ6LOLUdnO4gVne1+TGSAyL/CD1aznNCmBna+bQB9xyon7DiYbDtTR1cLaxDXuaVA==}
|
resolution: {integrity: sha512-QKF6fsJgdKn5Cy1SekTuwUQ6LOLUdnO4gVne1+TGSAyL/CD1aznNCmBna+bQB9xyon7DiYbDtTR1cLaxDXuaVA==}
|
||||||
engines: {node: '>=15.6.0'}
|
engines: {node: '>=15.6.0'}
|
||||||
@@ -2059,9 +2117,16 @@ snapshots:
|
|||||||
|
|
||||||
'@kevisual/permission@0.0.3': {}
|
'@kevisual/permission@0.0.3': {}
|
||||||
|
|
||||||
|
'@kevisual/query@0.0.29(@kevisual/ws@8.0.0)(zod@3.25.67)':
|
||||||
|
dependencies:
|
||||||
|
openai: 5.23.2(@kevisual/ws@8.0.0)(zod@3.25.67)
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- ws
|
||||||
|
- zod
|
||||||
|
|
||||||
'@kevisual/query@0.0.31': {}
|
'@kevisual/query@0.0.31': {}
|
||||||
|
|
||||||
'@kevisual/query@0.0.32': {}
|
'@kevisual/query@0.0.33': {}
|
||||||
|
|
||||||
'@kevisual/router@0.0.21':
|
'@kevisual/router@0.0.21':
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -2081,7 +2146,15 @@ snapshots:
|
|||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
'@kevisual/router@0.0.37':
|
'@kevisual/router@0.0.33':
|
||||||
|
dependencies:
|
||||||
|
path-to-regexp: 8.3.0
|
||||||
|
selfsigned: 4.0.1
|
||||||
|
send: 1.2.1
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- supports-color
|
||||||
|
|
||||||
|
'@kevisual/router@0.0.48':
|
||||||
dependencies:
|
dependencies:
|
||||||
path-to-regexp: 8.3.0
|
path-to-regexp: 8.3.0
|
||||||
selfsigned: 5.2.0
|
selfsigned: 5.2.0
|
||||||
@@ -2289,6 +2362,10 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@types/readdir-glob': 1.1.5
|
'@types/readdir-glob': 1.1.5
|
||||||
|
|
||||||
|
'@types/bun@1.3.5':
|
||||||
|
dependencies:
|
||||||
|
bun-types: 1.3.5
|
||||||
|
|
||||||
'@types/busboy@1.5.4':
|
'@types/busboy@1.5.4':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 25.0.3
|
'@types/node': 25.0.3
|
||||||
@@ -2328,6 +2405,10 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@types/node': 25.0.3
|
'@types/node': 25.0.3
|
||||||
|
|
||||||
|
'@types/node@24.10.4':
|
||||||
|
dependencies:
|
||||||
|
undici-types: 7.16.0
|
||||||
|
|
||||||
'@types/node@25.0.3':
|
'@types/node@25.0.3':
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 7.16.0
|
undici-types: 7.16.0
|
||||||
@@ -2482,7 +2563,7 @@ snapshots:
|
|||||||
base64-js: 1.5.1
|
base64-js: 1.5.1
|
||||||
ieee754: 1.2.1
|
ieee754: 1.2.1
|
||||||
|
|
||||||
bullmq@5.66.0:
|
bullmq@5.66.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
cron-parser: 4.9.0
|
cron-parser: 4.9.0
|
||||||
ioredis: 5.8.2
|
ioredis: 5.8.2
|
||||||
@@ -2494,6 +2575,10 @@ snapshots:
|
|||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- supports-color
|
||||||
|
|
||||||
|
bun-types@1.3.5:
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 25.0.3
|
||||||
|
|
||||||
busboy@1.6.0:
|
busboy@1.6.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
streamsearch: 1.1.0
|
streamsearch: 1.1.0
|
||||||
@@ -2645,8 +2730,9 @@ snapshots:
|
|||||||
|
|
||||||
dottie@2.0.6: {}
|
dottie@2.0.6: {}
|
||||||
|
|
||||||
drizzle-orm@0.45.1(pg@8.16.3):
|
drizzle-orm@0.45.1(bun-types@1.3.5)(pg@8.16.3):
|
||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
|
bun-types: 1.3.5
|
||||||
pg: 8.16.3
|
pg: 8.16.3
|
||||||
|
|
||||||
eastasianwidth@0.2.0: {}
|
eastasianwidth@0.2.0: {}
|
||||||
@@ -3166,6 +3252,11 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
wrappy: 1.0.2
|
wrappy: 1.0.2
|
||||||
|
|
||||||
|
openai@5.23.2(@kevisual/ws@8.0.0)(zod@3.25.67):
|
||||||
|
optionalDependencies:
|
||||||
|
ws: '@kevisual/ws@8.0.0'
|
||||||
|
zod: 3.25.67
|
||||||
|
|
||||||
p-queue@9.0.1:
|
p-queue@9.0.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
eventemitter3: 5.0.1
|
eventemitter3: 5.0.1
|
||||||
@@ -3473,6 +3564,10 @@ snapshots:
|
|||||||
'@types/node-forge': 1.3.11
|
'@types/node-forge': 1.3.11
|
||||||
node-forge: 1.3.1
|
node-forge: 1.3.1
|
||||||
|
|
||||||
|
selfsigned@4.0.1:
|
||||||
|
dependencies:
|
||||||
|
node-forge: 1.3.1
|
||||||
|
|
||||||
selfsigned@5.2.0:
|
selfsigned@5.2.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@peculiar/x509': 1.14.2
|
'@peculiar/x509': 1.14.2
|
||||||
|
|||||||
@@ -29,17 +29,13 @@ export const minioClient = useContextKey('minioClient', () => minioLib.minioClie
|
|||||||
export const sequelize = useContextKey('sequelize', () => sequelizeLib.sequelize);
|
export const sequelize = useContextKey('sequelize', () => sequelizeLib.sequelize);
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
return new App<{ sequelize: typeof sequelize }>({
|
return new App({
|
||||||
serverOptions: {
|
serverOptions: {
|
||||||
cors: {
|
cors: {
|
||||||
origin: '*',
|
origin: '*',
|
||||||
},
|
},
|
||||||
// httpType: 'https',
|
|
||||||
},
|
|
||||||
io: true,
|
io: true,
|
||||||
routerContext: {
|
}
|
||||||
sequelize,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
export const app = useContextKey('app', init);
|
export const app = useContextKey('app', init);
|
||||||
|
|||||||
69
src/index.ts
69
src/index.ts
@@ -1,62 +1,19 @@
|
|||||||
import { myConfig as config } from './modules/config.ts';
|
|
||||||
import { app } from './app.ts';
|
import { app } from './app.ts';
|
||||||
import './route.ts';
|
import './route.ts';
|
||||||
import { handleRequest } from './routes-simple/handle-request.ts';
|
import { handleRequest } from './routes-simple/handle-request.ts';
|
||||||
import { port } from './modules/config.ts';
|
import { port } from './modules/config.ts';
|
||||||
import { WssApp } from './modules/ws-proxy/index.ts';
|
import { wssFun } from './modules/ws-proxy/index.ts';
|
||||||
import net from 'node:net';
|
import { WebSocketListenerFun, HttpListenerFun } from '@kevisual/router/src/server/server-type.js';
|
||||||
// if (import.meta.url === `file://${process.argv[1]}`) {
|
console.log('Starting server...', port);
|
||||||
app.listen(port, () => {
|
app.listen(port, '0.0.0.0', () => {
|
||||||
console.log(`server is running at http://localhost:${port}`);
|
console.log(`server is running at http://localhost:${port}`);
|
||||||
});
|
});
|
||||||
app.server.on(handleRequest);
|
app.server.on([{
|
||||||
|
id: 'handle-all',
|
||||||
const wssApp = new WssApp();
|
func: handleRequest as any,
|
||||||
const main = () => {
|
}, {
|
||||||
console.log('Upgrade initialization started');
|
id: 'wss',
|
||||||
|
io: true,
|
||||||
app.server.server.on('upgrade', async (req, socket, head) => {
|
path: '/ws/proxy',
|
||||||
const isUpgrade = wssApp.upgrade(req, socket, head);
|
func: wssFun as WebSocketListenerFun,
|
||||||
if (isUpgrade) {
|
}]);
|
||||||
console.log('WebSocket upgrade successful for path:', req.url);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const proxyApiList = config?.apiList || [];
|
|
||||||
const proxyApi = proxyApiList.find((item) => req.url.startsWith(item.path));
|
|
||||||
|
|
||||||
if (proxyApi) {
|
|
||||||
const _u = new URL(req.url, `${proxyApi.target}`);
|
|
||||||
const options = {
|
|
||||||
hostname: _u.hostname,
|
|
||||||
port: Number(_u.port) || 80,
|
|
||||||
path: _u.pathname,
|
|
||||||
headers: req.headers,
|
|
||||||
};
|
|
||||||
|
|
||||||
const proxySocket = net.connect(options.port, options.hostname, () => {
|
|
||||||
proxySocket.write(
|
|
||||||
`GET ${options.path} HTTP/1.1\r\n` +
|
|
||||||
`Host: ${options.hostname}\r\n` +
|
|
||||||
`Connection: Upgrade\r\n` +
|
|
||||||
`Upgrade: websocket\r\n` +
|
|
||||||
`Sec-WebSocket-Key: ${req.headers['sec-websocket-key']}\r\n` +
|
|
||||||
`Sec-WebSocket-Version: ${req.headers['sec-websocket-version']}\r\n` +
|
|
||||||
`\r\n`,
|
|
||||||
);
|
|
||||||
proxySocket.pipe(socket);
|
|
||||||
socket.pipe(proxySocket);
|
|
||||||
});
|
|
||||||
|
|
||||||
proxySocket.on('error', (err) => {
|
|
||||||
console.error(`WebSocket proxy error: ${err.message}`);
|
|
||||||
socket.end();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
socket.end();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
main();
|
|
||||||
}, 1200);
|
|
||||||
|
|||||||
@@ -38,6 +38,21 @@ export const checkAuth = async (req: http.IncomingMessage, res: http.ServerRespo
|
|||||||
return { tokenUser, token };
|
return { tokenUser, token };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getLoginUserByToken = async (token: string) => {
|
||||||
|
if (token) {
|
||||||
|
token = token.replace('Bearer ', '');
|
||||||
|
}
|
||||||
|
if (!token) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let tokenUser;
|
||||||
|
try {
|
||||||
|
tokenUser = await User.verifyToken(token);
|
||||||
|
return { tokenUser, token };
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
export const getLoginUser = async (req: http.IncomingMessage) => {
|
export const getLoginUser = async (req: http.IncomingMessage) => {
|
||||||
let token = (req.headers?.['authorization'] as string) || (req.headers?.['Authorization'] as string) || '';
|
let token = (req.headers?.['authorization'] as string) || (req.headers?.['Authorization'] as string) || '';
|
||||||
const url = new URL(req.url || '', 'http://localhost');
|
const url = new URL(req.url || '', 'http://localhost');
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { useFileStore } from '@kevisual/use-config/file-store';
|
|||||||
import { minioResources } from './minio.ts';
|
import { minioResources } from './minio.ts';
|
||||||
|
|
||||||
export const config = useConfig() as any;
|
export const config = useConfig() as any;
|
||||||
export const port = config.PORT || 4005;
|
export const port = config.PORT ? Number(config.PORT) : 4005;
|
||||||
export const fileStore = useFileStore('pages');
|
export const fileStore = useFileStore('pages');
|
||||||
type ConfigType = {
|
type ConfigType = {
|
||||||
api: {
|
api: {
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
export const getTextContentType = (ext: string) => {
|
export const getTextContentType = (filePath: string, isFilePath = false) => {
|
||||||
|
let ext = filePath;
|
||||||
|
if (isFilePath) {
|
||||||
|
ext = path.extname(filePath).toLowerCase();
|
||||||
|
}
|
||||||
const textContentTypes = [
|
const textContentTypes = [
|
||||||
'.tsx',
|
'.tsx',
|
||||||
'.jsx', //
|
'.jsx', //
|
||||||
@@ -12,17 +16,21 @@ export const getTextContentType = (ext: string) => {
|
|||||||
'.json5',
|
'.json5',
|
||||||
'.pem',
|
'.pem',
|
||||||
'.crt',
|
'.crt',
|
||||||
|
'.yaml',
|
||||||
|
'.yml',
|
||||||
];
|
];
|
||||||
const include = textContentTypes.includes(ext);
|
const include = textContentTypes.includes(ext);
|
||||||
if (!include) {
|
if (include) {
|
||||||
return {};
|
return {
|
||||||
|
'content-type': 'text/plain; charset=utf-8',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const contentType = getContentTypeCore(ext);
|
const contentType = getContentTypeCore(ext);
|
||||||
if (!contentType) {
|
if (!contentType) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
'Content-Type': contentType,
|
'content-type': contentType,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
// 获取文件的 content-type
|
// 获取文件的 content-type
|
||||||
@@ -76,8 +84,8 @@ export const getContentTypeCore = (extname: string) => {
|
|||||||
'.wasm': 'application/wasm', // WebAssembly 文件
|
'.wasm': 'application/wasm', // WebAssembly 文件
|
||||||
'.pem': 'application/x-pem-file', // PEM 证书文件
|
'.pem': 'application/x-pem-file', // PEM 证书文件
|
||||||
'.crt': 'application/x-x509-ca-cert', // CRT 证书文件
|
'.crt': 'application/x-x509-ca-cert', // CRT 证书文件
|
||||||
'.yaml': 'application/x-yaml; charset=utf-8', // YAML 文件
|
'.yaml': 'application/yaml; charset=utf-8', // YAML 文件
|
||||||
'.yml': 'application/x-yaml; charset=utf-8', // YAML 文件(别名)
|
'.yml': 'application/yaml; charset=utf-8', // YAML 文件(别名)
|
||||||
'.zip': 'application/octet-stream',
|
'.zip': 'application/octet-stream',
|
||||||
};
|
};
|
||||||
return contentType[extname];
|
return contentType[extname];
|
||||||
|
|||||||
@@ -8,3 +8,7 @@ export * from './get-router.ts'
|
|||||||
export * from './get-content-type.ts'
|
export * from './get-content-type.ts'
|
||||||
|
|
||||||
export * from './utils.ts'
|
export * from './utils.ts'
|
||||||
|
|
||||||
|
export * from './pipe.ts'
|
||||||
|
|
||||||
|
export { pipeBusboy } from './pipe-busboy.ts'
|
||||||
13
src/modules/fm-manager/pipe-busboy.ts
Normal file
13
src/modules/fm-manager/pipe-busboy.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { isBun } from '@/utils/get-engine.ts';
|
||||||
|
import http from 'node:http';
|
||||||
|
export const pipeBusboy = async (req: http.IncomingMessage, res: http.ServerResponse, busboy: any) => {
|
||||||
|
if (isBun) {
|
||||||
|
// @ts-ignore
|
||||||
|
const bunRequest = req.bun.request;
|
||||||
|
const arrayBuffer = await bunRequest.arrayBuffer();
|
||||||
|
const buffer = Buffer.from(arrayBuffer);
|
||||||
|
busboy.end(buffer);
|
||||||
|
} else {
|
||||||
|
req.pipe(busboy);
|
||||||
|
}
|
||||||
|
}
|
||||||
138
src/modules/fm-manager/pipe.ts
Normal file
138
src/modules/fm-manager/pipe.ts
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
import * as http from 'http';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import { isBun } from './utils.ts';
|
||||||
|
import Stream from 'stream';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件流管道传输函数
|
||||||
|
* 将指定文件的内容通过流的方式传输给客户端响应
|
||||||
|
* @param filePath 要传输的文件路径
|
||||||
|
* @param res HTTP服务器响应对象
|
||||||
|
*/
|
||||||
|
export const pipeFileStream = (filePath: string, res: http.ServerResponse) => {
|
||||||
|
const readStream = fs.createReadStream(filePath);
|
||||||
|
if (isBun) {
|
||||||
|
// Bun环境下的流处理方式
|
||||||
|
res.pipe(readStream as any);
|
||||||
|
} else {
|
||||||
|
// Node.js标准环境下的流处理方式,end:true表示在流结束时自动关闭响应
|
||||||
|
readStream.pipe(res, { end: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用流管道传输函数
|
||||||
|
* 将可读流的数据传输给客户端响应
|
||||||
|
* @param readStream 可读流对象
|
||||||
|
* @param res HTTP服务器响应对象
|
||||||
|
*/
|
||||||
|
export const pipeStream = (readStream: fs.ReadStream, res: http.ServerResponse) => {
|
||||||
|
if (isBun) {
|
||||||
|
// Bun环境下的流处理方式
|
||||||
|
res.pipe(readStream as any);
|
||||||
|
} else {
|
||||||
|
// Node.js标准环境下的流处理方式
|
||||||
|
readStream.pipe(res, { end: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const pipeMinioStream = (minioStream: Stream.Readable, res: http.ServerResponse) => {
|
||||||
|
if (isBun) {
|
||||||
|
const chunks: Buffer[] = [];
|
||||||
|
// 监听数据到达事件,收集所有数据块
|
||||||
|
minioStream.on('data', (chunk: Buffer) => {
|
||||||
|
chunks.push(chunk);
|
||||||
|
});
|
||||||
|
// 监听数据结束事件,将收集的数据合并并发送给客户端
|
||||||
|
minioStream.on('end', () => {
|
||||||
|
const result = Buffer.concat(chunks);
|
||||||
|
res.end(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听错误事件,处理代理响应过程中的错误
|
||||||
|
minioStream.on('error', (error) => {
|
||||||
|
res.writeHead(500);
|
||||||
|
res.end(JSON.stringify({ error: error.message }));
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
minioStream.pipe(res, { end: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理响应流传输函数
|
||||||
|
* 将代理服务器返回的响应数据传输给客户端
|
||||||
|
* 处理从目标服务器收到的响应流并转发给原始客户端
|
||||||
|
* @param proxyRes 代理服务器的响应对象
|
||||||
|
* @param res HTTP服务器响应对象
|
||||||
|
*/
|
||||||
|
export const pipeProxyRes = (proxyRes: http.IncomingMessage, res: http.ServerResponse) => {
|
||||||
|
if (isBun) {
|
||||||
|
// Bun环境下需要手动收集数据并end,因为Bun的pipe机制与Node.js不同
|
||||||
|
const chunks: Buffer[] = [];
|
||||||
|
// 监听数据到达事件,收集所有数据块
|
||||||
|
proxyRes.on('data', (chunk: Buffer) => {
|
||||||
|
chunks.push(chunk);
|
||||||
|
});
|
||||||
|
if (proxyRes.url === '/api/router') {
|
||||||
|
console.log(proxyRes.url, proxyRes.statusCode);
|
||||||
|
}
|
||||||
|
// 监听数据结束事件,将收集的数据合并并发送给客户端
|
||||||
|
proxyRes.on('end', () => {
|
||||||
|
const result = Buffer.concat(chunks).toString();
|
||||||
|
res.end(result);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听错误事件,处理代理响应过程中的错误
|
||||||
|
proxyRes.on('error', (error) => {
|
||||||
|
res.writeHead(500);
|
||||||
|
res.end(JSON.stringify({ error: error.message }));
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Node.js标准环境下直接使用pipe进行流传输
|
||||||
|
proxyRes.pipe(res, { end: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理请求流传输函数
|
||||||
|
* 将客户端的请求数据传输给代理服务器
|
||||||
|
* 处理来自客户端的请求流并转发给目标服务器
|
||||||
|
* @param req 客户端的请求对象
|
||||||
|
* @param proxyReq 代理服务器的请求对象
|
||||||
|
*/
|
||||||
|
export const pipeProxyReq = async (req: http.IncomingMessage, proxyReq: http.ClientRequest, res: any) => {
|
||||||
|
if (isBun) {
|
||||||
|
try {
|
||||||
|
// @ts-ignore
|
||||||
|
const bunRequest = req.bun.request;
|
||||||
|
const contentType = req.headers['content-type'] || '';
|
||||||
|
if (contentType.includes('multipart/form-data')) {
|
||||||
|
console.log('Processing multipart/form-data');
|
||||||
|
const arrayBuffer = await bunRequest.arrayBuffer();
|
||||||
|
|
||||||
|
// 设置请求头(在写入数据之前)
|
||||||
|
proxyReq.setHeader('content-type', contentType);
|
||||||
|
proxyReq.setHeader('content-length', arrayBuffer.byteLength.toString());
|
||||||
|
|
||||||
|
// 写入数据并结束请求
|
||||||
|
if (arrayBuffer.byteLength > 0) {
|
||||||
|
proxyReq.write(Buffer.from(arrayBuffer));
|
||||||
|
}
|
||||||
|
proxyReq.end();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('Bun pipeProxyReq content-type', contentType);
|
||||||
|
// @ts-ignore
|
||||||
|
const bodyString = req.body;
|
||||||
|
bodyString && proxyReq.write(bodyString);
|
||||||
|
proxyReq.end();
|
||||||
|
} catch (error) {
|
||||||
|
proxyReq.destroy(error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Node.js标准环境下直接使用pipe进行流传输
|
||||||
|
req.pipe(proxyReq, { end: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,10 +5,12 @@ import { getUserFromRequest } from '../utils.ts';
|
|||||||
import { UserPermission, Permission } from '@kevisual/permission';
|
import { UserPermission, Permission } from '@kevisual/permission';
|
||||||
import { getLoginUser } from '@/modules/auth.ts';
|
import { getLoginUser } from '@/modules/auth.ts';
|
||||||
import busboy from 'busboy';
|
import busboy from 'busboy';
|
||||||
import { getContentType } from '../get-content-type.ts';
|
import { getContentType, getTextContentType } from '../get-content-type.ts';
|
||||||
import { OssBase } from '@kevisual/oss';
|
import { OssBase } from '@kevisual/oss';
|
||||||
import { parseSearchValue } from '@kevisual/router/browser';
|
import { parseSearchValue } from '@kevisual/router/browser';
|
||||||
import { logger } from '@/modules/logger.ts';
|
import { logger } from '@/modules/logger.ts';
|
||||||
|
import { pipeBusboy } from '../pipe-busboy.ts';
|
||||||
|
import { pipeMinioStream } from '../pipe.ts';
|
||||||
|
|
||||||
type FileList = {
|
type FileList = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -116,12 +118,14 @@ const getAiProxy = async (req: IncomingMessage, res: ServerResponse, opts: Proxy
|
|||||||
etag,
|
etag,
|
||||||
'last-modified': lastModified,
|
'last-modified': lastModified,
|
||||||
...filterMetaData,
|
...filterMetaData,
|
||||||
|
...getTextContentType(objectName, true),
|
||||||
};
|
};
|
||||||
|
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
...headers,
|
...headers,
|
||||||
});
|
});
|
||||||
objectStream.pipe(res, { end: true });
|
// objectStream.pipe(res, { end: true });
|
||||||
|
// @ts-ignore
|
||||||
|
pipeMinioStream(objectStream, res);
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Proxy request error: ${error.message}`);
|
console.error(`Proxy request error: ${error.message}`);
|
||||||
@@ -226,7 +230,7 @@ export const postProxy = async (req: IncomingMessage, res: ServerResponse, opts:
|
|||||||
end({ error: err }, '文件解析失败', 500);
|
end({ error: err }, '文件解析失败', 500);
|
||||||
});
|
});
|
||||||
|
|
||||||
req.pipe(bb);
|
pipeBusboy(req, res, bb);
|
||||||
};
|
};
|
||||||
export const getObjectName = async (req: IncomingMessage, opts?: { checkOwner?: boolean }) => {
|
export const getObjectName = async (req: IncomingMessage, opts?: { checkOwner?: boolean }) => {
|
||||||
const _u = new URL(req.url, 'http://localhost');
|
const _u = new URL(req.url, 'http://localhost');
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { addStat } from '@/modules/html/stat/index.ts';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { getTextContentType } from '@/modules/fm-manager/index.ts';
|
import { getTextContentType } from '@/modules/fm-manager/index.ts';
|
||||||
import { logger } from '@/modules/logger.ts';
|
import { logger } from '@/modules/logger.ts';
|
||||||
|
import { pipeStream } from '../pipe.ts';
|
||||||
const pipelineAsync = promisify(pipeline);
|
const pipelineAsync = promisify(pipeline);
|
||||||
|
|
||||||
export async function downloadFileFromMinio(fileUrl: string, destFile: string) {
|
export async function downloadFileFromMinio(fileUrl: string, destFile: string) {
|
||||||
@@ -74,7 +74,7 @@ export async function minioProxy(
|
|||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
...headers,
|
...headers,
|
||||||
});
|
});
|
||||||
objectStream.pipe(res, { end: true });
|
pipeStream(objectStream as any, res);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -154,7 +154,7 @@ export const httpProxy = async (
|
|||||||
res.writeHead(proxyRes.statusCode, {
|
res.writeHead(proxyRes.statusCode, {
|
||||||
...headers,
|
...headers,
|
||||||
});
|
});
|
||||||
proxyRes.pipe(res, { end: true });
|
pipeStream(proxyRes as any, res);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
proxyReq.on('error', (err) => {
|
proxyReq.on('error', (err) => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import http from 'http';
|
import http from 'node:http';
|
||||||
import { minioClient } from '@/modules/minio.ts';
|
import { minioClient } from '@/modules/minio.ts';
|
||||||
|
import { pipeMinioStream } from '../pipe.ts';
|
||||||
type ProxyInfo = {
|
type ProxyInfo = {
|
||||||
path?: string;
|
path?: string;
|
||||||
target: string;
|
target: string;
|
||||||
@@ -15,7 +16,8 @@ export const minioProxyOrigin = async (req: http.IncomingMessage, res: http.Serv
|
|||||||
objectName = objectName.slice(bucketName.length);
|
objectName = objectName.slice(bucketName.length);
|
||||||
}
|
}
|
||||||
const objectStream = await minioClient.getObject(bucketName, objectName);
|
const objectStream = await minioClient.getObject(bucketName, objectName);
|
||||||
objectStream.pipe(res);
|
// objectStream.pipe(res);
|
||||||
|
pipeMinioStream(objectStream, res);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching object from MinIO:', error);
|
console.error('Error fetching object from MinIO:', error);
|
||||||
res.statusCode = 500;
|
res.statusCode = 500;
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import { IncomingMessage } from 'node:http';
|
import { IncomingMessage } from 'node:http';
|
||||||
import http from 'node:http';
|
import http from 'node:http';
|
||||||
|
import { logger } from '../logger.ts';
|
||||||
|
export const isBun = typeof Bun !== 'undefined' && Bun?.version != null;
|
||||||
|
|
||||||
|
export const isNode = typeof process !== 'undefined' && process?.versions != null && process.versions?.node != null;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
export const isDeno = typeof Deno !== 'undefined' && Deno?.version != null && Deno?.version?.deno != null;
|
||||||
|
|
||||||
export const getUserFromRequest = (req: IncomingMessage) => {
|
export const getUserFromRequest = (req: IncomingMessage) => {
|
||||||
const url = new URL(req.url, `http://${req.headers.host}`);
|
const url = new URL(req.url, `http://${req.headers.host}`);
|
||||||
@@ -14,8 +21,8 @@ export const getUserFromRequest = (req: IncomingMessage) => {
|
|||||||
|
|
||||||
|
|
||||||
export const getDNS = (req: http.IncomingMessage) => {
|
export const getDNS = (req: http.IncomingMessage) => {
|
||||||
const hostName = req.headers.host;
|
const hostName = req.headers?.host;
|
||||||
const ip = req.socket.remoteAddress;
|
const ip = req?.socket?.remoteAddress || '';
|
||||||
return { hostName, ip };
|
return { hostName, ip };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -283,6 +283,10 @@ const commonSensitiveFiles = [
|
|||||||
"brevo",
|
"brevo",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const appSensitiveFiles = [
|
||||||
|
"App_Handlers",
|
||||||
|
"CMS",
|
||||||
|
]
|
||||||
// ========================
|
// ========================
|
||||||
// 🚨 汇总:所有敏感文件路径(供安全系统统一调用)
|
// 🚨 汇总:所有敏感文件路径(供安全系统统一调用)
|
||||||
// ========================
|
// ========================
|
||||||
@@ -297,6 +301,7 @@ export const ALL_SENSITIVE_FILES = [
|
|||||||
...wordpressFiles,
|
...wordpressFiles,
|
||||||
...secretFiles,
|
...secretFiles,
|
||||||
...gitFiles,
|
...gitFiles,
|
||||||
|
...appSensitiveFiles,
|
||||||
...commonSensitiveFiles
|
...commonSensitiveFiles
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +1,29 @@
|
|||||||
import { WebSocketServer } from 'ws';
|
|
||||||
import { nanoid } from 'nanoid';
|
|
||||||
import { WsProxyManager } from './manager.ts';
|
import { WsProxyManager } from './manager.ts';
|
||||||
import { getLoginUser } from '@/modules/auth.ts';
|
import { getLoginUserByToken } from '@/modules/auth.ts';
|
||||||
import { logger } from '../logger.ts';
|
import { logger } from '../logger.ts';
|
||||||
export const wsProxyManager = new WsProxyManager();
|
export const wsProxyManager = new WsProxyManager();
|
||||||
|
import { WebScoketListenerFun } from '@kevisual/router/src/server/server-type.ts'
|
||||||
export const upgrade = async (request: any, socket: any, head: any) => {
|
export const wssFun: WebScoketListenerFun = async (req, res) => {
|
||||||
const req = request as any;
|
// do nothing, just to enable ws upgrade event
|
||||||
const url = new URL(req.url, 'http://localhost');
|
const { id, ws, token, data, emitter } = req;
|
||||||
const id = url.searchParams.get('id');
|
logger.debug('ws proxy connected, id=', id, ' token=', token, ' data=', data);
|
||||||
if (url.pathname === '/ws/proxy') {
|
// console.log('req', req)
|
||||||
console.log('upgrade', request.url, id);
|
const { type } = data || {};
|
||||||
wss.handleUpgrade(req, socket, head, (ws) => {
|
if (type === 'registryClient') {
|
||||||
// 这里手动触发 connection 事件
|
const loginUser = await getLoginUserByToken(token);
|
||||||
// @ts-ignore
|
if (!loginUser?.tokenUser) {
|
||||||
wss.emit('connection', ws, req);
|
logger.debug('未登录,断开连接');
|
||||||
});
|
ws.send(JSON.stringify({ code: 401, message: '未登录' }));
|
||||||
return true;
|
setTimeout(() => {
|
||||||
}
|
ws.close(401, 'Unauthorized');
|
||||||
return false;
|
}, 1000);
|
||||||
};
|
|
||||||
export const wss = new WebSocketServer({
|
|
||||||
noServer: true,
|
|
||||||
path: '/ws/proxy',
|
|
||||||
});
|
|
||||||
|
|
||||||
wss.on('connection', async (ws, req) => {
|
|
||||||
console.log('connected', req.url);
|
|
||||||
const url = new URL(req.url, 'http://localhost');
|
|
||||||
const id = url?.searchParams?.get('id') || nanoid();
|
|
||||||
const loginUser = await getLoginUser(req);
|
|
||||||
if (!loginUser) {
|
|
||||||
ws.send(JSON.stringify({ code: 401, message: 'No Login' }));
|
|
||||||
ws.close();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const user = loginUser.tokenUser?.username;
|
const user = loginUser?.tokenUser?.username;
|
||||||
wsProxyManager.register(id, { user, ws });
|
const userApp = user + '-' + id;
|
||||||
|
logger.debug('注册 ws 连接', userApp);
|
||||||
|
// @ts-ignore
|
||||||
|
wsProxyManager.register(userApp, { user, ws });
|
||||||
ws.send(
|
ws.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: 'connected',
|
type: 'connected',
|
||||||
@@ -44,26 +31,22 @@ wss.on('connection', async (ws, req) => {
|
|||||||
id,
|
id,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
ws.on('message', async (event: Buffer) => {
|
emitter.once('close--' + id, () => {
|
||||||
const eventData = event.toString();
|
logger.debug('ws emitter closed');
|
||||||
if (!eventData) {
|
wsProxyManager.unregister(userApp);
|
||||||
|
});
|
||||||
|
// @ts-ignore
|
||||||
|
ws.data.userApp = userApp;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = JSON.parse(eventData);
|
// @ts-ignore
|
||||||
logger.debug('message', data);
|
const userApp = ws.data.userApp;
|
||||||
});
|
logger.debug('message', data, ' userApp=', userApp);
|
||||||
ws.on('close', () => {
|
const wsMessage = wsProxyManager.get(userApp);
|
||||||
logger.debug('ws closed');
|
if (wsMessage) {
|
||||||
wsProxyManager.unregister(id, user);
|
wsMessage.sendResponse(data);
|
||||||
});
|
} else {
|
||||||
});
|
// @ts-ignore
|
||||||
|
logger.debug('账号应用未注册,无法处理消息。未授权?', ws.data);
|
||||||
export class WssApp {
|
|
||||||
wss: WebSocketServer;
|
|
||||||
constructor() {
|
|
||||||
this.wss = wss;
|
|
||||||
}
|
|
||||||
upgrade(request: any, socket: any, head: any) {
|
|
||||||
return upgrade(request, socket, head);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,20 @@
|
|||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import { WebSocket } from 'ws';
|
import { WebSocket } from 'ws';
|
||||||
import { logger } from '../logger.ts';
|
import { logger } from '../logger.ts';
|
||||||
|
import { EventEmitter } from 'eventemitter3';
|
||||||
class WsMessage {
|
class WsMessage {
|
||||||
ws: WebSocket;
|
ws: WebSocket;
|
||||||
user?: string;
|
user?: string;
|
||||||
|
emitter: EventEmitter;;
|
||||||
constructor({ ws, user }: WssMessageOptions) {
|
constructor({ ws, user }: WssMessageOptions) {
|
||||||
this.ws = ws;
|
this.ws = ws;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
|
this.emitter = new EventEmitter();
|
||||||
|
}
|
||||||
|
async sendResponse(data: any) {
|
||||||
|
if (data.id) {
|
||||||
|
this.emitter.emit(data.id, data?.data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async sendData(data: any, opts?: { timeout?: number }) {
|
async sendData(data: any, opts?: { timeout?: number }) {
|
||||||
if (this.ws.readyState !== WebSocket.OPEN) {
|
if (this.ws.readyState !== WebSocket.OPEN) {
|
||||||
@@ -21,23 +29,17 @@ class WsMessage {
|
|||||||
});
|
});
|
||||||
logger.info('ws-proxy sendData', message);
|
logger.info('ws-proxy sendData', message);
|
||||||
this.ws.send(message);
|
this.ws.send(message);
|
||||||
|
const msg = { path: data?.path, key: data?.key, id: data?.id };
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
resolve({
|
resolve({
|
||||||
code: 500,
|
code: 500,
|
||||||
message: 'timeout',
|
message: `运行超时,执行的id: ${id},参数是${JSON.stringify(msg)}`,
|
||||||
});
|
});
|
||||||
}, timeout);
|
}, timeout);
|
||||||
this.ws.once('message', (event: Buffer) => {
|
this.emitter.once(id, (data: any) => {
|
||||||
const eventData = event.toString();
|
resolve(data);
|
||||||
if (!eventData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const data = JSON.parse(eventData);
|
|
||||||
if (data.id === id) {
|
|
||||||
resolve(data.data);
|
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -48,37 +50,29 @@ type WssMessageOptions = {
|
|||||||
};
|
};
|
||||||
export class WsProxyManager {
|
export class WsProxyManager {
|
||||||
wssMap: Map<string, WsMessage> = new Map();
|
wssMap: Map<string, WsMessage> = new Map();
|
||||||
constructor() {}
|
constructor() { }
|
||||||
getId(id: string, user?: string) {
|
|
||||||
return id + '/' + user;
|
|
||||||
}
|
|
||||||
register(id: string, opts?: { ws: WebSocket; user: string }) {
|
register(id: string, opts?: { ws: WebSocket; user: string }) {
|
||||||
const _id = this.getId(id, opts?.user || '');
|
if (this.wssMap.has(id)) {
|
||||||
if (this.wssMap.has(_id)) {
|
const value = this.wssMap.get(id);
|
||||||
const value = this.wssMap.get(_id);
|
|
||||||
if (value) {
|
if (value) {
|
||||||
value.ws.close();
|
value.ws.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('WsProxyManager register', id);
|
||||||
const value = new WsMessage({ ws: opts?.ws, user: opts?.user });
|
const value = new WsMessage({ ws: opts?.ws, user: opts?.user });
|
||||||
this.wssMap.set(_id, value);
|
this.wssMap.set(id, value);
|
||||||
}
|
}
|
||||||
unregister(id: string, user?: string) {
|
unregister(id: string) {
|
||||||
const _id = this.getId(id, user || '');
|
const value = this.wssMap.get(id);
|
||||||
const value = this.wssMap.get(_id);
|
|
||||||
if (value) {
|
if (value) {
|
||||||
value.ws.close();
|
value.ws.close();
|
||||||
}
|
}
|
||||||
this.wssMap.delete(_id);
|
this.wssMap.delete(id);
|
||||||
}
|
}
|
||||||
getIds() {
|
getIds() {
|
||||||
return Array.from(this.wssMap.keys());
|
return Array.from(this.wssMap.keys());
|
||||||
}
|
}
|
||||||
get(id: string, user?: string) {
|
get(id: string) {
|
||||||
if (user) {
|
|
||||||
const _id = this.getId(id, user);
|
|
||||||
return this.wssMap.get(_id);
|
|
||||||
}
|
|
||||||
return this.wssMap.get(id);
|
return this.wssMap.get(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,26 +11,36 @@ type ProxyOptions = {
|
|||||||
export const UserV1Proxy = async (req: IncomingMessage, res: ServerResponse, opts?: ProxyOptions) => {
|
export const UserV1Proxy = async (req: IncomingMessage, res: ServerResponse, opts?: ProxyOptions) => {
|
||||||
const { url } = req;
|
const { url } = req;
|
||||||
const { pathname } = new URL(url || '', `http://localhost`);
|
const { pathname } = new URL(url || '', `http://localhost`);
|
||||||
const [user, app, userAppKey] = pathname.split('/').slice(1);
|
let [user, app, userAppKey] = pathname.split('/').slice(1);
|
||||||
if (!user || !app || !userAppKey) {
|
if (!user || !app || !userAppKey) {
|
||||||
opts?.createNotFoundPage?.('应用未找到');
|
opts?.createNotFoundPage?.('应用未找到');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await App.handleRequest(req, res);
|
const data = await App.handleRequest(req, res);
|
||||||
const loginUser = await getLoginUser(req);
|
const loginUser = await getLoginUser(req);
|
||||||
if (!loginUser) {
|
if (!loginUser) {
|
||||||
opts?.createNotFoundPage?.('没有登录');
|
opts?.createNotFoundPage?.('没有登录');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (loginUser.tokenUser?.username !== user) {
|
const isAdmin = loginUser.tokenUser?.username === user
|
||||||
|
// TODO: 如果不是管理员,是否需要添加其他人可以访问的逻辑?
|
||||||
|
if (!isAdmin) {
|
||||||
opts?.createNotFoundPage?.('没有访问应用权限');
|
opts?.createNotFoundPage?.('没有访问应用权限');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!userAppKey.startsWith(user + '-')) {
|
||||||
|
userAppKey = user + '-' + userAppKey;
|
||||||
|
}
|
||||||
logger.debug('data', data);
|
logger.debug('data', data);
|
||||||
const client = wsProxyManager.get(userAppKey, user);
|
const client = wsProxyManager.get(userAppKey);
|
||||||
const ids = wsProxyManager.getIds();
|
const ids = wsProxyManager.getIds();
|
||||||
if (!client) {
|
if (!client) {
|
||||||
opts?.createNotFoundPage?.(`未找到应用, ${userAppKey}, ${ids.join(',')}`);
|
if (isAdmin) {
|
||||||
|
opts?.createNotFoundPage?.(`未找到应用 [${userAppKey}], 当前应用列表: ${ids.join(',')}`);
|
||||||
|
} else {
|
||||||
|
opts?.createNotFoundPage?.('应用访问失败');
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const value = await client.sendData(data);
|
const value = await client.sendData(data);
|
||||||
|
|||||||
34
src/route.ts
34
src/route.ts
@@ -17,6 +17,7 @@ export const addAuth = (app: App) => {
|
|||||||
.route({
|
.route({
|
||||||
path: 'auth',
|
path: 'auth',
|
||||||
id: 'auth',
|
id: 'auth',
|
||||||
|
description: '验证token,必须成功, 错误返回401,正确赋值到ctx.state.tokenUser',
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const token = ctx.query.token;
|
const token = ctx.query.token;
|
||||||
@@ -40,6 +41,7 @@ export const addAuth = (app: App) => {
|
|||||||
path: 'auth',
|
path: 'auth',
|
||||||
key: 'can',
|
key: 'can',
|
||||||
id: 'auth-can',
|
id: 'auth-can',
|
||||||
|
description: '验证token,可以不成功,错误不返回401,正确赋值到ctx.state.tokenUser,失败赋值null',
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
if (ctx.query?.token) {
|
if (ctx.query?.token) {
|
||||||
@@ -67,6 +69,7 @@ app
|
|||||||
id: 'auth-admin',
|
id: 'auth-admin',
|
||||||
isDebug: true,
|
isDebug: true,
|
||||||
middleware: ['auth'],
|
middleware: ['auth'],
|
||||||
|
description: '验证token,必须是admin用户, 错误返回403,正确赋值到ctx.state.tokenAdmin',
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
const tokenUser = ctx.state.tokenUser;
|
const tokenUser = ctx.state.tokenUser;
|
||||||
@@ -140,18 +143,37 @@ app
|
|||||||
|
|
||||||
app
|
app
|
||||||
.route({
|
.route({
|
||||||
path: 'test',
|
path: 'router',
|
||||||
key: 'test',
|
key: 'list',
|
||||||
|
description: '列出所有的当前的可请求的路由信息',
|
||||||
|
middleware: ['auth-can']
|
||||||
})
|
})
|
||||||
.define(async (ctx) => {
|
.define(async (ctx) => {
|
||||||
ctx.body = app.router.routes.map((item) => {
|
const tokenUser = ctx.state.tokenUser;
|
||||||
|
let isUser = !!tokenUser;
|
||||||
|
ctx.body = {
|
||||||
|
list: app.router.routes.map((item) => {
|
||||||
return {
|
return {
|
||||||
|
id: item.id,
|
||||||
path: item.path,
|
path: item.path,
|
||||||
key: item.key,
|
key: item.key,
|
||||||
description: item.description,
|
description: item.description,
|
||||||
validator: item.validator,
|
middeleware: item.middleware,
|
||||||
// schema: item.schema,
|
metadata: item.metadata,
|
||||||
};
|
};
|
||||||
});
|
}),
|
||||||
|
isUser
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.addTo(app);
|
.addTo(app);
|
||||||
|
|
||||||
|
|
||||||
|
app.route({
|
||||||
|
path: 'system',
|
||||||
|
key: 'version'
|
||||||
|
}).define(async (ctx) => {
|
||||||
|
ctx.body = {
|
||||||
|
version: '0.0.1',
|
||||||
|
name: 'KeVisual Backend System',
|
||||||
|
}
|
||||||
|
}).addTo(app);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IncomingForm } from 'formidable';
|
import Busboy from 'busboy';
|
||||||
import { checkAuth } from '../middleware/auth.ts';
|
import { checkAuth } from '../middleware/auth.ts';
|
||||||
import { router, clients, writeEvents } from '../router.ts';
|
import { router, clients, writeEvents } from '../router.ts';
|
||||||
import { error } from '../middleware/auth.ts';
|
import { error } from '../middleware/auth.ts';
|
||||||
@@ -7,26 +7,43 @@ import { useFileStore } from '@kevisual/use-config/file-store';
|
|||||||
import { app, minioClient } from '@/app.ts';
|
import { app, minioClient } from '@/app.ts';
|
||||||
import { bucketName } from '@/modules/minio.ts';
|
import { bucketName } from '@/modules/minio.ts';
|
||||||
import { getContentType } from '@/utils/get-content-type.ts';
|
import { getContentType } from '@/utils/get-content-type.ts';
|
||||||
|
import path from 'path';
|
||||||
|
import { createWriteStream } from 'fs';
|
||||||
|
import crypto from 'crypto';
|
||||||
|
import { pipeBusboy } from '@/modules/fm-manager/index.ts';
|
||||||
const cacheFilePath = useFileStore('cache-file', { needExists: true });
|
const cacheFilePath = useFileStore('cache-file', { needExists: true });
|
||||||
|
|
||||||
router.post('/api/micro-app/upload', async (req, res) => {
|
router.post('/api/micro-app/upload', async (req, res) => {
|
||||||
if (res.headersSent) return; // 如果响应已发送,不再处理
|
if (res.headersSent) return; // 如果响应已发送,不再处理
|
||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
const { tokenUser, token } = await checkAuth(req, res);
|
const { tokenUser, token } = await checkAuth(req, res);
|
||||||
if (!tokenUser) return;
|
if (!tokenUser) return;
|
||||||
//
|
|
||||||
// 使用 formidable 解析 multipart/form-data
|
// 使用 busboy 解析 multipart/form-data
|
||||||
const form = new IncomingForm({
|
const busboy = Busboy({ headers: req.headers, preservePath: true });
|
||||||
multiples: false, // 支持多文件上传
|
const fields: any = {};
|
||||||
uploadDir: cacheFilePath, // 上传文件存储目录
|
let file: any = null;
|
||||||
allowEmptyFiles: true, // 允许空
|
let filePromise: Promise<void> | null = null;
|
||||||
minFileSize: 0, // 最小文件大小
|
let bytesReceived = 0;
|
||||||
maxFiles: 1, // 最大文件数量
|
let bytesExpected = parseInt(req.headers['content-length'] || '0');
|
||||||
createDirsFromUploads: false, // 根据上传的文件夹结构创建目录
|
|
||||||
keepExtensions: true, // 保留文件
|
busboy.on('field', (fieldname, value) => {
|
||||||
hashAlgorithm: 'md5', // 文件哈希算法
|
fields[fieldname] = value;
|
||||||
});
|
});
|
||||||
form.on('progress', (bytesReceived, bytesExpected) => {
|
|
||||||
|
busboy.on('file', (fieldname, fileStream, info) => {
|
||||||
|
const { filename, encoding, mimeType } = info;
|
||||||
|
const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`);
|
||||||
|
const writeStream = createWriteStream(tempPath);
|
||||||
|
const hash = crypto.createHash('md5');
|
||||||
|
let size = 0;
|
||||||
|
|
||||||
|
filePromise = new Promise<void>((resolve, reject) => {
|
||||||
|
fileStream.on('data', (chunk) => {
|
||||||
|
bytesReceived += chunk.length;
|
||||||
|
size += chunk.length;
|
||||||
|
hash.update(chunk);
|
||||||
|
if (bytesExpected > 0) {
|
||||||
const progress = (bytesReceived / bytesExpected) * 100;
|
const progress = (bytesReceived / bytesExpected) * 100;
|
||||||
console.log(`Upload progress: ${progress.toFixed(2)}%`);
|
console.log(`Upload progress: ${progress.toFixed(2)}%`);
|
||||||
const data = {
|
const data = {
|
||||||
@@ -34,23 +51,50 @@ router.post('/api/micro-app/upload', async (req, res) => {
|
|||||||
message: `Upload progress: ${progress.toFixed(2)}%`,
|
message: `Upload progress: ${progress.toFixed(2)}%`,
|
||||||
};
|
};
|
||||||
writeEvents(req, data);
|
writeEvents(req, data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// 解析上传的文件
|
|
||||||
form.parse(req, async (err, fields, files) => {
|
fileStream.pipe(writeStream);
|
||||||
if (err) {
|
|
||||||
res.end(error(`Upload error: ${err.message}`));
|
writeStream.on('finish', () => {
|
||||||
const uploadedFiles = Array.isArray(files.file) ? files.file : [files.file];
|
file = {
|
||||||
uploadedFiles.forEach((file) => {
|
filepath: tempPath,
|
||||||
fs.unlinkSync(file.filepath);
|
originalFilename: filename,
|
||||||
|
mimetype: mimeType,
|
||||||
|
hash: hash.digest('hex'),
|
||||||
|
size: size,
|
||||||
|
};
|
||||||
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
writeStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
busboy.on('finish', async () => {
|
||||||
|
// 等待文件写入完成
|
||||||
|
if (filePromise) {
|
||||||
|
try {
|
||||||
|
await filePromise;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`File write error: ${err.message}`);
|
||||||
|
res.end(error(`File write error: ${err.message}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const clearFiles = () => {
|
const clearFiles = () => {
|
||||||
const uploadedFiles = Array.isArray(files.file) ? files.file : [files.file];
|
if (file?.filepath && fs.existsSync(file.filepath)) {
|
||||||
uploadedFiles.forEach((file) => {
|
|
||||||
fs.unlinkSync(file.filepath);
|
fs.unlinkSync(file.filepath);
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
res.end(error('No file uploaded'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let appKey, collection;
|
let appKey, collection;
|
||||||
const { appKey: _appKey, collection: _collecion } = fields;
|
const { appKey: _appKey, collection: _collecion } = fields;
|
||||||
if (Array.isArray(_appKey)) {
|
if (Array.isArray(_appKey)) {
|
||||||
@@ -68,12 +112,9 @@ router.post('/api/micro-app/upload', async (req, res) => {
|
|||||||
appKey = appKey || 'micro-app';
|
appKey = appKey || 'micro-app';
|
||||||
console.log('Appkey', appKey);
|
console.log('Appkey', appKey);
|
||||||
console.log('collection', collection);
|
console.log('collection', collection);
|
||||||
// 逐个处理每个上传的文件
|
|
||||||
const uploadedFiles = Array.isArray(files.file) ? files.file : [files.file];
|
// 处理上传的文件
|
||||||
const uploadResults = [];
|
const uploadResults = [];
|
||||||
for (let i = 0; i < uploadedFiles.length; i++) {
|
|
||||||
const file = uploadedFiles[i];
|
|
||||||
// @ts-ignore
|
|
||||||
const tempPath = file.filepath; // 文件上传时的临时路径
|
const tempPath = file.filepath; // 文件上传时的临时路径
|
||||||
const relativePath = file.originalFilename; // 保留表单中上传的文件名 (包含文件夹结构)
|
const relativePath = file.originalFilename; // 保留表单中上传的文件名 (包含文件夹结构)
|
||||||
// 比如 child2/b.txt
|
// 比如 child2/b.txt
|
||||||
@@ -92,7 +133,7 @@ router.post('/api/micro-app/upload', async (req, res) => {
|
|||||||
size: file.size,
|
size: file.size,
|
||||||
});
|
});
|
||||||
fs.unlinkSync(tempPath); // 删除临时文件
|
fs.unlinkSync(tempPath); // 删除临时文件
|
||||||
}
|
|
||||||
// 受控
|
// 受控
|
||||||
const r = await app.call({
|
const r = await app.call({
|
||||||
path: 'micro-app',
|
path: 'micro-app',
|
||||||
@@ -115,6 +156,8 @@ router.post('/api/micro-app/upload', async (req, res) => {
|
|||||||
}
|
}
|
||||||
res.end(JSON.stringify(data));
|
res.end(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pipeBusboy(req, res, busboy);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useFileStore } from '@kevisual/use-config/file-store';
|
import { useFileStore } from '@kevisual/use-config/file-store';
|
||||||
import http from 'node:http';
|
import http from 'node:http';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { IncomingForm } from 'formidable';
|
import Busboy from 'busboy';
|
||||||
import { app, minioClient } from '@/app.ts';
|
import { app, minioClient } from '@/app.ts';
|
||||||
|
|
||||||
import { bucketName } from '@/modules/minio.ts';
|
import { bucketName } from '@/modules/minio.ts';
|
||||||
@@ -11,6 +11,9 @@ import { getContainerById } from '@/routes/container/module/get-container-file.t
|
|||||||
import { router, error, checkAuth, writeEvents } from './router.ts';
|
import { router, error, checkAuth, writeEvents } from './router.ts';
|
||||||
import './index.ts';
|
import './index.ts';
|
||||||
import { handleRequest as PageProxy } from './page-proxy.ts';
|
import { handleRequest as PageProxy } from './page-proxy.ts';
|
||||||
|
import path from 'path';
|
||||||
|
import { createWriteStream } from 'fs';
|
||||||
|
import { pipeBusboy } from '@/modules/fm-manager/pipe-busboy.ts';
|
||||||
const cacheFilePath = useFileStore('cache-file', { needExists: true });
|
const cacheFilePath = useFileStore('cache-file', { needExists: true });
|
||||||
|
|
||||||
router.get('/api/app/upload', async (req, res) => {
|
router.get('/api/app/upload', async (req, res) => {
|
||||||
@@ -23,17 +26,28 @@ router.post('/api/app/upload', async (req, res) => {
|
|||||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||||
const { tokenUser, token } = await checkAuth(req, res);
|
const { tokenUser, token } = await checkAuth(req, res);
|
||||||
if (!tokenUser) return;
|
if (!tokenUser) return;
|
||||||
// 使用 formidable 解析 multipart/form-data
|
|
||||||
const form = new IncomingForm({
|
// 使用 busboy 解析 multipart/form-data
|
||||||
multiples: true, // 支持多文件上传
|
const busboy = Busboy({ headers: req.headers, preservePath: true });
|
||||||
uploadDir: cacheFilePath, // 上传文件存储目录
|
const fields: any = {};
|
||||||
allowEmptyFiles: true, // 允许空
|
const files: any = [];
|
||||||
minFileSize: 0, // 最小文件大小
|
const filePromises: Promise<void>[] = [];
|
||||||
createDirsFromUploads: false, // 根据上传的文件夹结构创建目录
|
let bytesReceived = 0;
|
||||||
keepExtensions: true, // 保留文件
|
let bytesExpected = parseInt(req.headers['content-length'] || '0');
|
||||||
hashAlgorithm: 'md5', // 文件哈希算法
|
|
||||||
|
busboy.on('field', (fieldname, value) => {
|
||||||
|
fields[fieldname] = value;
|
||||||
});
|
});
|
||||||
form.on('progress', (bytesReceived, bytesExpected) => {
|
|
||||||
|
busboy.on('file', (fieldname, fileStream, info) => {
|
||||||
|
const { filename, encoding, mimeType } = info;
|
||||||
|
const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`);
|
||||||
|
const writeStream = createWriteStream(tempPath);
|
||||||
|
|
||||||
|
const filePromise = new Promise<void>((resolve, reject) => {
|
||||||
|
fileStream.on('data', (chunk) => {
|
||||||
|
bytesReceived += chunk.length;
|
||||||
|
if (bytesExpected > 0) {
|
||||||
const progress = (bytesReceived / bytesExpected) * 100;
|
const progress = (bytesReceived / bytesExpected) * 100;
|
||||||
console.log(`Upload progress: ${progress.toFixed(2)}%`);
|
console.log(`Upload progress: ${progress.toFixed(2)}%`);
|
||||||
const data = {
|
const data = {
|
||||||
@@ -41,23 +55,51 @@ router.post('/api/app/upload', async (req, res) => {
|
|||||||
message: `Upload progress: ${progress.toFixed(2)}%`,
|
message: `Upload progress: ${progress.toFixed(2)}%`,
|
||||||
};
|
};
|
||||||
writeEvents(req, data);
|
writeEvents(req, data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// 解析上传的文件
|
|
||||||
form.parse(req, async (err, fields, files) => {
|
fileStream.pipe(writeStream);
|
||||||
if (err) {
|
|
||||||
res.end(error(`Upload error: ${err.message}`));
|
writeStream.on('finish', () => {
|
||||||
const uploadedFiles = Array.isArray(files.file) ? files.file : [files.file];
|
files.push({
|
||||||
uploadedFiles.forEach((file) => {
|
filepath: tempPath,
|
||||||
fs.unlinkSync(file.filepath);
|
originalFilename: filename,
|
||||||
|
mimetype: mimeType,
|
||||||
});
|
});
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
writeStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
filePromises.push(filePromise);
|
||||||
|
});
|
||||||
|
|
||||||
|
busboy.on('finish', async () => {
|
||||||
|
// 等待所有文件写入完成
|
||||||
|
try {
|
||||||
|
await Promise.all(filePromises);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`File write error: ${err.message}`);
|
||||||
|
res.end(error(`File write error: ${err.message}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const clearFiles = () => {
|
const clearFiles = () => {
|
||||||
const uploadedFiles = Array.isArray(files.file) ? files.file : [files.file];
|
files.forEach((file: any) => {
|
||||||
uploadedFiles.forEach((file) => {
|
if (file?.filepath && fs.existsSync(file.filepath)) {
|
||||||
fs.unlinkSync(file.filepath);
|
fs.unlinkSync(file.filepath);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 检查是否有文件上传
|
||||||
|
if (files.length === 0) {
|
||||||
|
res.end(error('files is required'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let appKey,
|
let appKey,
|
||||||
version,
|
version,
|
||||||
username = '';
|
username = '';
|
||||||
@@ -99,11 +141,9 @@ router.post('/api/app/upload', async (req, res) => {
|
|||||||
console.log('Appkey', appKey, version);
|
console.log('Appkey', appKey, version);
|
||||||
|
|
||||||
// 逐个处理每个上传的文件
|
// 逐个处理每个上传的文件
|
||||||
const uploadedFiles = Array.isArray(files.file) ? files.file : [files.file];
|
|
||||||
const uploadResults = [];
|
const uploadResults = [];
|
||||||
for (let i = 0; i < uploadedFiles.length; i++) {
|
for (let i = 0; i < files.length; i++) {
|
||||||
const file = uploadedFiles[i];
|
const file = files[i];
|
||||||
// @ts-ignore
|
|
||||||
const tempPath = file.filepath; // 文件上传时的临时路径
|
const tempPath = file.filepath; // 文件上传时的临时路径
|
||||||
const relativePath = file.originalFilename; // 保留表单中上传的文件名 (包含文件夹结构)
|
const relativePath = file.originalFilename; // 保留表单中上传的文件名 (包含文件夹结构)
|
||||||
// 比如 child2/b.txt
|
// 比如 child2/b.txt
|
||||||
@@ -144,6 +184,8 @@ router.post('/api/app/upload', async (req, res) => {
|
|||||||
}
|
}
|
||||||
res.end(JSON.stringify(data));
|
res.end(JSON.stringify(data));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pipeBusboy(req, res, busboy);
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/api/container/file/:id', async (req, res) => {
|
router.get('/api/container/file/:id', async (req, res) => {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { bucketName } from '@/modules/minio.ts';
|
|||||||
import { getLoginUser } from '../middleware/auth.ts';
|
import { getLoginUser } from '../middleware/auth.ts';
|
||||||
import { BucketItemStat } from 'minio';
|
import { BucketItemStat } from 'minio';
|
||||||
import { UserPermission, Permission } from '@kevisual/permission';
|
import { UserPermission, Permission } from '@kevisual/permission';
|
||||||
|
import { pipeMinioStream } from '@/modules/fm-manager/index.ts';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过滤 metaData 中的 key, 去除 password, accesskey, secretkey,
|
* 过滤 metaData 中的 key, 去除 password, accesskey, secretkey,
|
||||||
@@ -101,5 +102,6 @@ export const authMinio = async (req: IncomingMessage, res: ServerResponse, objec
|
|||||||
});
|
});
|
||||||
const objectStream = await minioClient.getObject(bucketName, objectName);
|
const objectStream = await minioClient.getObject(bucketName, objectName);
|
||||||
|
|
||||||
objectStream.pipe(res, { end: true });
|
// objectStream.pipe(res, { end: true });
|
||||||
|
pipeMinioStream(objectStream, res);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getDNS, isIpv4OrIpv6, isLocalhost } from '../modules/fm-manager/index.ts';
|
import { getDNS, isIpv4OrIpv6, isLocalhost, pipeFileStream, pipeProxyReq, pipeProxyRes } from '../modules/fm-manager/index.ts';
|
||||||
import http from 'node:http';
|
import http from 'node:http';
|
||||||
import https from 'node:https';
|
import https from 'node:https';
|
||||||
import { UserApp } from '../modules/user-app/index.ts';
|
import { UserApp } from '../modules/user-app/index.ts';
|
||||||
@@ -15,6 +15,7 @@ import { logger } from '../modules/logger.ts';
|
|||||||
import { UserV1Proxy } from '../modules/ws-proxy/proxy.ts';
|
import { UserV1Proxy } from '../modules/ws-proxy/proxy.ts';
|
||||||
import { hasBadUser, userIsBanned, appIsBanned, userPathIsBanned } from '@/modules/off/index.ts';
|
import { hasBadUser, userIsBanned, appIsBanned, userPathIsBanned } from '@/modules/off/index.ts';
|
||||||
import { robotsTxt } from '@/modules/html/index.ts';
|
import { robotsTxt } from '@/modules/html/index.ts';
|
||||||
|
import { isBun } from '@/utils/get-engine.ts';
|
||||||
const domain = config?.proxy?.domain;
|
const domain = config?.proxy?.domain;
|
||||||
const allowedOrigins = config?.proxy?.allowedOrigin || [];
|
const allowedOrigins = config?.proxy?.allowedOrigin || [];
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ const checkNotAuthPath = (user, app) => {
|
|||||||
const forBadUser = (req: http.IncomingMessage, res: http.ServerResponse) => {
|
const forBadUser = (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||||
// TODO: 记录日志,封禁IP等操作
|
// TODO: 记录日志,封禁IP等操作
|
||||||
const dns = getDNS(req);
|
const dns = getDNS(req);
|
||||||
logger.warn(`Bad user access from IP: ${dns.ip}, Host: ${dns.hostName}, URL: ${req.url}`);
|
logger.warn(`forBadUser: Bad user access from IP: ${dns.ip}, Host: ${dns.hostName}, URL: ${req.url}`);
|
||||||
// 这里可以添加更多的处理逻辑,比如封禁IP等
|
// 这里可以添加更多的处理逻辑,比如封禁IP等
|
||||||
}
|
}
|
||||||
export const handleRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
export const handleRequest = async (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||||
@@ -109,7 +110,8 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
// 将代理服务器的响应头和状态码返回给客户端
|
// 将代理服务器的响应头和状态码返回给客户端
|
||||||
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
res.writeHead(proxyRes.statusCode, proxyRes.headers);
|
||||||
// 将代理响应流写入客户端响应
|
// 将代理响应流写入客户端响应
|
||||||
proxyRes.pipe(res, { end: true });
|
// proxyRes.pipe(res, { end: true });
|
||||||
|
pipeProxyRes(proxyRes, res);
|
||||||
});
|
});
|
||||||
// 处理代理请求的错误事件
|
// 处理代理请求的错误事件
|
||||||
proxyReq.on('error', (err) => {
|
proxyReq.on('error', (err) => {
|
||||||
@@ -118,7 +120,8 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
res.write(`Proxy request error: ${err.message}`);
|
res.write(`Proxy request error: ${err.message}`);
|
||||||
});
|
});
|
||||||
// 处理 POST 请求的请求体(传递数据到目标服务器)
|
// 处理 POST 请求的请求体(传递数据到目标服务器)
|
||||||
req.pipe(proxyReq, { end: true });
|
// req.pipe(proxyReq, { end: true });
|
||||||
|
pipeProxyReq(req, proxyReq, res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (req.url.startsWith('/api') || req.url.startsWith('/v1')) {
|
if (req.url.startsWith('/api') || req.url.startsWith('/v1')) {
|
||||||
@@ -132,7 +135,7 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
const _orings = allowedOrigins || [];
|
const _orings = allowedOrigins || [];
|
||||||
const host = dns.hostName;
|
const host = dns.hostName;
|
||||||
if (
|
if (
|
||||||
_orings.some((item) => {
|
host && _orings.some((item) => {
|
||||||
return host.includes(item);
|
return host.includes(item);
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
@@ -142,11 +145,9 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
|
|
||||||
let user, app;
|
let user, app;
|
||||||
let domainApp = false;
|
let domainApp = false;
|
||||||
if (isLocalhost(dns.hostName)) {
|
const isDev = isLocalhost(dns.hostName);
|
||||||
// 本地开发环境 测试
|
if (isDev) {
|
||||||
// user = 'root';
|
console.debug('开发环境访问:', req.url, 'Host:', dns.hostName);
|
||||||
// app = 'codeflow';
|
|
||||||
// domainApp = true;
|
|
||||||
} else {
|
} else {
|
||||||
if (isIpv4OrIpv6(dns.hostName)) {
|
if (isIpv4OrIpv6(dns.hostName)) {
|
||||||
// 打印出 req.url 和错误信息
|
// 打印出 req.url 和错误信息
|
||||||
@@ -184,14 +185,9 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
const url = pathname;
|
const url = pathname;
|
||||||
if (!domainApp && noProxyUrl.includes(url)) {
|
if (!domainApp && noProxyUrl.includes(url)) {
|
||||||
if (url === '/') {
|
if (url === '/') {
|
||||||
// TODO: 获取一下登陆用户,如果没有登陆用户,重定向到ai-chat页面
|
|
||||||
// 重定向到
|
|
||||||
// res.writeHead(302, { Location: home });
|
|
||||||
// return res.end();
|
|
||||||
rediretHome(req, res);
|
rediretHome(req, res);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 不是域名代理,且是在不代理的url当中
|
|
||||||
res.write('No proxy for this URL\n');
|
res.write('No proxy for this URL\n');
|
||||||
return res.end();
|
return res.end();
|
||||||
}
|
}
|
||||||
@@ -205,7 +201,7 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
res.end(robotsTxt);
|
res.end(robotsTxt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(userPathIsBanned(_user)) {
|
if (userPathIsBanned(_user)) {
|
||||||
logger.warn(`Bad user access from IP: ${dns.ip}, Host: ${dns.hostName}, URL: ${req.url}`);
|
logger.warn(`Bad user access from IP: ${dns.ip}, Host: ${dns.hostName}, URL: ${req.url}`);
|
||||||
} else {
|
} else {
|
||||||
console.log('urls error', urls, 'originUrl:', url);
|
console.log('urls error', urls, 'originUrl:', url);
|
||||||
@@ -259,7 +255,7 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
let isExist = await userApp.getExist();
|
let isExist = await userApp.getExist();
|
||||||
logger.debug('userApp', userApp, isExist);
|
logger.debug('userApp', userApp, isExist);
|
||||||
if (userIsBanned(user) || appIsBanned(app)) {
|
if (userIsBanned(user) || appIsBanned(app)) {
|
||||||
forBadUser(req, res);
|
if (!isDev) forBadUser(req, res);
|
||||||
return createErrorPage();
|
return createErrorPage();
|
||||||
}
|
}
|
||||||
if (!isExist) {
|
if (!isExist) {
|
||||||
@@ -314,7 +310,7 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
if (!proxyUrl.startsWith('http')) {
|
if (!proxyUrl.startsWith('http')) {
|
||||||
return createNotFoundPage('Invalid proxy url');
|
return createNotFoundPage('Invalid proxy url');
|
||||||
}
|
}
|
||||||
console.log('proxyUrl', appFileUrl, proxyUrl);
|
console.log('proxyUrl indexFile', appFileUrl, proxyUrl);
|
||||||
httpProxy(req, res, {
|
httpProxy(req, res, {
|
||||||
proxyUrl,
|
proxyUrl,
|
||||||
userApp,
|
userApp,
|
||||||
@@ -332,8 +328,7 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
const filePath = path.join(fileStore, indexFilePath);
|
const filePath = path.join(fileStore, indexFilePath);
|
||||||
if (!userApp.fileCheck(filePath)) {
|
if (!userApp.fileCheck(filePath)) {
|
||||||
res.writeHead(500, { 'Content-Type': 'text/html; charset=utf-8', tips: 'App Cache expired, Please refresh' });
|
res.writeHead(500, { 'Content-Type': 'text/html; charset=utf-8', tips: 'App Cache expired, Please refresh' });
|
||||||
res.write(createRefreshHtml(user, app));
|
res.end(createRefreshHtml(user, app));
|
||||||
res.end();
|
|
||||||
await userApp.clearCacheData();
|
await userApp.clearCacheData();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -384,17 +379,14 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
headers.set('Content-Type', contentType);
|
headers.set('Content-Type', contentType);
|
||||||
headers.set('Cache-Control', isHTML ? 'no-cache' : 'public, max-age=3600'); // 设置缓存时间为 1 小时
|
headers.set('Cache-Control', isHTML ? 'no-cache' : 'public, max-age=3600'); // 设置缓存时间为 1 小时
|
||||||
headers.set('ETag', eTag);
|
headers.set('ETag', eTag);
|
||||||
res?.setHeaders?.(headers);
|
res.writeHead(200, Object.fromEntries(headers));
|
||||||
if (isHTML) {
|
if (isHTML) {
|
||||||
const newHtml = await getTextFromStreamAndAddStat(fs.createReadStream(filePath));
|
const newHtml = await getTextFromStreamAndAddStat(fs.createReadStream(filePath));
|
||||||
resContent = newHtml.html;
|
resContent = newHtml.html;
|
||||||
headers.set('Content-Length', newHtml.contentLength.toString());
|
headers.set('Content-Length', newHtml.contentLength.toString());
|
||||||
res.writeHead(200);
|
|
||||||
res.end(resContent);
|
res.end(resContent);
|
||||||
} else {
|
} else {
|
||||||
res.writeHead(200);
|
pipeFileStream(filePath, res);
|
||||||
const readStream = fs.createReadStream(filePath);
|
|
||||||
readStream.pipe(res);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -402,3 +394,4 @@ export const handleRequest = async (req: http.IncomingMessage, res: http.ServerR
|
|||||||
console.error('getFile error', error);
|
console.error('getFile error', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useFileStore } from '@kevisual/use-config/file-store';
|
import { useFileStore } from '@kevisual/use-config/file-store';
|
||||||
import { checkAuth, error, router, writeEvents, getKey, getTaskId } from '../router.ts';
|
import { checkAuth, error, router, writeEvents, getKey, getTaskId } from '../router.ts';
|
||||||
import { IncomingForm } from 'formidable';
|
import Busboy from 'busboy';
|
||||||
import { app, oss } from '@/app.ts';
|
import { app, oss } from '@/app.ts';
|
||||||
|
|
||||||
import { getContentType } from '@/utils/get-content-type.ts';
|
import { getContentType } from '@/utils/get-content-type.ts';
|
||||||
@@ -8,6 +8,9 @@ import { User } from '@/models/user.ts';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { ConfigModel } from '@/routes/config/models/model.ts';
|
import { ConfigModel } from '@/routes/config/models/model.ts';
|
||||||
import { validateDirectory } from './util.ts';
|
import { validateDirectory } from './util.ts';
|
||||||
|
import path from 'path';
|
||||||
|
import { createWriteStream } from 'fs';
|
||||||
|
import { pipeBusboy } from '@/modules/fm-manager/index.ts';
|
||||||
|
|
||||||
const cacheFilePath = useFileStore('cache-file', { needExists: true });
|
const cacheFilePath = useFileStore('cache-file', { needExists: true });
|
||||||
|
|
||||||
@@ -23,35 +26,70 @@ router.post('/api/s1/resources/upload/chunk', async (req, res) => {
|
|||||||
const url = new URL(req.url || '', 'http://localhost');
|
const url = new URL(req.url || '', 'http://localhost');
|
||||||
const share = !!url.searchParams.get('public');
|
const share = !!url.searchParams.get('public');
|
||||||
const noCheckAppFiles = !!url.searchParams.get('noCheckAppFiles');
|
const noCheckAppFiles = !!url.searchParams.get('noCheckAppFiles');
|
||||||
// 使用 formidable 解析 multipart/form-data
|
|
||||||
const form = new IncomingForm({
|
|
||||||
multiples: false, // 改为单文件上传
|
|
||||||
uploadDir: cacheFilePath, // 上传文件存储目录
|
|
||||||
allowEmptyFiles: true, // 允许空
|
|
||||||
minFileSize: 0, // 最小文件大小
|
|
||||||
createDirsFromUploads: false, // 根据上传的文件夹结构创建目录
|
|
||||||
keepExtensions: true, // 保留文件拓展名
|
|
||||||
hashAlgorithm: 'md5', // 文件哈希算法
|
|
||||||
});
|
|
||||||
const taskId = getTaskId(req);
|
const taskId = getTaskId(req);
|
||||||
const finalFilePath = `${cacheFilePath}/${taskId}`;
|
const finalFilePath = `${cacheFilePath}/${taskId}`;
|
||||||
if (!taskId) {
|
if (!taskId) {
|
||||||
res.end(error('taskId is required'));
|
res.end(error('taskId is required'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 解析上传的文件
|
|
||||||
form.parse(req, async (err, fields, files) => {
|
// 使用 busboy 解析 multipart/form-data
|
||||||
const file = Array.isArray(files.file) ? files.file[0] : files.file;
|
const busboy = Busboy({ headers: req.headers, preservePath: true });
|
||||||
|
const fields: any = {};
|
||||||
|
let file: any = null;
|
||||||
|
let tempPath = '';
|
||||||
|
let filePromise: Promise<void> | null = null;
|
||||||
|
|
||||||
|
busboy.on('field', (fieldname, value) => {
|
||||||
|
fields[fieldname] = value;
|
||||||
|
});
|
||||||
|
|
||||||
|
busboy.on('file', (fieldname, fileStream, info) => {
|
||||||
|
const { filename, encoding, mimeType } = info;
|
||||||
|
tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`);
|
||||||
|
const writeStream = createWriteStream(tempPath);
|
||||||
|
|
||||||
|
filePromise = new Promise<void>((resolve, reject) => {
|
||||||
|
fileStream.pipe(writeStream);
|
||||||
|
|
||||||
|
writeStream.on('finish', () => {
|
||||||
|
file = {
|
||||||
|
filepath: tempPath,
|
||||||
|
originalFilename: filename,
|
||||||
|
mimetype: mimeType,
|
||||||
|
};
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
writeStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
busboy.on('finish', async () => {
|
||||||
|
// 等待文件写入完成
|
||||||
|
if (filePromise) {
|
||||||
|
try {
|
||||||
|
await filePromise;
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`File write error: ${err.message}`);
|
||||||
|
res.end(error(`File write error: ${err.message}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
const clearFiles = () => {
|
const clearFiles = () => {
|
||||||
if (file) {
|
if (tempPath && fs.existsSync(tempPath)) {
|
||||||
fs.unlinkSync(file.filepath);
|
fs.unlinkSync(tempPath);
|
||||||
|
}
|
||||||
|
if (fs.existsSync(finalFilePath)) {
|
||||||
fs.unlinkSync(finalFilePath);
|
fs.unlinkSync(finalFilePath);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (err) {
|
if (!file) {
|
||||||
res.end(error(`Upload error: ${err.message}`));
|
res.end(error('No file uploaded'));
|
||||||
clearFiles();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,9 +107,7 @@ router.post('/api/s1/resources/upload/chunk', async (req, res) => {
|
|||||||
clearFiles();
|
clearFiles();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const tempPath = file.filepath;
|
|
||||||
const relativePath = file.originalFilename;
|
const relativePath = file.originalFilename;
|
||||||
// Append chunk to the final file
|
|
||||||
|
|
||||||
const writeStream = fs.createWriteStream(finalFilePath, { flags: 'a' });
|
const writeStream = fs.createWriteStream(finalFilePath, { flags: 'a' });
|
||||||
const readStream = fs.createReadStream(tempPath);
|
const readStream = fs.createReadStream(tempPath);
|
||||||
@@ -195,4 +231,6 @@ router.post('/api/s1/resources/upload/chunk', async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pipeBusboy(req, res, busboy);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { useFileStore } from '@kevisual/use-config/file-store';
|
import { useFileStore } from '@kevisual/use-config/file-store';
|
||||||
import { checkAuth, error, router, writeEvents, getKey } from '../router.ts';
|
import { checkAuth, error, router, writeEvents, getKey } from '../router.ts';
|
||||||
import { IncomingForm } from 'formidable';
|
import Busboy from 'busboy';
|
||||||
import { app, minioClient } from '@/app.ts';
|
import { app, minioClient } from '@/app.ts';
|
||||||
|
|
||||||
import { bucketName } from '@/modules/minio.ts';
|
import { bucketName } from '@/modules/minio.ts';
|
||||||
import { getContentType } from '@/utils/get-content-type.ts';
|
import { getContentType } from '@/utils/get-content-type.ts';
|
||||||
import { User } from '@/models/user.ts';
|
import { User } from '@/models/user.ts';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
import { createWriteStream } from 'fs';
|
||||||
|
import { pipeBusboy } from '@/modules/fm-manager/pipe-busboy.ts';
|
||||||
import { ConfigModel } from '@/routes/config/models/model.ts';
|
import { ConfigModel } from '@/routes/config/models/model.ts';
|
||||||
import { validateDirectory } from './util.ts';
|
import { validateDirectory } from './util.ts';
|
||||||
import { pick } from 'lodash-es';
|
import { pick } from 'lodash-es';
|
||||||
@@ -103,17 +106,25 @@ router.post('/api/s1/resources/upload', async (req, res) => {
|
|||||||
const share = !!url.searchParams.get('public');
|
const share = !!url.searchParams.get('public');
|
||||||
const meta = parseIfJson(url.searchParams.get('meta'));
|
const meta = parseIfJson(url.searchParams.get('meta'));
|
||||||
const noCheckAppFiles = !!url.searchParams.get('noCheckAppFiles');
|
const noCheckAppFiles = !!url.searchParams.get('noCheckAppFiles');
|
||||||
// 使用 formi dable 解析 multipart/form-data
|
// 使用 busboy 解析 multipart/form-data
|
||||||
const form = new IncomingForm({
|
const busboy = Busboy({ headers: req.headers, preservePath: true });
|
||||||
multiples: true, // 支持多文件上传
|
const fields: any = {};
|
||||||
uploadDir: cacheFilePath, // 上传文件存储目录
|
const files: any[] = [];
|
||||||
allowEmptyFiles: true, // 允许空
|
const filePromises: Promise<void>[] = [];
|
||||||
minFileSize: 0, // 最小文件大小
|
let bytesReceived = 0;
|
||||||
createDirsFromUploads: false, // 根据上传的文件夹结构创建目录
|
let bytesExpected = parseInt(req.headers['content-length'] || '0');
|
||||||
keepExtensions: true, // 保留文件拓展名
|
busboy.on('field', (fieldname, value) => {
|
||||||
hashAlgorithm: 'md5', // 文件哈希算法
|
fields[fieldname] = value;
|
||||||
});
|
});
|
||||||
form.on('progress', (bytesReceived, bytesExpected) => {
|
|
||||||
|
busboy.on('file', (fieldname, fileStream, info) => {
|
||||||
|
const { filename, encoding, mimeType } = info;
|
||||||
|
const tempPath = path.join(cacheFilePath, `${Date.now()}-${Math.random().toString(36).substring(7)}`);
|
||||||
|
const writeStream = createWriteStream(tempPath);
|
||||||
|
const filePromise = new Promise<void>((resolve, reject) => {
|
||||||
|
fileStream.on('data', (chunk) => {
|
||||||
|
bytesReceived += chunk.length;
|
||||||
|
if (bytesExpected > 0) {
|
||||||
const progress = (bytesReceived / bytesExpected) * 100;
|
const progress = (bytesReceived / bytesExpected) * 100;
|
||||||
const data = {
|
const data = {
|
||||||
progress: progress.toFixed(2),
|
progress: progress.toFixed(2),
|
||||||
@@ -121,23 +132,51 @@ router.post('/api/s1/resources/upload', async (req, res) => {
|
|||||||
};
|
};
|
||||||
console.log('progress-upload', data);
|
console.log('progress-upload', data);
|
||||||
writeEvents(req, data);
|
writeEvents(req, data);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// 解析上传的文件
|
|
||||||
form.parse(req, async (err, fields, files) => {
|
fileStream.pipe(writeStream);
|
||||||
|
|
||||||
|
writeStream.on('finish', () => {
|
||||||
|
files.push({
|
||||||
|
filepath: tempPath,
|
||||||
|
originalFilename: filename,
|
||||||
|
mimetype: mimeType,
|
||||||
|
});
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
writeStream.on('error', (err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
filePromises.push(filePromise);
|
||||||
|
});
|
||||||
|
|
||||||
|
busboy.on('finish', async () => {
|
||||||
|
// 等待所有文件写入完成
|
||||||
|
try {
|
||||||
|
await Promise.all(filePromises);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(`File write error: ${err.message}`);
|
||||||
|
res.end(error(`File write error: ${err.message}`));
|
||||||
|
return;
|
||||||
|
}
|
||||||
const clearFiles = () => {
|
const clearFiles = () => {
|
||||||
const uploadedFiles = Array.isArray(files.file) ? files.file : [files.file];
|
files.forEach((file) => {
|
||||||
uploadedFiles.forEach((file) => {
|
|
||||||
if (file?.filepath && fs.existsSync(file.filepath)) {
|
if (file?.filepath && fs.existsSync(file.filepath)) {
|
||||||
fs.unlinkSync(file.filepath);
|
fs.unlinkSync(file.filepath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
if (err) {
|
|
||||||
logger.error(`Upload error: ${err.message}`);
|
// 检查是否有文件上传
|
||||||
res.end(error(`Upload error: ${err.message}`));
|
if (files.length === 0) {
|
||||||
clearFiles();
|
res.end(error('files is required'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { appKey, version, username, directory, description } = getKey(fields, ['appKey', 'version', 'username', 'directory', 'description']);
|
let { appKey, version, username, directory, description } = getKey(fields, ['appKey', 'version', 'username', 'directory', 'description']);
|
||||||
let uid = tokenUser.id;
|
let uid = tokenUser.id;
|
||||||
if (username) {
|
if (username) {
|
||||||
@@ -170,7 +209,7 @@ router.post('/api/s1/resources/upload', async (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 逐个处理每个上传的文件
|
// 逐个处理每个上传的文件
|
||||||
const uploadedFiles = Array.isArray(files.file) ? files.file : [files.file];
|
const uploadedFiles = files;
|
||||||
logger.info(
|
logger.info(
|
||||||
'upload files',
|
'upload files',
|
||||||
uploadedFiles.map((item) => {
|
uploadedFiles.map((item) => {
|
||||||
@@ -244,4 +283,6 @@ router.post('/api/s1/resources/upload', async (req, res) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pipeBusboy(req, res, busboy);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { router } from '@/app.ts';
|
|||||||
import http from 'http';
|
import http from 'http';
|
||||||
import { useContextKey } from '@kevisual/context';
|
import { useContextKey } from '@kevisual/context';
|
||||||
import { checkAuth, error } from './middleware/auth.ts';
|
import { checkAuth, error } from './middleware/auth.ts';
|
||||||
import formidable from 'formidable';
|
|
||||||
export { router, checkAuth, error };
|
export { router, checkAuth, error };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,7 +67,7 @@ export const deleteOldClients = () => {
|
|||||||
* @param parseKeys 需要解析的键
|
* @param parseKeys 需要解析的键
|
||||||
* @returns 解析后的数据
|
* @returns 解析后的数据
|
||||||
*/
|
*/
|
||||||
export const getKey = (fields: formidable.Fields<string>, parseKeys: string[]) => {
|
export const getKey = (fields: Record<string, any>, parseKeys: string[]) => {
|
||||||
let value: Record<string, any> = {};
|
let value: Record<string, any> = {};
|
||||||
for (const key of parseKeys) {
|
for (const key of parseKeys) {
|
||||||
const v = fields[key];
|
const v = fields[key];
|
||||||
|
|||||||
6
src/utils/get-engine.ts
Normal file
6
src/utils/get-engine.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export const isBun = typeof Bun !== 'undefined' && Bun?.version != null;
|
||||||
|
|
||||||
|
export const isNode = typeof process !== 'undefined' && process?.versions != null && process.versions?.node != null;
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
export const isDeno = typeof Deno !== 'undefined' && Deno?.version != null && Deno?.version?.deno != null;
|
||||||
3
src/utils/sleep.ts
Normal file
3
src/utils/sleep.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const sleep = (ms: number = 1000) => {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user