mirror of
https://github.com/whyour/qinglong.git
synced 2026-08-12 03:10:48 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
437a849c2a | ||
|
|
8f7261dd50 | ||
|
|
76fa82c3a7 | ||
|
|
46c9774efa | ||
|
|
1bc64a23e3 | ||
|
|
cc9a17afa3 | ||
|
|
fcbcfc3a03 | ||
|
|
0144f3b131 | ||
|
|
518436d5ca | ||
|
|
1961a6b913 | ||
|
|
5edebdd5f3 | ||
|
|
48edf2c212 | ||
|
|
9b16dca9da | ||
|
|
9479c2498c | ||
|
|
4a18bcabe2 | ||
|
|
34f690c53d | ||
|
|
e70cd6579f | ||
|
|
99c047e9c7 | ||
|
|
978ae326f8 | ||
|
|
b01f27f2d3 | ||
|
|
4d34e0dd96 | ||
|
|
9b0065e533 | ||
|
|
34a51feee9 | ||
|
|
679091de59 | ||
|
|
c6220cb920 | ||
|
|
633b30269c | ||
|
|
8ad26267d8 | ||
|
|
7cfb125682 | ||
|
|
a2dc5de5ce | ||
|
|
4f41ff29ec | ||
|
|
13d95b8c19 | ||
|
|
335c13ab44 | ||
|
|
015cdc10a7 | ||
|
|
a5075ab28f | ||
|
|
2e3c3274c7 | ||
|
|
443c581955 | ||
|
|
5e41faf590 | ||
|
|
0579fb83d3 | ||
|
|
2864845d5b | ||
|
|
659dddace7 | ||
|
|
b096f30558 | ||
|
|
dcfb72143a | ||
|
|
c63bcd7706 | ||
|
|
bac306f9b3 | ||
|
|
a6fd96e97b | ||
|
|
7edd91f923 | ||
|
|
66df445bd5 | ||
|
|
5c03034bb4 | ||
|
|
0eab181d46 | ||
|
|
f6f95308c7 | ||
|
|
e93cad91b4 | ||
|
|
08ee61b179 | ||
|
|
0ab756665e | ||
|
|
3570cddce0 | ||
|
|
a2d9f1a5db | ||
|
|
0c6a214e55 | ||
|
|
095fcdbe69 | ||
|
|
3afb1d18f6 | ||
|
|
4526c84330 | ||
|
|
a9cc1cb4b9 | ||
|
|
7acf1eace3 | ||
|
|
bb2e8cb287 | ||
|
|
3b389259c1 | ||
|
|
310ce55b09 | ||
|
|
4662e3fec2 | ||
|
|
10fab9d415 | ||
|
|
acecf01cbe | ||
|
|
b95fb9cda4 | ||
|
|
23fd595582 | ||
|
|
468d05cb10 | ||
|
|
88c2e5d160 | ||
|
|
8cf491b802 | ||
|
|
5886e78299 | ||
|
|
591ef9781c | ||
|
|
52fef96c1c | ||
|
|
d5fd9c57ec | ||
|
|
8a7d6a1c13 | ||
|
|
1745c72981 | ||
|
|
b98b7646cb | ||
|
|
1446e925ec | ||
|
|
799cda1e3e | ||
|
|
d2e0231341 | ||
|
|
9e0aa655a0 | ||
|
|
e303c73d44 | ||
|
|
e5e8e66d6b | ||
|
|
0bb3381122 | ||
|
|
2c5bf2bd6b | ||
|
|
83763b00ae | ||
|
|
47fc795c97 | ||
|
|
6a59bf7af3 | ||
|
|
6f185570d6 | ||
|
|
8b8336d9d0 | ||
|
|
a1e1d6ed3f | ||
|
|
df3e209534 | ||
|
|
851408860e | ||
|
|
d92ea23b0e | ||
|
|
d83641db92 | ||
|
|
48f262e1f3 | ||
|
|
bc49a7db50 | ||
|
|
49975b461c | ||
|
|
3ccb635956 | ||
|
|
074a90e0ac | ||
|
|
526f927436 | ||
|
|
fae7fad915 | ||
|
|
56132ceb8b | ||
|
|
3c3fce0a5a | ||
|
|
8139384961 | ||
|
|
734cc94048 | ||
|
|
91dbb7770d | ||
|
|
707709837d | ||
|
|
e868e65208 | ||
|
|
b19ad2a13b | ||
|
|
98ccccf6ab | ||
|
|
0a6166c557 | ||
|
|
5ee00e52a8 | ||
|
|
ff2b4e0b2f | ||
|
|
8fdd8db51b | ||
|
|
f113eb7ba8 | ||
|
|
40bc25ed5f | ||
|
|
cd3eab5d35 | ||
|
|
7038e15ad2 | ||
|
|
c72abd29ec | ||
|
|
5efc3d2228 | ||
|
|
8ac3f83c79 | ||
|
|
b31b054d0c | ||
|
|
fb4a87f5ce | ||
|
|
049c73880b | ||
|
|
7b2c54f6a6 | ||
|
|
23bda39812 | ||
|
|
90af5801ee | ||
|
|
543c241bc6 | ||
|
|
19a58a3510 | ||
|
|
73c6fd18ed | ||
|
|
409297c6aa | ||
|
|
4272b9ea35 | ||
|
|
3c5c5b0bbc | ||
|
|
802b2d722e | ||
|
|
8f90d3f8ff | ||
|
|
f93cbbf508 | ||
|
|
2ba8756bd3 | ||
|
|
8013de56c9 | ||
|
|
4af9b22442 | ||
|
|
8a392170cf | ||
|
|
6385e053ae | ||
|
|
2789119882 | ||
|
|
3e0553c3e8 | ||
|
|
5e16ace1e7 | ||
|
|
0ca23cc4ca | ||
|
|
4949457001 | ||
|
|
8ae13fe823 | ||
|
|
fdf672092a | ||
|
|
48dd6ea826 | ||
|
|
68bb4f15e2 | ||
|
|
9c6d9ec22d | ||
|
|
ac075ace73 | ||
|
|
eb58774ee9 | ||
|
|
04613bf9a9 | ||
|
|
4194f1964d | ||
|
|
42c64c82d7 | ||
|
|
d44a8966f2 | ||
|
|
ff44330aa1 | ||
|
|
ed259e8168 | ||
|
|
444836975d | ||
|
|
3756fa93e4 | ||
|
|
064b52b306 | ||
|
|
648dc51474 | ||
|
|
7c0bc32759 | ||
|
|
d4b6cc5e4d | ||
|
|
75fca715e3 | ||
|
|
6e9a4a29ef | ||
|
|
78f643c50f | ||
|
|
2db4f1ba87 | ||
|
|
5741dbb78c |
@@ -10,3 +10,4 @@ SECRET='whyour'
|
|||||||
QINIU_AK=''
|
QINIU_AK=''
|
||||||
QINIU_SK=''
|
QINIU_SK=''
|
||||||
QINIU_SCOPE=''
|
QINIU_SCOPE=''
|
||||||
|
TEMP=''
|
||||||
|
|||||||
@@ -5,28 +5,55 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
- 'develop'
|
- 'develop'
|
||||||
# Sequence of patterns matched against refs/tags
|
|
||||||
tags:
|
tags:
|
||||||
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
|
||||||
schedule:
|
schedule:
|
||||||
# 参考 https://jasonet.co/posts/scheduled-actions/
|
# 参考 https://jasonet.co/posts/scheduled-actions/
|
||||||
# note: 这里是GMT时间,北京时间减去八小时即可。如北京时间 22:30 => GMT 14:30
|
- cron: '00 14 * * *' # GMT 15:00 => 北京时间 23:00
|
||||||
# minute hour day month dayOfWeek
|
|
||||||
- cron: '00 14 * * *' # GMT 14:00 => 北京时间 22:00
|
|
||||||
#- cron: '30 16 * * *' # GMT 16:30(前一天) => 北京时间 00:30
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
to_gitlab:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- uses: pixta-dev/repository-mirroring-action@v1
|
||||||
|
with:
|
||||||
|
target_repo_url:
|
||||||
|
git@gitlab.com:whyour/qinglong.git
|
||||||
|
ssh_private_key:
|
||||||
|
${{ secrets.GITLAB_SSH_PK }}
|
||||||
|
|
||||||
|
to_gitee:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- uses: pixta-dev/repository-mirroring-action@v1
|
||||||
|
with:
|
||||||
|
target_repo_url:
|
||||||
|
git@gitee.com:whyour/qinglong.git
|
||||||
|
ssh_private_key:
|
||||||
|
${{ secrets.GITLAB_SSH_PK }}
|
||||||
|
|
||||||
build-static:
|
build-static:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
- uses: pnpm/action-setup@v2
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
cache: 'pnpm'
|
||||||
|
|
||||||
- name: build front and back
|
- name: build front and back
|
||||||
run: |
|
run: |
|
||||||
npm i -g pnpm
|
pnpm install --frozen-lockfile
|
||||||
pnpm install
|
|
||||||
pnpm build:front
|
pnpm build:front
|
||||||
pnpm build:back
|
pnpm build:back
|
||||||
|
|
||||||
@@ -34,6 +61,9 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GITHUB_REPO: github.com/${{ github.repository_owner }}/qinglong-static
|
GITHUB_REPO: github.com/${{ github.repository_owner }}/qinglong-static
|
||||||
GITHUB_BRANCH: ${{ github.ref_name }}
|
GITHUB_BRANCH: ${{ github.ref_name }}
|
||||||
|
REPO_GITEE: git@gitee.com:whyour/qinglong-static.git
|
||||||
|
REPO_GITLAB: git@gitlab.com:whyour/qinglong-static.git
|
||||||
|
PRIVATE_KEY: ${{ secrets.GITLAB_SSH_PK }}
|
||||||
run: |
|
run: |
|
||||||
mkdir -p tmp
|
mkdir -p tmp
|
||||||
cd ./tmp
|
cd ./tmp
|
||||||
@@ -44,7 +74,19 @@ jobs:
|
|||||||
git commit --allow-empty -m "copy static at $(date +'%Y-%m-%d %H:%M:%S')"
|
git commit --allow-empty -m "copy static at $(date +'%Y-%m-%d %H:%M:%S')"
|
||||||
git push --force --quiet "https://${{ secrets.API_TOKEN }}@${GITHUB_REPO}.git" ${GITHUB_BRANCH}:${GITHUB_BRANCH}
|
git push --force --quiet "https://${{ secrets.API_TOKEN }}@${GITHUB_REPO}.git" ${GITHUB_BRANCH}:${GITHUB_BRANCH}
|
||||||
|
|
||||||
|
mkdir -p ~/.ssh
|
||||||
|
echo "${PRIVATE_KEY}" > ~/.ssh/id_rsa
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
|
||||||
|
export GIT_SSH_COMMAND="ssh -v -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -l git"
|
||||||
|
git remote add gitee "${REPO_GITEE}"
|
||||||
|
git remote add gitlab "${REPO_GITLAB}"
|
||||||
|
git push --force --quiet gitee ${GITHUB_BRANCH}:${GITHUB_BRANCH}
|
||||||
|
git push --force --quiet gitlab ${GITHUB_BRANCH}:${GITHUB_BRANCH}
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
if: github.ref != 'refs/heads/master'
|
||||||
|
|
||||||
needs: build-static
|
needs: build-static
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -55,14 +97,17 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-node@v3
|
- uses: pnpm/action-setup@v2
|
||||||
|
|
||||||
- name: Set time zone
|
|
||||||
uses: szenius/set-timezone@v1.0
|
|
||||||
with:
|
with:
|
||||||
timezoneLinux: "Asia/Shanghai"
|
version: latest
|
||||||
timezoneMacos: "Asia/Shanghai"
|
- uses: actions/setup-node@v3
|
||||||
timezoneWindows: "China Standard Time"
|
with:
|
||||||
|
cache: 'pnpm'
|
||||||
|
|
||||||
|
- name: Setup timezone
|
||||||
|
uses: zcong1993/setup-timezone@master
|
||||||
|
with:
|
||||||
|
timezone: Asia/Shanghai
|
||||||
|
|
||||||
- name: Login to DockerHub
|
- name: Login to DockerHub
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v2
|
||||||
@@ -108,9 +153,16 @@ jobs:
|
|||||||
build-args: |
|
build-args: |
|
||||||
MAINTAINER=${{ github.repository_owner }}
|
MAINTAINER=${{ github.repository_owner }}
|
||||||
QL_BRANCH=${{ github.ref_name }}
|
QL_BRANCH=${{ github.ref_name }}
|
||||||
|
SOURCE_COMMIT=${{ github.sha }}
|
||||||
network: host
|
network: host
|
||||||
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
|
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x,linux/386
|
||||||
context: docker/
|
context: .
|
||||||
|
file: ./docker/Dockerfile
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=registry,ref=whyour/qinglong:cache
|
||||||
|
cache-to: type=registry,ref=whyour/qinglong:cache,mode=max
|
||||||
|
|
||||||
|
- name: Image digest
|
||||||
|
run: echo ${{ steps.docker_build.outputs.digest }}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
/npm-debug.log*
|
/npm-debug.log*
|
||||||
/yarn-error.log
|
/yarn-error.log
|
||||||
/yarn.lock
|
/yarn.lock
|
||||||
/pnpm-lock.yaml
|
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
|
|
||||||
# production
|
# production
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ export default defineConfig({
|
|||||||
antd: {},
|
antd: {},
|
||||||
outputPath: 'static/dist',
|
outputPath: 'static/dist',
|
||||||
fastRefresh: true,
|
fastRefresh: true,
|
||||||
favicons: ['/images/favicon.svg'],
|
favicons: ['./images/favicon.svg'],
|
||||||
mfsu: {
|
mfsu: {
|
||||||
strategy: 'eager',
|
strategy: 'eager',
|
||||||
},
|
},
|
||||||
|
publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api/public': {
|
'/api/public': {
|
||||||
target: 'http://127.0.0.1:5400/',
|
target: 'http://127.0.0.1:5400/',
|
||||||
|
|||||||
+7
-3
@@ -22,7 +22,7 @@ Timed task management panel with python3, javaScript, shell, typescript support
|
|||||||
[docker-image-size-url]: https://hub.docker.com/r/whyour/qinglong
|
[docker-image-size-url]: https://hub.docker.com/r/whyour/qinglong
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
[](https://whyour.cn)
|
[](https://whyour.cn)
|
||||||
|
|
||||||
[简体中文](./README.md) | English
|
[简体中文](./README.md) | English
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ Timed task management panel with python3, javaScript, shell, typescript support
|
|||||||
### Local Deployment
|
### Local Deployment
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# To be completed
|
# To be refined, see the development steps first (not supported on windows yet)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Podman Deployment
|
### Podman Deployment
|
||||||
@@ -61,7 +61,6 @@ podman run -dit \
|
|||||||
-p 5700:5700 \
|
-p 5700:5700 \
|
||||||
--name qinglong \
|
--name qinglong \
|
||||||
--hostname qinglong \
|
--hostname qinglong \
|
||||||
--restart unless-stopped \
|
|
||||||
docker.io/whyour/qinglong:latest
|
docker.io/whyour/qinglong:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -162,6 +161,10 @@ task <file_path> now
|
|||||||
task <file_path> conc <env_name> <account_number>(Optional)
|
task <file_path> conc <env_name> <account_number>(Optional)
|
||||||
# Specify the account to execute and run immediately regardless of whether a random delay is set
|
# Specify the account to execute and run immediately regardless of whether a random delay is set
|
||||||
task <file_path> desi <env_name> <account_number>
|
task <file_path> desi <env_name> <account_number>
|
||||||
|
# Set task timeout
|
||||||
|
task -m <max_time> <file_path>
|
||||||
|
# Print task log in real time, no need to carry this parameter when creating timed tasks
|
||||||
|
task -l <file_path>
|
||||||
```
|
```
|
||||||
|
|
||||||
2. parameter description
|
2. parameter description
|
||||||
@@ -176,6 +179,7 @@ task <file_path> desi <env_name> <account_number>
|
|||||||
* file_path: File path for task execution
|
* file_path: File path for task execution
|
||||||
* env_name: The name of the environment variable that needs to be concurrent or specified at the time of task execution
|
* env_name: The name of the environment variable that needs to be concurrent or specified at the time of task execution
|
||||||
* account_number: Specify the account number of an environment variable to be executed when the task is executed
|
* account_number: Specify the account number of an environment variable to be executed when the task is executed
|
||||||
|
* max_time: Timeout, suffix "s" for seconds (default), "m" for minutes, "h" for hours, "d" for days
|
||||||
|
|
||||||
## Links
|
## Links
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
[docker-image-size-url]: https://hub.docker.com/r/whyour/qinglong
|
[docker-image-size-url]: https://hub.docker.com/r/whyour/qinglong
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
[](https://whyour.cn)
|
[](https://whyour.cn)
|
||||||
|
|
||||||
简体中文 | [English](./README-en.md)
|
简体中文 | [English](./README-en.md)
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
### 本机部署
|
### 本机部署
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 待完善
|
# 待完善,可先参考开发步骤 (windows暂时不支持)
|
||||||
```
|
```
|
||||||
|
|
||||||
### podman 部署
|
### podman 部署
|
||||||
@@ -61,7 +61,6 @@ podman run -dit \
|
|||||||
-p 5700:5700 \
|
-p 5700:5700 \
|
||||||
--name qinglong \
|
--name qinglong \
|
||||||
--hostname qinglong \
|
--hostname qinglong \
|
||||||
--restart unless-stopped \
|
|
||||||
docker.io/whyour/qinglong:latest
|
docker.io/whyour/qinglong:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -161,6 +160,10 @@ task <file_path> now
|
|||||||
task <file_path> conc <env_name> <account_number>(可选的)
|
task <file_path> conc <env_name> <account_number>(可选的)
|
||||||
# 指定账号执行,无论是否设置了随机延迟,均立即运行
|
# 指定账号执行,无论是否设置了随机延迟,均立即运行
|
||||||
task <file_path> desi <env_name> <account_number>
|
task <file_path> desi <env_name> <account_number>
|
||||||
|
# 设置任务超时时间
|
||||||
|
task -m <max_time> <file_path>
|
||||||
|
# 实时打印任务日志,创建定时任务时,不用携带此参数
|
||||||
|
task -l <file_path>
|
||||||
```
|
```
|
||||||
|
|
||||||
2. 参数说明
|
2. 参数说明
|
||||||
@@ -176,6 +179,7 @@ task <file_path> desi <env_name> <account_number>
|
|||||||
* file_path: 任务执行时的文件路径
|
* file_path: 任务执行时的文件路径
|
||||||
* env_name: 任务执行时需要并发或者指定时的环境变量名称
|
* env_name: 任务执行时需要并发或者指定时的环境变量名称
|
||||||
* account_number: 任务执行时指定某个环境变量需要执行的账号序号
|
* account_number: 任务执行时指定某个环境变量需要执行的账号序号
|
||||||
|
* max_time: 超时时间,后缀"s"代表秒(默认值), "m"代表分, "h"代表小时, "d"代表天
|
||||||
|
|
||||||
## 链接
|
## 链接
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -30,6 +30,7 @@ export default (app: Router) => {
|
|||||||
name: Joi.string().required(),
|
name: Joi.string().required(),
|
||||||
sorts: Joi.array().optional().allow(null),
|
sorts: Joi.array().optional().allow(null),
|
||||||
filters: Joi.array().optional(),
|
filters: Joi.array().optional(),
|
||||||
|
filterRelation: Joi.string().optional(),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
@@ -51,13 +52,18 @@ export default (app: Router) => {
|
|||||||
id: Joi.number().required(),
|
id: Joi.number().required(),
|
||||||
sorts: Joi.array().optional().allow(null),
|
sorts: Joi.array().optional().allow(null),
|
||||||
filters: Joi.array().optional(),
|
filters: Joi.array().optional(),
|
||||||
|
filterRelation: Joi.string().optional(),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
const cronViewService = Container.get(CronViewService);
|
const cronViewService = Container.get(CronViewService);
|
||||||
const data = await cronViewService.update(req.body);
|
if (req.body.type === 1) {
|
||||||
return res.send({ code: 200, data });
|
return res.send({ code: 400, message: '参数错误' });
|
||||||
|
} else {
|
||||||
|
const data = await cronViewService.update(req.body);
|
||||||
|
return res.send({ code: 200, data });
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return next(e);
|
return next(e);
|
||||||
}
|
}
|
||||||
|
|||||||
+49
-2
@@ -3,8 +3,21 @@ import { Container } from 'typedi';
|
|||||||
import EnvService from '../services/env';
|
import EnvService from '../services/env';
|
||||||
import { Logger } from 'winston';
|
import { Logger } from 'winston';
|
||||||
import { celebrate, Joi } from 'celebrate';
|
import { celebrate, Joi } from 'celebrate';
|
||||||
|
import multer from 'multer';
|
||||||
|
import config from '../config';
|
||||||
|
import fs from 'fs';
|
||||||
const route = Router();
|
const route = Router();
|
||||||
|
|
||||||
|
const storage = multer.diskStorage({
|
||||||
|
destination: function (req, file, cb) {
|
||||||
|
cb(null, config.scriptPath);
|
||||||
|
},
|
||||||
|
filename: function (req, file, cb) {
|
||||||
|
cb(null, file.originalname);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const upload = multer({ storage: storage });
|
||||||
|
|
||||||
export default (app: Router) => {
|
export default (app: Router) => {
|
||||||
app.use('/envs', route);
|
app.use('/envs', route);
|
||||||
|
|
||||||
@@ -26,7 +39,9 @@ export default (app: Router) => {
|
|||||||
body: Joi.array().items(
|
body: Joi.array().items(
|
||||||
Joi.object({
|
Joi.object({
|
||||||
value: Joi.string().required(),
|
value: Joi.string().required(),
|
||||||
name: Joi.string().required(),
|
name: Joi.string()
|
||||||
|
.required()
|
||||||
|
.pattern(/^[a-zA-Z_][0-9a-zA-Z_]*$/),
|
||||||
remarks: Joi.string().optional().allow(''),
|
remarks: Joi.string().optional().allow(''),
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
@@ -94,7 +109,6 @@ export default (app: Router) => {
|
|||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request<{ id: number }>, res: Response, next: NextFunction) => {
|
async (req: Request<{ id: number }>, res: Response, next: NextFunction) => {
|
||||||
const logger: Logger = Container.get('logger');
|
|
||||||
try {
|
try {
|
||||||
const envService = Container.get(EnvService);
|
const envService = Container.get(EnvService);
|
||||||
const data = await envService.move(req.params.id, req.body);
|
const data = await envService.move(req.params.id, req.body);
|
||||||
@@ -177,4 +191,37 @@ export default (app: Router) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
route.post(
|
||||||
|
'/upload',
|
||||||
|
upload.single('env'),
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
const logger: Logger = Container.get('logger');
|
||||||
|
try {
|
||||||
|
const envService = Container.get(EnvService);
|
||||||
|
const fileContent = await fs.promises.readFile(req!.file!.path, 'utf8');
|
||||||
|
const parseContent = JSON.parse(fileContent);
|
||||||
|
const data = Array.isArray(parseContent)
|
||||||
|
? parseContent
|
||||||
|
: [parseContent];
|
||||||
|
if (data.every((x) => x.name && x.value)) {
|
||||||
|
const result = await envService.create(
|
||||||
|
data.map((x) => ({
|
||||||
|
name: x.name,
|
||||||
|
value: x.value,
|
||||||
|
remarks: x.remarks,
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
return res.send({ code: 200, data: result });
|
||||||
|
} else {
|
||||||
|
return res.send({
|
||||||
|
code: 400,
|
||||||
|
message: '文件缺少name或者value字段,参考导出文件格式',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
+31
-4
@@ -170,7 +170,7 @@ export default (app: Router) => {
|
|||||||
body: Joi.object({
|
body: Joi.object({
|
||||||
filename: Joi.string().required(),
|
filename: Joi.string().required(),
|
||||||
path: Joi.string().allow(''),
|
path: Joi.string().allow(''),
|
||||||
type: Joi.string().optional()
|
type: Joi.string().optional(),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
@@ -255,23 +255,50 @@ export default (app: Router) => {
|
|||||||
celebrate({
|
celebrate({
|
||||||
body: Joi.object({
|
body: Joi.object({
|
||||||
filename: Joi.string().required(),
|
filename: Joi.string().required(),
|
||||||
content: Joi.string().optional().allow(''),
|
|
||||||
path: Joi.string().optional().allow(''),
|
path: Joi.string().optional().allow(''),
|
||||||
|
pid: Joi.number().optional().allow(''),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const logger: Logger = Container.get('logger');
|
const logger: Logger = Container.get('logger');
|
||||||
try {
|
try {
|
||||||
let { filename, content, path } = req.body;
|
let { filename, path, pid } = req.body;
|
||||||
const { name, ext } = parse(filename);
|
const { name, ext } = parse(filename);
|
||||||
const filePath = join(config.scriptPath, path, `${name}.swap${ext}`);
|
const filePath = join(config.scriptPath, path, `${name}.swap${ext}`);
|
||||||
|
|
||||||
const scriptService = Container.get(ScriptService);
|
const scriptService = Container.get(ScriptService);
|
||||||
const result = await scriptService.stopScript(filePath);
|
const result = await scriptService.stopScript(filePath, pid);
|
||||||
res.send(result);
|
res.send(result);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return next(e);
|
return next(e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
route.put(
|
||||||
|
'/rename',
|
||||||
|
celebrate({
|
||||||
|
body: Joi.object({
|
||||||
|
filename: Joi.string().required(),
|
||||||
|
path: Joi.string().allow(''),
|
||||||
|
newFilename: Joi.string().required(),
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
|
try {
|
||||||
|
let { filename, path, type, newFilename } = req.body as {
|
||||||
|
filename: string;
|
||||||
|
path: string;
|
||||||
|
type: string;
|
||||||
|
newFilename: string;
|
||||||
|
};
|
||||||
|
const filePath = join(config.scriptPath, path, filename);
|
||||||
|
const newPath = join(config.scriptPath, path, newFilename);
|
||||||
|
fs.renameSync(filePath, newPath);
|
||||||
|
res.send({ code: 200 });
|
||||||
|
} catch (e) {
|
||||||
|
return next(e);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ export default (app: Router) => {
|
|||||||
sub_after: Joi.string().optional().allow('').allow(null),
|
sub_after: Joi.string().optional().allow('').allow(null),
|
||||||
schedule_type: Joi.string().required(),
|
schedule_type: Joi.string().required(),
|
||||||
alias: Joi.string().required(),
|
alias: Joi.string().required(),
|
||||||
|
proxy: Joi.string().optional().allow('').allow(null),
|
||||||
|
autoAddCron: Joi.boolean().optional().allow('').allow(null),
|
||||||
|
autoDelCron: Joi.boolean().optional().allow('').allow(null),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
@@ -177,6 +180,9 @@ export default (app: Router) => {
|
|||||||
sub_before: Joi.string().optional().allow('').allow(null),
|
sub_before: Joi.string().optional().allow('').allow(null),
|
||||||
sub_after: Joi.string().optional().allow('').allow(null),
|
sub_after: Joi.string().optional().allow('').allow(null),
|
||||||
alias: Joi.string().required(),
|
alias: Joi.string().required(),
|
||||||
|
proxy: Joi.string().optional().allow('').allow(null),
|
||||||
|
autoAddCron: Joi.boolean().optional().allow('').allow(null),
|
||||||
|
autoDelCron: Joi.boolean().optional().allow('').allow(null),
|
||||||
id: Joi.number().required(),
|
id: Joi.number().required(),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|||||||
+24
-4
@@ -7,6 +7,9 @@ import SystemService from '../services/system';
|
|||||||
import { celebrate, Joi } from 'celebrate';
|
import { celebrate, Joi } from 'celebrate';
|
||||||
import UserService from '../services/user';
|
import UserService from '../services/user';
|
||||||
import { EnvModel } from '../data/env';
|
import { EnvModel } from '../data/env';
|
||||||
|
import { parseVersion, promiseExec } from '../config/util';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
const route = Router();
|
const route = Router();
|
||||||
|
|
||||||
export default (app: Router) => {
|
export default (app: Router) => {
|
||||||
@@ -18,10 +21,22 @@ export default (app: Router) => {
|
|||||||
const userService = Container.get(UserService);
|
const userService = Container.get(UserService);
|
||||||
const authInfo = await userService.getUserInfo();
|
const authInfo = await userService.getUserInfo();
|
||||||
const envCount = await EnvModel.count();
|
const envCount = await EnvModel.count();
|
||||||
const versionRegx = /.*export const version = \'(.*)\'\;/;
|
const { version, changeLog, changeLogLink } = await parseVersion(
|
||||||
|
config.versionFile,
|
||||||
const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8');
|
);
|
||||||
const version = currentVersionFile.match(versionRegx)![1];
|
const lastCommitTime = (
|
||||||
|
await promiseExec(
|
||||||
|
`cd ${config.rootPath} && git show -s --format=%ai | head -1`,
|
||||||
|
)
|
||||||
|
).replace('\n', '');
|
||||||
|
const lastCommitId = (
|
||||||
|
await promiseExec(`cd ${config.rootPath} && git rev-parse --short HEAD`)
|
||||||
|
).replace('\n', '');
|
||||||
|
const branch = (
|
||||||
|
await promiseExec(
|
||||||
|
`cd ${config.rootPath} && git symbolic-ref --short HEAD`,
|
||||||
|
)
|
||||||
|
).replace('\n', '');
|
||||||
|
|
||||||
let isInitialized = true;
|
let isInitialized = true;
|
||||||
if (
|
if (
|
||||||
@@ -37,6 +52,11 @@ export default (app: Router) => {
|
|||||||
data: {
|
data: {
|
||||||
isInitialized,
|
isInitialized,
|
||||||
version,
|
version,
|
||||||
|
lastCommitTime: dayjs(lastCommitTime).unix(),
|
||||||
|
lastCommitId,
|
||||||
|
branch,
|
||||||
|
changeLog,
|
||||||
|
changeLogLink,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export const LOG_END_SYMBOL = ' ';
|
||||||
|
|
||||||
|
export const TASK_COMMAND = 'task';
|
||||||
|
export const QL_COMMAND = 'ql';
|
||||||
|
|
||||||
|
export const TASK_PREFIX = `${TASK_COMMAND} `;
|
||||||
|
export const QL_PREFIX = `${QL_COMMAND} `;
|
||||||
@@ -14,7 +14,7 @@ if (!process.env.QL_DIR) {
|
|||||||
process.env.QL_DIR = qlHomePath.replace(/\/$/g, '');
|
process.env.QL_DIR = qlHomePath.replace(/\/$/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastVersionFile = `http://qn.whyour.cn/version.ts?v=${Date.now()}`;
|
const lastVersionFile = `https://qn.whyour.cn/version.yaml`;
|
||||||
|
|
||||||
const rootPath = process.env.QL_DIR as string;
|
const rootPath = process.env.QL_DIR as string;
|
||||||
const envFound = dotenv.config({ path: path.join(rootPath, '.env') });
|
const envFound = dotenv.config({ path: path.join(rootPath, '.env') });
|
||||||
@@ -40,7 +40,7 @@ const sqliteFile = path.join(samplePath, 'database.sqlite');
|
|||||||
const authError = '错误的用户名密码,请重试';
|
const authError = '错误的用户名密码,请重试';
|
||||||
const loginFaild = '请先登录!';
|
const loginFaild = '请先登录!';
|
||||||
const configString = 'config sample crontab shareCode diy';
|
const configString = 'config sample crontab shareCode diy';
|
||||||
const versionFile = path.join(rootPath, 'src/version.ts');
|
const versionFile = path.join(rootPath, 'version.yaml');
|
||||||
|
|
||||||
if (envFound.error) {
|
if (envFound.error) {
|
||||||
throw new Error("⚠️ Couldn't find .env file ⚠️");
|
throw new Error("⚠️ Couldn't find .env file ⚠️");
|
||||||
|
|||||||
+69
-8
@@ -4,6 +4,9 @@ import got from 'got';
|
|||||||
import iconv from 'iconv-lite';
|
import iconv from 'iconv-lite';
|
||||||
import { exec } from 'child_process';
|
import { exec } from 'child_process';
|
||||||
import FormData from 'form-data';
|
import FormData from 'form-data';
|
||||||
|
import psTreeFun from 'pstree.remy';
|
||||||
|
import { promisify } from 'util';
|
||||||
|
import { load } from 'js-yaml';
|
||||||
|
|
||||||
export function getFileContentByName(fileName: string) {
|
export function getFileContentByName(fileName: string) {
|
||||||
if (fs.existsSync(fileName)) {
|
if (fs.existsSync(fileName)) {
|
||||||
@@ -284,6 +287,20 @@ enum FileType {
|
|||||||
'file',
|
'file',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IFile {
|
||||||
|
title: string;
|
||||||
|
key: string;
|
||||||
|
type: 'directory' | 'file';
|
||||||
|
parent: string;
|
||||||
|
mtime: number;
|
||||||
|
children?: IFile[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function dirSort(a: IFile, b: IFile) {
|
||||||
|
if (a.type !== b.type) return FileType[a.type] < FileType[b.type] ? -1 : 1;
|
||||||
|
else if (a.mtime !== b.mtime) return a.mtime > b.mtime ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
export function readDirs(
|
export function readDirs(
|
||||||
dir: string,
|
dir: string,
|
||||||
baseDir: string = '',
|
baseDir: string = '',
|
||||||
@@ -303,10 +320,8 @@ export function readDirs(
|
|||||||
key,
|
key,
|
||||||
type: 'directory',
|
type: 'directory',
|
||||||
parent: relativePath,
|
parent: relativePath,
|
||||||
children: readDirs(subPath, baseDir).sort(
|
mtime: stats.mtime.getTime(),
|
||||||
(a: any, b: any) =>
|
children: readDirs(subPath, baseDir).sort(dirSort),
|
||||||
(FileType as any)[a.type] - (FileType as any)[b.type],
|
|
||||||
),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
@@ -315,11 +330,10 @@ export function readDirs(
|
|||||||
isLeaf: true,
|
isLeaf: true,
|
||||||
key,
|
key,
|
||||||
parent: relativePath,
|
parent: relativePath,
|
||||||
|
mtime: stats.mtime.getTime(),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return result.sort(
|
return result.sort(dirSort);
|
||||||
(a: any, b: any) => (FileType as any)[a.type] - (FileType as any)[b.type],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readDir(
|
export function readDir(
|
||||||
@@ -419,7 +433,12 @@ export function parseBody(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
parsed[key] = val;
|
try {
|
||||||
|
const jsonValue = JSON.parse(val);
|
||||||
|
parsed[key] = jsonValue;
|
||||||
|
} catch (error) {
|
||||||
|
parsed[key] = val;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
@@ -436,3 +455,45 @@ export function parseBody(
|
|||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function psTree(pid: number): Promise<number[]> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
psTreeFun(pid, (err: any, pids: number[]) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err);
|
||||||
|
}
|
||||||
|
resolve(pids.filter((x) => !isNaN(x)));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function killTask(pid: number) {
|
||||||
|
const pids = await psTree(pid);
|
||||||
|
// SIGALRM 14 时钟信号
|
||||||
|
if (pids.length) {
|
||||||
|
process.kill(pids[0], 14);
|
||||||
|
} else {
|
||||||
|
process.kill(pid, 14);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPid(name: string) {
|
||||||
|
let taskCommand = `ps -ef | grep "${name}" | grep -v grep | awk '{print $1}'`;
|
||||||
|
const execAsync = promisify(exec);
|
||||||
|
let pid = (await execAsync(taskCommand)).stdout;
|
||||||
|
return Number(pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IVersion {
|
||||||
|
version: string;
|
||||||
|
changeLogLink: string;
|
||||||
|
changeLog: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function parseVersion(path: string): Promise<IVersion> {
|
||||||
|
return load(await promisify(fs.readFile)(path, 'utf8')) as IVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function parseContentVersion(content: string): Promise<IVersion> {
|
||||||
|
return load(content) as IVersion;
|
||||||
|
}
|
||||||
|
|||||||
+16
-1
@@ -1,13 +1,19 @@
|
|||||||
import { sequelize } from '.';
|
import { sequelize } from '.';
|
||||||
import { DataTypes, Model } from 'sequelize';
|
import { DataTypes, Model } from 'sequelize';
|
||||||
|
|
||||||
|
export enum CronViewType {
|
||||||
|
'系统' = 1,
|
||||||
|
'个人',
|
||||||
|
}
|
||||||
|
|
||||||
interface SortType {
|
interface SortType {
|
||||||
type: 'ASC' | 'DESC';
|
type: 'ASC' | 'DESC';
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FilterType {
|
interface FilterType {
|
||||||
type: 'or' | 'and';
|
property: string;
|
||||||
|
operation: string;
|
||||||
value: string;
|
value: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,6 +24,8 @@ export class CrontabView {
|
|||||||
isDisabled?: 1 | 0;
|
isDisabled?: 1 | 0;
|
||||||
filters?: FilterType[];
|
filters?: FilterType[];
|
||||||
sorts?: SortType[];
|
sorts?: SortType[];
|
||||||
|
filterRelation?: 'and' | 'or';
|
||||||
|
type?: CronViewType;
|
||||||
|
|
||||||
constructor(options: CrontabView) {
|
constructor(options: CrontabView) {
|
||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
@@ -26,6 +34,8 @@ export class CrontabView {
|
|||||||
this.isDisabled = options.isDisabled || 0;
|
this.isDisabled = options.isDisabled || 0;
|
||||||
this.filters = options.filters;
|
this.filters = options.filters;
|
||||||
this.sorts = options.sorts;
|
this.sorts = options.sorts;
|
||||||
|
this.filterRelation = options.filterRelation;
|
||||||
|
this.type = options.type || CronViewType.个人;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,5 +53,10 @@ export const CrontabViewModel = sequelize.define<CronViewInstance>(
|
|||||||
isDisabled: DataTypes.NUMBER,
|
isDisabled: DataTypes.NUMBER,
|
||||||
filters: DataTypes.JSON,
|
filters: DataTypes.JSON,
|
||||||
sorts: DataTypes.JSON,
|
sorts: DataTypes.JSON,
|
||||||
|
filterRelation: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
type: DataTypes.NUMBER,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
+4
-1
@@ -26,7 +26,10 @@ export enum EnvStatus {
|
|||||||
'disabled',
|
'disabled',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const initEnvPosition = 9999999999;
|
export const maxPosition = 9000000000000000;
|
||||||
|
export const initPosition = 4500000000000000;
|
||||||
|
export const stepPosition = 10000000;
|
||||||
|
export const minPosition = 100;
|
||||||
|
|
||||||
interface EnvInstance extends Model<Env, Env>, Env {}
|
interface EnvInstance extends Model<Env, Env>, Env {}
|
||||||
export const EnvModel = sequelize.define<EnvInstance>('Env', {
|
export const EnvModel = sequelize.define<EnvInstance>('Env', {
|
||||||
|
|||||||
+12
-5
@@ -1,15 +1,22 @@
|
|||||||
import { Sequelize } from 'sequelize';
|
import { Sequelize, Transaction } from 'sequelize';
|
||||||
import config from '../config/index';
|
import config from '../config/index';
|
||||||
|
|
||||||
export const sequelize = new Sequelize({
|
export const sequelize = new Sequelize({
|
||||||
dialect: 'sqlite',
|
dialect: 'sqlite',
|
||||||
storage: `${config.dbPath}database.sqlite`,
|
storage: `${config.dbPath}database.sqlite`,
|
||||||
logging: false,
|
logging: false,
|
||||||
pool: {
|
retry: {
|
||||||
max: 6,
|
max: 10,
|
||||||
min: 0,
|
match: ['SQLITE_BUSY: database is locked'],
|
||||||
idle: 30000,
|
|
||||||
},
|
},
|
||||||
|
pool: {
|
||||||
|
max: 5,
|
||||||
|
min: 2,
|
||||||
|
idle: 30000,
|
||||||
|
acquire: 30000,
|
||||||
|
evict: 10000,
|
||||||
|
},
|
||||||
|
transactionType: Transaction.TYPES.IMMEDIATE,
|
||||||
});
|
});
|
||||||
|
|
||||||
export type ResponseType<T> = { code: number; data?: T; message?: string };
|
export type ResponseType<T> = { code: number; data?: T; message?: string };
|
||||||
|
|||||||
+21
-3
@@ -11,9 +11,11 @@ export enum NotificationMode {
|
|||||||
'dingtalkBot' = 'dingtalkBot',
|
'dingtalkBot' = 'dingtalkBot',
|
||||||
'weWorkBot' = 'weWorkBot',
|
'weWorkBot' = 'weWorkBot',
|
||||||
'weWorkApp' = 'weWorkApp',
|
'weWorkApp' = 'weWorkApp',
|
||||||
|
'aibotk' = 'aibotk',
|
||||||
'iGot' = 'iGot',
|
'iGot' = 'iGot',
|
||||||
'pushPlus' = 'pushPlus',
|
'pushPlus' = 'pushPlus',
|
||||||
'email' = 'email',
|
'email' = 'email',
|
||||||
|
'feishu' = 'feishu',
|
||||||
'webhook' = 'webhook',
|
'webhook' = 'webhook',
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +41,7 @@ export class ServerChanNotification extends NotificationBaseInfo {
|
|||||||
|
|
||||||
export class PushDeerNotification extends NotificationBaseInfo {
|
export class PushDeerNotification extends NotificationBaseInfo {
|
||||||
public pushDeerKey = '';
|
public pushDeerKey = '';
|
||||||
|
public pushDeerUrl = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ChatNotification extends NotificationBaseInfo {
|
export class ChatNotification extends NotificationBaseInfo {
|
||||||
@@ -48,7 +51,7 @@ export class ChatNotification extends NotificationBaseInfo {
|
|||||||
|
|
||||||
export class BarkNotification extends NotificationBaseInfo {
|
export class BarkNotification extends NotificationBaseInfo {
|
||||||
public barkPush = '';
|
public barkPush = '';
|
||||||
public barkIcon = 'http://qn.whyour.cn/logo.png';
|
public barkIcon = 'https://qn.whyour.cn/logo.png';
|
||||||
public barkSound = '';
|
public barkSound = '';
|
||||||
public barkGroup = 'qinglong';
|
public barkGroup = 'qinglong';
|
||||||
}
|
}
|
||||||
@@ -75,6 +78,12 @@ export class WeWorkAppNotification extends NotificationBaseInfo {
|
|||||||
public weWorkAppKey = '';
|
public weWorkAppKey = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class AibotkNotification extends NotificationBaseInfo {
|
||||||
|
public aibotkKey: string = '';
|
||||||
|
public aibotkType: 'room' | 'contact' = 'room';
|
||||||
|
public aibotkName: string = '';
|
||||||
|
}
|
||||||
|
|
||||||
export class IGotNotification extends NotificationBaseInfo {
|
export class IGotNotification extends NotificationBaseInfo {
|
||||||
public iGotPushKey = '';
|
public iGotPushKey = '';
|
||||||
}
|
}
|
||||||
@@ -95,7 +104,14 @@ export class WebhookNotification extends NotificationBaseInfo {
|
|||||||
public webhookBody: string = '';
|
public webhookBody: string = '';
|
||||||
public webhookUrl: string = '';
|
public webhookUrl: string = '';
|
||||||
public webhookMethod: 'GET' | 'POST' | 'PUT' = 'GET';
|
public webhookMethod: 'GET' | 'POST' | 'PUT' = 'GET';
|
||||||
public webhookContentType: 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded' = 'application/json';
|
public webhookContentType:
|
||||||
|
| 'application/json'
|
||||||
|
| 'multipart/form-data'
|
||||||
|
| 'application/x-www-form-urlencoded' = 'application/json';
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LarkNotification extends NotificationBaseInfo {
|
||||||
|
public larkKey = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NotificationInfo
|
export interface NotificationInfo
|
||||||
@@ -109,7 +125,9 @@ export interface NotificationInfo
|
|||||||
DingtalkBotNotification,
|
DingtalkBotNotification,
|
||||||
WeWorkBotNotification,
|
WeWorkBotNotification,
|
||||||
WeWorkAppNotification,
|
WeWorkAppNotification,
|
||||||
|
AibotkNotification,
|
||||||
IGotNotification,
|
IGotNotification,
|
||||||
PushPlusNotification,
|
PushPlusNotification,
|
||||||
EmailNotification,
|
EmailNotification,
|
||||||
WebhookNotification {}
|
WebhookNotification,
|
||||||
|
LarkNotification {}
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ export class Subscription {
|
|||||||
extensions?: string;
|
extensions?: string;
|
||||||
sub_before?: string;
|
sub_before?: string;
|
||||||
sub_after?: string;
|
sub_after?: string;
|
||||||
|
proxy?: string;
|
||||||
|
autoAddCron?: 1 | 0;
|
||||||
|
autoDelCron?: 1 | 0;
|
||||||
|
|
||||||
constructor(options: Subscription) {
|
constructor(options: Subscription) {
|
||||||
this.id = options.id;
|
this.id = options.id;
|
||||||
@@ -54,6 +57,9 @@ export class Subscription {
|
|||||||
this.extensions = options.extensions;
|
this.extensions = options.extensions;
|
||||||
this.sub_before = options.sub_before;
|
this.sub_before = options.sub_before;
|
||||||
this.sub_after = options.sub_after;
|
this.sub_after = options.sub_after;
|
||||||
|
this.proxy = options.proxy;
|
||||||
|
this.autoAddCron = options.autoAddCron ? 1 : 0;
|
||||||
|
this.autoDelCron = options.autoDelCron ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,5 +108,8 @@ export const SubscriptionModel = sequelize.define<SubscriptionInstance>(
|
|||||||
log_path: DataTypes.STRING,
|
log_path: DataTypes.STRING,
|
||||||
schedule_type: DataTypes.STRING,
|
schedule_type: DataTypes.STRING,
|
||||||
alias: { type: DataTypes.STRING, unique: 'alias' },
|
alias: { type: DataTypes.STRING, unique: 'alias' },
|
||||||
|
proxy: { type: DataTypes.STRING, allowNull: true },
|
||||||
|
autoAddCron: { type: DataTypes.NUMBER, allowNull: true },
|
||||||
|
autoDelCron: { type: DataTypes.NUMBER, allowNull: true },
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
+25
-6
@@ -10,6 +10,7 @@ import { fileExist } from '../config/util';
|
|||||||
import { SubscriptionModel } from '../data/subscription';
|
import { SubscriptionModel } from '../data/subscription';
|
||||||
import { CrontabViewModel } from '../data/cronView';
|
import { CrontabViewModel } from '../data/cronView';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
import { sequelize } from '../data';
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
try {
|
try {
|
||||||
@@ -21,12 +22,30 @@ export default async () => {
|
|||||||
await SubscriptionModel.sync();
|
await SubscriptionModel.sync();
|
||||||
await CrontabViewModel.sync();
|
await CrontabViewModel.sync();
|
||||||
|
|
||||||
// try {
|
// 初始化新增字段
|
||||||
// const queryInterface = sequelize.getQueryInterface();
|
try {
|
||||||
// await queryInterface.addIndex('Crontabs', ['command'], { unique: true });
|
await sequelize.query(
|
||||||
// await queryInterface.addIndex('Envs', ['name', 'value'], { unique: true });
|
'alter table CrontabViews add column filterRelation VARCHAR(255)',
|
||||||
// await queryInterface.addIndex('Apps', ['name'], { unique: true });
|
);
|
||||||
// } catch (error) { }
|
} catch (error) {}
|
||||||
|
try {
|
||||||
|
await sequelize.query(
|
||||||
|
'alter table Subscriptions add column proxy VARCHAR(255)',
|
||||||
|
);
|
||||||
|
} catch (error) {}
|
||||||
|
try {
|
||||||
|
await sequelize.query('alter table CrontabViews add column type NUMBER');
|
||||||
|
} catch (error) {}
|
||||||
|
try {
|
||||||
|
await sequelize.query(
|
||||||
|
'alter table Subscriptions add column autoAddCron NUMBER',
|
||||||
|
);
|
||||||
|
} catch (error) {}
|
||||||
|
try {
|
||||||
|
await sequelize.query(
|
||||||
|
'alter table Subscriptions add column autoDelCron NUMBER',
|
||||||
|
);
|
||||||
|
} catch (error) {}
|
||||||
|
|
||||||
// 2.10-2.11 升级
|
// 2.10-2.11 升级
|
||||||
const cronDbFile = path.join(config.rootPath, 'db/crontab.db');
|
const cronDbFile = path.join(config.rootPath, 'db/crontab.db');
|
||||||
|
|||||||
@@ -4,16 +4,32 @@ import { Container } from 'typedi';
|
|||||||
import { Crontab, CrontabModel, CrontabStatus } from '../data/cron';
|
import { Crontab, CrontabModel, CrontabStatus } from '../data/cron';
|
||||||
import CronService from '../services/cron';
|
import CronService from '../services/cron';
|
||||||
import EnvService from '../services/env';
|
import EnvService from '../services/env';
|
||||||
import _ from 'lodash';
|
import groupBy from 'lodash/groupBy';
|
||||||
import { DependenceModel } from '../data/dependence';
|
import { DependenceModel } from '../data/dependence';
|
||||||
import { Op } from 'sequelize';
|
import { Op } from 'sequelize';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
import { CrontabViewModel, CronViewType } from '../data/cronView';
|
||||||
|
import { initPosition } from '../data/env';
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
const cronService = Container.get(CronService);
|
const cronService = Container.get(CronService);
|
||||||
const envService = Container.get(EnvService);
|
const envService = Container.get(EnvService);
|
||||||
const dependenceService = Container.get(DependenceService);
|
const dependenceService = Container.get(DependenceService);
|
||||||
|
|
||||||
|
// 初始化新增默认全部任务视图
|
||||||
|
CrontabViewModel.findAll({
|
||||||
|
where: { type: CronViewType.系统, name: '全部任务' },
|
||||||
|
raw: true,
|
||||||
|
}).then((docs) => {
|
||||||
|
if (docs.length === 0) {
|
||||||
|
CrontabViewModel.create({
|
||||||
|
name: '全部任务',
|
||||||
|
type: CronViewType.系统,
|
||||||
|
position: initPosition / 2,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 初始化更新所有任务状态为空闲
|
// 初始化更新所有任务状态为空闲
|
||||||
await CrontabModel.update(
|
await CrontabModel.update(
|
||||||
{ status: CrontabStatus.idle },
|
{ status: CrontabStatus.idle },
|
||||||
@@ -26,7 +42,7 @@ export default async () => {
|
|||||||
order: [['type', 'DESC']],
|
order: [['type', 'DESC']],
|
||||||
raw: true,
|
raw: true,
|
||||||
}).then(async (docs) => {
|
}).then(async (docs) => {
|
||||||
const groups = _.groupBy(docs, 'type');
|
const groups = groupBy(docs, 'type');
|
||||||
const keys = Object.keys(groups).sort((a, b) => parseInt(b) - parseInt(a));
|
const keys = Object.keys(groups).sort((a, b) => parseInt(b) - parseInt(a));
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
const group = groups[key];
|
const group = groups[key];
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Container } from 'typedi';
|
import { Container } from 'typedi';
|
||||||
import _ from 'lodash';
|
|
||||||
import SystemService from '../services/system';
|
import SystemService from '../services/system';
|
||||||
import ScheduleService from '../services/schedule';
|
import ScheduleService from '../services/schedule';
|
||||||
import SubscriptionService from '../services/subscription';
|
import SubscriptionService from '../services/subscription';
|
||||||
|
|||||||
@@ -4,12 +4,10 @@ import * as Tracing from '@sentry/tracing';
|
|||||||
import Logger from './logger';
|
import Logger from './logger';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { parseVersion } from '../config/util';
|
||||||
|
|
||||||
export default ({ expressApp }: { expressApp: Application }) => {
|
export default async ({ expressApp }: { expressApp: Application }) => {
|
||||||
const versionRegx = /.*export const version = \'(.*)\'\;/;
|
const { version } = await parseVersion(config.versionFile);
|
||||||
|
|
||||||
const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8');
|
|
||||||
const currentVersion = currentVersionFile.match(versionRegx)![1];
|
|
||||||
|
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
dsn: 'https://f4b5b55fb3c645b29a5dc2d70a1a4ef4@o1098464.ingest.sentry.io/6122819',
|
dsn: 'https://f4b5b55fb3c645b29a5dc2d70a1a4ef4@o1098464.ingest.sentry.io/6122819',
|
||||||
@@ -18,7 +16,7 @@ export default ({ expressApp }: { expressApp: Application }) => {
|
|||||||
new Tracing.Integrations.Express({ app: expressApp }),
|
new Tracing.Integrations.Express({ app: expressApp }),
|
||||||
],
|
],
|
||||||
tracesSampleRate: 0.1,
|
tracesSampleRate: 0.1,
|
||||||
release: currentVersion,
|
release: version,
|
||||||
});
|
});
|
||||||
|
|
||||||
expressApp.use(Sentry.Handlers.requestHandler());
|
expressApp.use(Sentry.Handlers.requestHandler());
|
||||||
|
|||||||
+6
-9
@@ -6,15 +6,12 @@ import config from './config';
|
|||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
app.get('/api/public/panel/log', (req, res) => {
|
app.get('/api/public/panel/log', (req, res) => {
|
||||||
exec(
|
exec('tail -n 300 ~/.pm2/logs/panel-error.log', (err, stdout, stderr) => {
|
||||||
'pm2 logs panel --lines 500 --nostream --timestamp',
|
if (err || stderr) {
|
||||||
(err, stdout, stderr) => {
|
return res.send({ code: 400, message: (err && err.message) || stderr });
|
||||||
if (err || stderr) {
|
}
|
||||||
return res.send({ code: 400, message: (err && err.message) || stderr });
|
return res.send({ code: 200, data: stdout });
|
||||||
}
|
});
|
||||||
return res.send({ code: 200, data: stdout });
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app
|
app
|
||||||
|
|||||||
+6
-2
@@ -4,6 +4,7 @@ import { exec } from 'child_process';
|
|||||||
import Logger from './loaders/logger';
|
import Logger from './loaders/logger';
|
||||||
import { CrontabModel, CrontabStatus } from './data/cron';
|
import { CrontabModel, CrontabStatus } from './data/cron';
|
||||||
import config from './config';
|
import config from './config';
|
||||||
|
import { QL_PREFIX, TASK_PREFIX } from './config/const';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
@@ -23,8 +24,11 @@ const run = async () => {
|
|||||||
) {
|
) {
|
||||||
schedule.scheduleJob(task.schedule, function () {
|
schedule.scheduleJob(task.schedule, function () {
|
||||||
let command = task.command as string;
|
let command = task.command as string;
|
||||||
if (!command.includes('task ') && !command.includes('ql ')) {
|
if (
|
||||||
command = `task ${command}`;
|
!command.startsWith(TASK_PREFIX) &&
|
||||||
|
!command.startsWith(QL_PREFIX)
|
||||||
|
) {
|
||||||
|
command = `${TASK_PREFIX}${command}`;
|
||||||
}
|
}
|
||||||
exec(`ID=${task.id} ${command}`);
|
exec(`ID=${task.id} ${command}`);
|
||||||
});
|
});
|
||||||
|
|||||||
+55
-152
@@ -5,16 +5,20 @@ import { Crontab, CrontabModel, CrontabStatus } from '../data/cron';
|
|||||||
import { exec, execSync, spawn } from 'child_process';
|
import { exec, execSync, spawn } from 'child_process';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import cron_parser from 'cron-parser';
|
import cron_parser from 'cron-parser';
|
||||||
import { getFileContentByName, concurrentRun, fileExist } from '../config/util';
|
import {
|
||||||
|
getFileContentByName,
|
||||||
|
concurrentRun,
|
||||||
|
fileExist,
|
||||||
|
killTask,
|
||||||
|
} from '../config/util';
|
||||||
import { promises, existsSync } from 'fs';
|
import { promises, existsSync } from 'fs';
|
||||||
import { promisify } from 'util';
|
import { Op, where, col as colFn } from 'sequelize';
|
||||||
import { Op } from 'sequelize';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import dayjs from 'dayjs';
|
import { TASK_PREFIX, QL_PREFIX } from '../config/const';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class CronService {
|
export default class CronService {
|
||||||
constructor(@Inject('logger') private logger: winston.Logger) {}
|
constructor(@Inject('logger') private logger: winston.Logger) { }
|
||||||
|
|
||||||
private isSixCron(cron: Crontab) {
|
private isSixCron(cron: Crontab) {
|
||||||
const { schedule } = cron;
|
const { schedule } = cron;
|
||||||
@@ -28,7 +32,7 @@ export default class CronService {
|
|||||||
const tab = new Crontab(payload);
|
const tab = new Crontab(payload);
|
||||||
tab.saved = false;
|
tab.saved = false;
|
||||||
const doc = await this.insert(tab);
|
const doc = await this.insert(tab);
|
||||||
await this.set_crontab(this.isSixCron(doc));
|
await this.set_crontab();
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +43,7 @@ export default class CronService {
|
|||||||
public async update(payload: Crontab): Promise<Crontab> {
|
public async update(payload: Crontab): Promise<Crontab> {
|
||||||
payload.saved = false;
|
payload.saved = false;
|
||||||
const newDoc = await this.updateDb(payload);
|
const newDoc = await this.updateDb(payload);
|
||||||
await this.set_crontab(this.isSixCron(newDoc));
|
await this.set_crontab();
|
||||||
return newDoc;
|
return newDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +82,7 @@ export default class CronService {
|
|||||||
|
|
||||||
public async remove(ids: number[]) {
|
public async remove(ids: number[]) {
|
||||||
await CrontabModel.destroy({ where: { id: ids } });
|
await CrontabModel.destroy({ where: { id: ids } });
|
||||||
await this.set_crontab(true);
|
await this.set_crontab();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async pin(ids: number[]) {
|
public async pin(ids: number[]) {
|
||||||
@@ -115,8 +119,9 @@ export default class CronService {
|
|||||||
|
|
||||||
private formatViewQuery(query: any, viewQuery: any) {
|
private formatViewQuery(query: any, viewQuery: any) {
|
||||||
if (viewQuery.filters && viewQuery.filters.length > 0) {
|
if (viewQuery.filters && viewQuery.filters.length > 0) {
|
||||||
if (!query[Op.and]) {
|
const primaryOperate = viewQuery.filterRelation === 'or' ? Op.or : Op.and;
|
||||||
query[Op.and] = [];
|
if (!query[primaryOperate]) {
|
||||||
|
query[primaryOperate] = [];
|
||||||
}
|
}
|
||||||
for (const col of viewQuery.filters) {
|
for (const col of viewQuery.filters) {
|
||||||
const { property, value, operation } = col;
|
const { property, value, operation } = col;
|
||||||
@@ -159,13 +164,27 @@ export default class CronService {
|
|||||||
}
|
}
|
||||||
if (operate && operate2) {
|
if (operate && operate2) {
|
||||||
q[property] = {
|
q[property] = {
|
||||||
[operate2]: [
|
[Op.or]: [
|
||||||
{ [operate]: `%${value}%` },
|
{
|
||||||
{ [operate]: `%${encodeURIComponent(value)}%` },
|
[operate2]: [
|
||||||
|
{ [operate]: `%${value}%` },
|
||||||
|
{ [operate]: `%${encodeURIComponent(value)}%` },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
[operate2]: [
|
||||||
|
where(colFn(property), operate, `%${value}%`),
|
||||||
|
where(
|
||||||
|
colFn(property),
|
||||||
|
operate,
|
||||||
|
`%${encodeURIComponent(value)}%`,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
query[Op.and].push(q);
|
query[primaryOperate].push(q);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -313,31 +332,11 @@ export default class CronService {
|
|||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
if (doc.pid) {
|
if (doc.pid) {
|
||||||
try {
|
try {
|
||||||
process.kill(-doc.pid);
|
await killTask(doc.pid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.silly(error);
|
this.logger.silly(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const err = await this.killTask(doc.command);
|
|
||||||
const absolutePath = path.resolve(config.logPath, `${doc.log_path}`);
|
|
||||||
const logFileExist = doc.log_path && (await fileExist(absolutePath));
|
|
||||||
|
|
||||||
const endTime = dayjs();
|
|
||||||
const diffTimeStr = doc.last_execution_time
|
|
||||||
? `,耗时 ${endTime.diff(
|
|
||||||
dayjs(doc.last_execution_time * 1000),
|
|
||||||
'second',
|
|
||||||
)}`
|
|
||||||
: '';
|
|
||||||
if (logFileExist) {
|
|
||||||
const str = err ? `\n${err}` : '';
|
|
||||||
fs.appendFileSync(
|
|
||||||
`${absolutePath}`,
|
|
||||||
`${str}\n## 执行结束... ${endTime.format(
|
|
||||||
'YYYY-MM-DD HH:mm:ss',
|
|
||||||
)}${diffTimeStr}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await CrontabModel.update(
|
await CrontabModel.update(
|
||||||
@@ -346,42 +345,6 @@ export default class CronService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async killTask(name: string) {
|
|
||||||
let taskCommand = `ps -ef | grep "${name}" | grep -v grep | awk '{print $1}'`;
|
|
||||||
const execAsync = promisify(exec);
|
|
||||||
try {
|
|
||||||
let pid = (await execAsync(taskCommand)).stdout;
|
|
||||||
if (pid) {
|
|
||||||
pid = (await execAsync(`pstree -p ${pid}`)).stdout;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let pids = pid.match(/\(\d+/g);
|
|
||||||
const killLogs = [];
|
|
||||||
if (pids && pids.length > 0) {
|
|
||||||
// node 执行脚本时还会有10个子进程,但是ps -ef中不存在,所以截取前三个
|
|
||||||
pids = pids.slice(0, 3);
|
|
||||||
for (const id of pids) {
|
|
||||||
const c = `kill -9 ${id.slice(1)}`;
|
|
||||||
try {
|
|
||||||
const { stdout, stderr } = await execAsync(c);
|
|
||||||
if (stderr) {
|
|
||||||
killLogs.push(stderr);
|
|
||||||
}
|
|
||||||
if (stdout) {
|
|
||||||
killLogs.push(stdout);
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
killLogs.push(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return killLogs.length > 0 ? JSON.stringify(killLogs) : '';
|
|
||||||
} catch (e) {
|
|
||||||
return JSON.stringify(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async runSingle(cronId: number): Promise<number> {
|
private async runSingle(cronId: number): Promise<number> {
|
||||||
return new Promise(async (resolve: any) => {
|
return new Promise(async (resolve: any) => {
|
||||||
const cron = await this.getDb({ id: cronId });
|
const cron = await this.getDb({ id: cronId });
|
||||||
@@ -399,8 +362,8 @@ export default class CronService {
|
|||||||
this.logger.silly('Original command: ' + command);
|
this.logger.silly('Original command: ' + command);
|
||||||
|
|
||||||
let cmdStr = command;
|
let cmdStr = command;
|
||||||
if (!cmdStr.includes('task ') && !cmdStr.includes('ql ')) {
|
if (!cmdStr.startsWith(TASK_PREFIX) && !cmdStr.startsWith(QL_PREFIX)) {
|
||||||
cmdStr = `task ${cmdStr}`;
|
cmdStr = `${TASK_PREFIX}${cmdStr}`;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
cmdStr.endsWith('.js') ||
|
cmdStr.endsWith('.js') ||
|
||||||
@@ -420,7 +383,7 @@ export default class CronService {
|
|||||||
);
|
);
|
||||||
cp.stderr.on('data', (data) => {
|
cp.stderr.on('data', (data) => {
|
||||||
if (logFileExist) {
|
if (logFileExist) {
|
||||||
fs.appendFileSync(`${absolutePath}`, `${data}`);
|
fs.appendFileSync(`${absolutePath}`, `${data.toString()}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cp.on('error', (err) => {
|
cp.on('error', (err) => {
|
||||||
@@ -446,12 +409,12 @@ export default class CronService {
|
|||||||
|
|
||||||
public async disabled(ids: number[]) {
|
public async disabled(ids: number[]) {
|
||||||
await CrontabModel.update({ isDisabled: 1 }, { where: { id: ids } });
|
await CrontabModel.update({ isDisabled: 1 }, { where: { id: ids } });
|
||||||
await this.set_crontab(true);
|
await this.set_crontab();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async enabled(ids: number[]) {
|
public async enabled(ids: number[]) {
|
||||||
await CrontabModel.update({ isDisabled: 0 }, { where: { id: ids } });
|
await CrontabModel.update({ isDisabled: 0 }, { where: { id: ids } });
|
||||||
await this.set_crontab(true);
|
await this.set_crontab();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async log(id: number) {
|
public async log(id: number) {
|
||||||
@@ -464,104 +427,46 @@ export default class CronService {
|
|||||||
const logFileExist = doc.log_path && (await fileExist(absolutePath));
|
const logFileExist = doc.log_path && (await fileExist(absolutePath));
|
||||||
if (logFileExist) {
|
if (logFileExist) {
|
||||||
return getFileContentByName(`${absolutePath}`);
|
return getFileContentByName(`${absolutePath}`);
|
||||||
}
|
|
||||||
const [, commandStr, url] = doc.command.split(/ +/);
|
|
||||||
let logPath = this.getKey(commandStr);
|
|
||||||
const isQlCommand = doc.command.startsWith('ql ');
|
|
||||||
const key =
|
|
||||||
(url && ['repo', 'raw'].includes(commandStr) && this.getKey(url)) ||
|
|
||||||
logPath;
|
|
||||||
if (isQlCommand) {
|
|
||||||
logPath = 'update';
|
|
||||||
}
|
|
||||||
let logDir = `${config.logPath}${logPath}`;
|
|
||||||
if (existsSync(logDir)) {
|
|
||||||
let files = await promises.readdir(logDir);
|
|
||||||
if (isQlCommand) {
|
|
||||||
files = files.filter((x) => x.includes(key));
|
|
||||||
}
|
|
||||||
return getFileContentByName(`${logDir}/${files[files.length - 1]}`);
|
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return '任务未运行或运行失败,请尝试手动运行';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async logs(id: number) {
|
public async logs(id: number) {
|
||||||
const doc = await this.getDb({ id });
|
const doc = await this.getDb({ id });
|
||||||
if (!doc) {
|
if (!doc || !doc.log_path) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc.log_path) {
|
const relativeDir = path.dirname(`${doc.log_path}`);
|
||||||
const relativeDir = path.dirname(`${doc.log_path}`);
|
const dir = path.resolve(config.logPath, relativeDir);
|
||||||
const dir = path.resolve(config.logPath, relativeDir);
|
if (existsSync(dir)) {
|
||||||
if (existsSync(dir)) {
|
let files = await promises.readdir(dir);
|
||||||
let files = await promises.readdir(dir);
|
|
||||||
return files
|
|
||||||
.map((x) => ({
|
|
||||||
filename: x,
|
|
||||||
directory: relativeDir.replace(config.logPath, ''),
|
|
||||||
time: fs.statSync(`${dir}/${x}`).mtime.getTime(),
|
|
||||||
}))
|
|
||||||
.sort((a, b) => b.time - a.time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const [, commandStr, url] = doc.command.split(/ +/);
|
|
||||||
let logPath = this.getKey(commandStr);
|
|
||||||
const isQlCommand = doc.command.startsWith('ql ');
|
|
||||||
const key =
|
|
||||||
(url && ['repo', 'raw'].includes(commandStr) && this.getKey(url)) ||
|
|
||||||
logPath;
|
|
||||||
if (isQlCommand) {
|
|
||||||
logPath = 'update';
|
|
||||||
}
|
|
||||||
let logDir = `${config.logPath}${logPath}`;
|
|
||||||
if (existsSync(logDir)) {
|
|
||||||
let files = await promises.readdir(logDir);
|
|
||||||
if (isQlCommand) {
|
|
||||||
files = files.filter((x) => x.includes(key));
|
|
||||||
}
|
|
||||||
return files
|
return files
|
||||||
.map((x) => ({
|
.map((x) => ({
|
||||||
filename: x,
|
filename: x,
|
||||||
directory: logPath,
|
directory: relativeDir.replace(config.logPath, ''),
|
||||||
time: fs.statSync(`${logDir}/${x}`).mtime.getTime(),
|
time: fs.statSync(`${dir}/${x}`).mtime.getTime(),
|
||||||
}))
|
}))
|
||||||
.sort((a, b) => b.time - a.time);
|
.sort((a, b) => b.time - a.time);
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private getKey(command: string): string {
|
|
||||||
const start =
|
|
||||||
command.lastIndexOf('/') !== -1 ? command.lastIndexOf('/') + 1 : 0;
|
|
||||||
const end =
|
|
||||||
command.lastIndexOf('.') !== -1
|
|
||||||
? command.lastIndexOf('.')
|
|
||||||
: command.length;
|
|
||||||
|
|
||||||
const tmpStr = command.substring(0, start - 1);
|
|
||||||
let index = 0;
|
|
||||||
if (tmpStr.lastIndexOf('/') !== -1 && tmpStr.startsWith('http')) {
|
|
||||||
index = tmpStr.lastIndexOf('/');
|
|
||||||
} else if (tmpStr.lastIndexOf(':') !== -1 && tmpStr.startsWith('git@')) {
|
|
||||||
index = tmpStr.lastIndexOf(':');
|
|
||||||
}
|
|
||||||
if (index) {
|
|
||||||
return `${tmpStr.substring(index + 1)}_${command.substring(start, end)}`;
|
|
||||||
} else {
|
|
||||||
return command.substring(start, end);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private make_command(tab: Crontab) {
|
private make_command(tab: Crontab) {
|
||||||
|
if (
|
||||||
|
!tab.command.startsWith(TASK_PREFIX) &&
|
||||||
|
!tab.command.startsWith(QL_PREFIX)
|
||||||
|
) {
|
||||||
|
tab.command = `${TASK_PREFIX}${tab.command}`;
|
||||||
|
}
|
||||||
const crontab_job_string = `ID=${tab.id} ${tab.command}`;
|
const crontab_job_string = `ID=${tab.id} ${tab.command}`;
|
||||||
return crontab_job_string;
|
return crontab_job_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async set_crontab(needReloadSchedule: boolean = false) {
|
private async set_crontab() {
|
||||||
const tabs = await this.crontabs();
|
const tabs = await this.crontabs();
|
||||||
var crontab_string = '';
|
var crontab_string = '';
|
||||||
tabs.data.forEach((tab) => {
|
tabs.data.forEach((tab) => {
|
||||||
@@ -584,9 +489,7 @@ export default class CronService {
|
|||||||
fs.writeFileSync(config.crontabFile, crontab_string);
|
fs.writeFileSync(config.crontabFile, crontab_string);
|
||||||
|
|
||||||
execSync(`crontab ${config.crontabFile}`);
|
execSync(`crontab ${config.crontabFile}`);
|
||||||
if (needReloadSchedule) {
|
exec(`pm2 reload schedule`);
|
||||||
exec(`pm2 reload schedule`);
|
|
||||||
}
|
|
||||||
await CrontabModel.update({ saved: true }, { where: {} });
|
await CrontabModel.update({ saved: true }, { where: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import winston from 'winston';
|
import winston from 'winston';
|
||||||
import { CrontabView, CrontabViewModel } from '../data/cronView';
|
import { CrontabView, CrontabViewModel } from '../data/cronView';
|
||||||
import { initEnvPosition } from '../data/env';
|
import {
|
||||||
|
initPosition,
|
||||||
|
maxPosition,
|
||||||
|
minPosition,
|
||||||
|
stepPosition,
|
||||||
|
} from '../data/env';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class CronViewService {
|
export default class CronViewService {
|
||||||
constructor(@Inject('logger') private logger: winston.Logger) {}
|
constructor(@Inject('logger') private logger: winston.Logger) {}
|
||||||
|
|
||||||
public async create(payload: CrontabView): Promise<CrontabView> {
|
public async create(payload: CrontabView): Promise<CrontabView> {
|
||||||
let position = initEnvPosition;
|
let position = initPosition;
|
||||||
const views = await this.list();
|
const views = await this.list();
|
||||||
if (views && views.length > 0 && views[views.length - 1].position) {
|
if (views && views.length > 0 && views[views.length - 1].position) {
|
||||||
position = views[views.length - 1].position as number;
|
position = views[views.length - 1].position as number;
|
||||||
@@ -16,6 +21,8 @@ export default class CronViewService {
|
|||||||
position = position / 2;
|
position = position / 2;
|
||||||
const tab = new CrontabView({ ...payload, position });
|
const tab = new CrontabView({ ...payload, position });
|
||||||
const doc = await this.insert(tab);
|
const doc = await this.insert(tab);
|
||||||
|
|
||||||
|
await this.checkPosition(tab.position!);
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +69,22 @@ export default class CronViewService {
|
|||||||
await CrontabViewModel.update({ isDisabled: 0 }, { where: { id: ids } });
|
await CrontabViewModel.update({ isDisabled: 0 }, { where: { id: ids } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async checkPosition(position: number) {
|
||||||
|
const precisionPosition = parseFloat(position.toPrecision(16));
|
||||||
|
if (precisionPosition < minPosition || precisionPosition > maxPosition) {
|
||||||
|
const envs = await this.list();
|
||||||
|
let position = initPosition;
|
||||||
|
for (const env of envs) {
|
||||||
|
position = position - stepPosition;
|
||||||
|
await this.updateDb({ id: env.id, position });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPrecisionPosition(position: number): number {
|
||||||
|
return parseFloat(position.toPrecision(16));
|
||||||
|
}
|
||||||
|
|
||||||
public async move({
|
public async move({
|
||||||
id,
|
id,
|
||||||
fromIndex,
|
fromIndex,
|
||||||
@@ -76,17 +99,19 @@ export default class CronViewService {
|
|||||||
const views = await this.list();
|
const views = await this.list();
|
||||||
if (toIndex === 0 || toIndex === views.length - 1) {
|
if (toIndex === 0 || toIndex === views.length - 1) {
|
||||||
targetPosition = isUpward
|
targetPosition = isUpward
|
||||||
? views[0].position * 2
|
? views[0].position! * 2
|
||||||
: views[toIndex].position / 2;
|
: views[toIndex].position! / 2;
|
||||||
} else {
|
} else {
|
||||||
targetPosition = isUpward
|
targetPosition = isUpward
|
||||||
? (views[toIndex].position + views[toIndex - 1].position) / 2
|
? (views[toIndex].position! + views[toIndex - 1].position!) / 2
|
||||||
: (views[toIndex].position + views[toIndex + 1].position) / 2;
|
: (views[toIndex].position! + views[toIndex + 1].position!) / 2;
|
||||||
}
|
}
|
||||||
const newDoc = await this.update({
|
const newDoc = await this.update({
|
||||||
id,
|
id,
|
||||||
position: targetPosition,
|
position: this.getPrecisionPosition(targetPosition),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await this.checkPosition(targetPosition);
|
||||||
return newDoc;
|
return newDoc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
unInstallDependenceCommandTypes,
|
unInstallDependenceCommandTypes,
|
||||||
DependenceModel,
|
DependenceModel,
|
||||||
} from '../data/dependence';
|
} from '../data/dependence';
|
||||||
import _ from 'lodash';
|
|
||||||
import { spawn } from 'child_process';
|
import { spawn } from 'child_process';
|
||||||
import SockService from './sock';
|
import SockService from './sock';
|
||||||
import { Op } from 'sequelize';
|
import { Op } from 'sequelize';
|
||||||
|
|||||||
+53
-28
@@ -1,10 +1,17 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import winston from 'winston';
|
import winston from 'winston';
|
||||||
import { getFileContentByName } from '../config/util';
|
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { Env, EnvModel, EnvStatus, initEnvPosition } from '../data/env';
|
import {
|
||||||
import _ from 'lodash';
|
Env,
|
||||||
|
EnvModel,
|
||||||
|
EnvStatus,
|
||||||
|
initPosition,
|
||||||
|
maxPosition,
|
||||||
|
minPosition,
|
||||||
|
stepPosition,
|
||||||
|
} from '../data/env';
|
||||||
|
import groupBy from 'lodash/groupBy';
|
||||||
import { Op } from 'sequelize';
|
import { Op } from 'sequelize';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
@@ -13,17 +20,22 @@ export default class EnvService {
|
|||||||
|
|
||||||
public async create(payloads: Env[]): Promise<Env[]> {
|
public async create(payloads: Env[]): Promise<Env[]> {
|
||||||
const envs = await this.envs();
|
const envs = await this.envs();
|
||||||
let position = initEnvPosition;
|
let position = initPosition;
|
||||||
if (envs && envs.length > 0 && envs[envs.length - 1].position) {
|
if (
|
||||||
position = envs[envs.length - 1].position as number;
|
envs &&
|
||||||
|
envs.length > 0 &&
|
||||||
|
typeof envs[envs.length - 1].position === 'number'
|
||||||
|
) {
|
||||||
|
position = envs[envs.length - 1].position!;
|
||||||
}
|
}
|
||||||
const tabs = payloads.map((x) => {
|
const tabs = payloads.map((x) => {
|
||||||
position = position / 2;
|
position = position - stepPosition;
|
||||||
const tab = new Env({ ...x, position });
|
const tab = new Env({ ...x, position });
|
||||||
return tab;
|
return tab;
|
||||||
});
|
});
|
||||||
const docs = await this.insert(tabs);
|
const docs = await this.insert(tabs);
|
||||||
await this.set_envs();
|
await this.set_envs();
|
||||||
|
await this.checkPosition(tabs[tabs.length - 1].position!);
|
||||||
return docs;
|
return docs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,25 +79,40 @@ export default class EnvService {
|
|||||||
const envs = await this.envs();
|
const envs = await this.envs();
|
||||||
if (toIndex === 0 || toIndex === envs.length - 1) {
|
if (toIndex === 0 || toIndex === envs.length - 1) {
|
||||||
targetPosition = isUpward
|
targetPosition = isUpward
|
||||||
? envs[0].position * 2
|
? envs[0].position! + stepPosition
|
||||||
: envs[toIndex].position / 2;
|
: envs[toIndex].position! - stepPosition;
|
||||||
} else {
|
} else {
|
||||||
targetPosition = isUpward
|
targetPosition = isUpward
|
||||||
? (envs[toIndex].position + envs[toIndex - 1].position) / 2
|
? (envs[toIndex].position! + envs[toIndex - 1].position!) / 2
|
||||||
: (envs[toIndex].position + envs[toIndex + 1].position) / 2;
|
: (envs[toIndex].position! + envs[toIndex + 1].position!) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
const newDoc = await this.update({
|
const newDoc = await this.update({
|
||||||
id,
|
id,
|
||||||
position: targetPosition,
|
position: this.getPrecisionPosition(targetPosition),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await this.checkPosition(targetPosition);
|
||||||
return newDoc;
|
return newDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async envs(
|
private async checkPosition(position: number) {
|
||||||
searchText: string = '',
|
const precisionPosition = parseFloat(position.toPrecision(16));
|
||||||
sort: any = { position: -1 },
|
if (precisionPosition < minPosition || precisionPosition > maxPosition) {
|
||||||
query: any = {},
|
const envs = await this.envs();
|
||||||
): Promise<Env[]> {
|
let position = initPosition;
|
||||||
|
for (const env of envs) {
|
||||||
|
position = position - stepPosition;
|
||||||
|
await this.updateDb({ id: env.id, position });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getPrecisionPosition(position: number): number {
|
||||||
|
return parseFloat(position.toPrecision(16));
|
||||||
|
}
|
||||||
|
|
||||||
|
public async envs(searchText: string = '', query: any = {}): Promise<Env[]> {
|
||||||
let condition = { ...query };
|
let condition = { ...query };
|
||||||
if (searchText) {
|
if (searchText) {
|
||||||
const encodeText = encodeURIComponent(searchText);
|
const encodeText = encodeURIComponent(searchText);
|
||||||
@@ -115,7 +142,7 @@ export default class EnvService {
|
|||||||
const result = await this.find(condition, [
|
const result = await this.find(condition, [
|
||||||
['status', 'ASC'],
|
['status', 'ASC'],
|
||||||
['position', 'DESC'],
|
['position', 'DESC'],
|
||||||
['createdAt', 'DESC'],
|
['createdAt', 'ASC'],
|
||||||
]);
|
]);
|
||||||
return result as any;
|
return result as any;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -155,22 +182,20 @@ export default class EnvService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async set_envs() {
|
public async set_envs() {
|
||||||
const envs = await this.envs(
|
const envs = await this.envs('', {
|
||||||
'',
|
name: { [Op.not]: null },
|
||||||
{ position: -1 },
|
status: EnvStatus.normal,
|
||||||
{ name: { [Op.not]: null } },
|
});
|
||||||
);
|
const groups = groupBy(envs, 'name');
|
||||||
const groups = _.groupBy(envs, 'name');
|
|
||||||
let env_string = '';
|
let env_string = '';
|
||||||
for (const key in groups) {
|
for (const key in groups) {
|
||||||
if (Object.prototype.hasOwnProperty.call(groups, key)) {
|
if (Object.prototype.hasOwnProperty.call(groups, key)) {
|
||||||
const group = groups[key];
|
const group = groups[key];
|
||||||
|
|
||||||
// 忽略不符合bash要求的环境变量名称
|
// 忽略不符合bash要求的环境变量名称
|
||||||
if (/^[a-zA-Z_][0-9a-zA-Z_]+$/.test(key)) {
|
if (/^[a-zA-Z_][0-9a-zA-Z_]*$/.test(key)) {
|
||||||
let value = _(group)
|
let value = group
|
||||||
.filter((x) => x.status !== EnvStatus.disabled)
|
.map((x) => x.value)
|
||||||
.map('value')
|
|
||||||
.join('&')
|
.join('&')
|
||||||
.replace(/(\\)[^n]/g, '\\\\')
|
.replace(/(\\)[^n]/g, '\\\\')
|
||||||
.replace(/(\\$)/, '\\\\')
|
.replace(/(\\$)/, '\\\\')
|
||||||
|
|||||||
+102
-42
@@ -24,18 +24,23 @@ export default class NotificationService {
|
|||||||
['dingtalkBot', this.dingtalkBot],
|
['dingtalkBot', this.dingtalkBot],
|
||||||
['weWorkBot', this.weWorkBot],
|
['weWorkBot', this.weWorkBot],
|
||||||
['weWorkApp', this.weWorkApp],
|
['weWorkApp', this.weWorkApp],
|
||||||
|
['aibotk', this.aibotk],
|
||||||
['iGot', this.iGot],
|
['iGot', this.iGot],
|
||||||
['pushPlus', this.pushPlus],
|
['pushPlus', this.pushPlus],
|
||||||
['email', this.email],
|
['email', this.email],
|
||||||
['webhook', this.webhook],
|
['webhook', this.webhook],
|
||||||
|
['lark', this.lark],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
private timeout = 10000;
|
|
||||||
private title = '';
|
private title = '';
|
||||||
private content = '';
|
private content = '';
|
||||||
private params!: Omit<NotificationInfo, 'type'>;
|
private params!: Omit<NotificationInfo, 'type'>;
|
||||||
|
private gotOption = {
|
||||||
|
timeout: 30000,
|
||||||
|
retry: 1,
|
||||||
|
};
|
||||||
|
|
||||||
constructor(@Inject('logger') private logger: winston.Logger) { }
|
constructor(@Inject('logger') private logger: winston.Logger) {}
|
||||||
|
|
||||||
public async notify(
|
public async notify(
|
||||||
title: string,
|
title: string,
|
||||||
@@ -76,8 +81,7 @@ export default class NotificationService {
|
|||||||
const { gotifyUrl, gotifyToken, gotifyPriority } = this.params;
|
const { gotifyUrl, gotifyToken, gotifyPriority } = this.params;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(`${gotifyUrl}/message?token=${gotifyToken}`, {
|
.post(`${gotifyUrl}/message?token=${gotifyToken}`, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `title=${encodeURIComponent(
|
body: `title=${encodeURIComponent(
|
||||||
this.title,
|
this.title,
|
||||||
)}&message=${encodeURIComponent(
|
)}&message=${encodeURIComponent(
|
||||||
@@ -95,8 +99,7 @@ export default class NotificationService {
|
|||||||
const { goCqHttpBotQq, goCqHttpBotToken, goCqHttpBotUrl } = this.params;
|
const { goCqHttpBotQq, goCqHttpBotToken, goCqHttpBotUrl } = this.params;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(`${goCqHttpBotUrl}?${goCqHttpBotQq}`, {
|
.post(`${goCqHttpBotUrl}?${goCqHttpBotQq}`, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: { message: `${this.title}\n${this.content}` },
|
json: { message: `${this.title}\n${this.content}` },
|
||||||
headers: { Authorization: 'Bearer ' + goCqHttpBotToken },
|
headers: { Authorization: 'Bearer ' + goCqHttpBotToken },
|
||||||
})
|
})
|
||||||
@@ -111,8 +114,7 @@ export default class NotificationService {
|
|||||||
: `https://sc.ftqq.com/${serverChanKey}.send`;
|
: `https://sc.ftqq.com/${serverChanKey}.send`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `title=${this.title}&desp=${this.content}`,
|
body: `title=${this.title}&desp=${this.content}`,
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
})
|
})
|
||||||
@@ -121,12 +123,11 @@ export default class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async pushDeer() {
|
private async pushDeer() {
|
||||||
const { pushDeerKey } = this.params;
|
const { pushDeerKey, pushDeerUrl } = this.params;
|
||||||
const url = `https://api2.pushdeer.com/message/push`;
|
const url = pushDeerUrl || `https://api2.pushdeer.com/message/push`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `pushkey=${pushDeerKey}&text=${encodeURIComponent(
|
body: `pushkey=${pushDeerKey}&text=${encodeURIComponent(
|
||||||
this.title,
|
this.title,
|
||||||
)}&desp=${encodeURIComponent(this.content)}&type=markdown`,
|
)}&desp=${encodeURIComponent(this.content)}&type=markdown`,
|
||||||
@@ -143,8 +144,7 @@ export default class NotificationService {
|
|||||||
const url = `${chatUrl}${chatToken}`;
|
const url = `${chatUrl}${chatToken}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `payload={"text":"${this.title}\n${this.content}"}`,
|
body: `payload={"text":"${this.title}\n${this.content}"}`,
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
})
|
})
|
||||||
@@ -164,8 +164,7 @@ export default class NotificationService {
|
|||||||
)}?icon=${barkIcon}?sound=${barkSound}&group=${barkGroup}`;
|
)}?icon=${barkIcon}?sound=${barkSound}&group=${barkGroup}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.get(url, {
|
.get(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
})
|
})
|
||||||
.json();
|
.json();
|
||||||
@@ -182,8 +181,9 @@ export default class NotificationService {
|
|||||||
telegramBotUserId,
|
telegramBotUserId,
|
||||||
} = this.params;
|
} = this.params;
|
||||||
const authStr = telegramBotProxyAuth ? `${telegramBotProxyAuth}@` : '';
|
const authStr = telegramBotProxyAuth ? `${telegramBotProxyAuth}@` : '';
|
||||||
const url = `https://${telegramBotApiHost ? telegramBotApiHost : 'api.telegram.org'
|
const url = `https://${
|
||||||
}/bot${telegramBotToken}/sendMessage`;
|
telegramBotApiHost ? telegramBotApiHost : 'api.telegram.org'
|
||||||
|
}/bot${telegramBotToken}/sendMessage`;
|
||||||
let agent;
|
let agent;
|
||||||
if (telegramBotProxyHost && telegramBotProxyPort) {
|
if (telegramBotProxyHost && telegramBotProxyPort) {
|
||||||
const options: any = {
|
const options: any = {
|
||||||
@@ -202,8 +202,7 @@ export default class NotificationService {
|
|||||||
}
|
}
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `chat_id=${telegramBotUserId}&text=${this.title}\n\n${this.content}&disable_web_page_preview=true`,
|
body: `chat_id=${telegramBotUserId}&text=${this.title}\n\n${this.content}&disable_web_page_preview=true`,
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
agent,
|
agent,
|
||||||
@@ -225,8 +224,7 @@ export default class NotificationService {
|
|||||||
const url = `https://oapi.dingtalk.com/robot/send?access_token=${dingtalkBotToken}${secretParam}`;
|
const url = `https://oapi.dingtalk.com/robot/send?access_token=${dingtalkBotToken}${secretParam}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
msgtype: 'text',
|
msgtype: 'text',
|
||||||
text: {
|
text: {
|
||||||
@@ -243,8 +241,7 @@ export default class NotificationService {
|
|||||||
const url = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${weWorkBotKey}`;
|
const url = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${weWorkBotKey}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
msgtype: 'text',
|
msgtype: 'text',
|
||||||
text: {
|
text: {
|
||||||
@@ -263,8 +260,7 @@ export default class NotificationService {
|
|||||||
const url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken`;
|
const url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken`;
|
||||||
const tokenRes: any = await got
|
const tokenRes: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
corpid,
|
corpid,
|
||||||
corpsecret,
|
corpsecret,
|
||||||
@@ -314,8 +310,7 @@ export default class NotificationService {
|
|||||||
.post(
|
.post(
|
||||||
`https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${tokenRes.access_token}`,
|
`https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${tokenRes.access_token}`,
|
||||||
{
|
{
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
touser,
|
touser,
|
||||||
agentid,
|
agentid,
|
||||||
@@ -329,13 +324,53 @@ export default class NotificationService {
|
|||||||
return res.errcode === 0;
|
return res.errcode === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async aibotk() {
|
||||||
|
const { aibotkKey, aibotkType, aibotkName } = this.params;
|
||||||
|
let url = '';
|
||||||
|
let json = {};
|
||||||
|
switch (aibotkType) {
|
||||||
|
case 'room':
|
||||||
|
url = 'https://api-bot.aibotk.com/openapi/v1/chat/room';
|
||||||
|
json = {
|
||||||
|
apiKey: `${aibotkKey}`,
|
||||||
|
roomName: `${aibotkName}`,
|
||||||
|
message: {
|
||||||
|
type: 1,
|
||||||
|
content: `【青龙快讯】\n\n${this.title}\n${this.content}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'contact':
|
||||||
|
url = 'https://api-bot.aibotk.com/openapi/v1/chat/contact';
|
||||||
|
json = {
|
||||||
|
apiKey: `${aibotkKey}`,
|
||||||
|
name: `${aibotkName}`,
|
||||||
|
message: {
|
||||||
|
type: 1,
|
||||||
|
content: `【青龙快讯】\n\n${this.title}\n${this.content}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const res: any = await got
|
||||||
|
.post(url, {
|
||||||
|
...this.gotOption,
|
||||||
|
json: {
|
||||||
|
...json,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
|
||||||
|
return res.code === 0;
|
||||||
|
}
|
||||||
|
|
||||||
private async iGot() {
|
private async iGot() {
|
||||||
const { iGotPushKey } = this.params;
|
const { iGotPushKey } = this.params;
|
||||||
const url = `https://push.hellyw.com/${iGotPushKey.toLowerCase()}`;
|
const url = `https://push.hellyw.com/${iGotPushKey.toLowerCase()}`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
body: `title=${this.title}&content=${this.content}`,
|
body: `title=${this.title}&content=${this.content}`,
|
||||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||||
})
|
})
|
||||||
@@ -349,8 +384,7 @@ export default class NotificationService {
|
|||||||
const url = `https://www.pushplus.plus/send`;
|
const url = `https://www.pushplus.plus/send`;
|
||||||
const res: any = await got
|
const res: any = await got
|
||||||
.post(url, {
|
.post(url, {
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
json: {
|
json: {
|
||||||
token: `${pushPlusToken}`,
|
token: `${pushPlusToken}`,
|
||||||
title: `${this.title}`,
|
title: `${this.title}`,
|
||||||
@@ -363,6 +397,21 @@ export default class NotificationService {
|
|||||||
return res.code === 200;
|
return res.code === 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async lark() {
|
||||||
|
const { larkKey } = this.params;
|
||||||
|
const res: any = await got
|
||||||
|
.post(`https://open.feishu.cn/open-apis/bot/v2/hook/${larkKey}`, {
|
||||||
|
...this.gotOption,
|
||||||
|
json: {
|
||||||
|
msg_type: 'text',
|
||||||
|
content: { text: `${this.title}\n\n${this.content}` },
|
||||||
|
},
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
})
|
||||||
|
.json();
|
||||||
|
return res.StatusCode === 0;
|
||||||
|
}
|
||||||
|
|
||||||
private async email() {
|
private async email() {
|
||||||
const { emailPass, emailService, emailUser } = this.params;
|
const { emailPass, emailService, emailUser } = this.params;
|
||||||
const transporter = nodemailer.createTransport({
|
const transporter = nodemailer.createTransport({
|
||||||
@@ -386,10 +435,18 @@ export default class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async webhook() {
|
private async webhook() {
|
||||||
const { webhookUrl, webhookBody, webhookHeaders, webhookMethod, webhookContentType } =
|
const {
|
||||||
this.params;
|
webhookUrl,
|
||||||
|
webhookBody,
|
||||||
|
webhookHeaders,
|
||||||
|
webhookMethod,
|
||||||
|
webhookContentType,
|
||||||
|
} = this.params;
|
||||||
|
|
||||||
const { formatBody, formatUrl } = this.formatNotifyContent(webhookUrl, webhookBody);
|
const { formatBody, formatUrl } = this.formatNotifyContent(
|
||||||
|
webhookUrl,
|
||||||
|
webhookBody,
|
||||||
|
);
|
||||||
if (!formatUrl && !formatBody) {
|
if (!formatUrl && !formatBody) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -399,11 +456,10 @@ export default class NotificationService {
|
|||||||
const options = {
|
const options = {
|
||||||
method: webhookMethod,
|
method: webhookMethod,
|
||||||
headers,
|
headers,
|
||||||
timeout: this.timeout,
|
...this.gotOption,
|
||||||
retry: 0,
|
|
||||||
allowGetBody: true,
|
allowGetBody: true,
|
||||||
...bodyParam
|
...bodyParam,
|
||||||
}
|
};
|
||||||
const res = await got(formatUrl, options);
|
const res = await got(formatUrl, options);
|
||||||
return String(res.statusCode).startsWith('20');
|
return String(res.statusCode).startsWith('20');
|
||||||
}
|
}
|
||||||
@@ -427,8 +483,12 @@ export default class NotificationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
formatUrl: url.replaceAll('$title', encodeURIComponent(this.title)).replaceAll('$content', encodeURIComponent(this.content)),
|
formatUrl: url
|
||||||
formatBody: body.replaceAll('$title', this.title).replaceAll('$content', this.content),
|
.replaceAll('$title', encodeURIComponent(this.title))
|
||||||
}
|
.replaceAll('$content', encodeURIComponent(this.content)),
|
||||||
|
formatBody: body
|
||||||
|
.replaceAll('$title', this.title)
|
||||||
|
.replaceAll('$content', this.content),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ export default class OpenService {
|
|||||||
(x) => x.expiration >= timestamp,
|
(x) => x.expiration >= timestamp,
|
||||||
);
|
);
|
||||||
let tokens = invalidTokens;
|
let tokens = invalidTokens;
|
||||||
if (invalidTokens.length > 5) {
|
if (invalidTokens.length >= 5) {
|
||||||
tokens = [
|
tokens = [
|
||||||
...invalidTokens.slice(0, 4),
|
...invalidTokens.slice(0, 4),
|
||||||
{ ...invalidTokens[4], expiration },
|
{ ...invalidTokens[4], expiration },
|
||||||
|
|||||||
@@ -42,7 +42,11 @@ export default class ScheduleService {
|
|||||||
|
|
||||||
constructor(@Inject('logger') private logger: winston.Logger) {}
|
constructor(@Inject('logger') private logger: winston.Logger) {}
|
||||||
|
|
||||||
async runTask(command: string, callbacks: TaskCallbacks = {}) {
|
async runTask(
|
||||||
|
command: string,
|
||||||
|
callbacks: TaskCallbacks = {},
|
||||||
|
completionTime: 'start' | 'end' = 'end',
|
||||||
|
) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const startTime = dayjs();
|
const startTime = dayjs();
|
||||||
@@ -52,6 +56,7 @@ export default class ScheduleService {
|
|||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
callbacks.onStart?.(cp, startTime);
|
callbacks.onStart?.(cp, startTime);
|
||||||
|
completionTime === 'start' && resolve(cp.pid);
|
||||||
|
|
||||||
cp.stdout.on('data', async (data) => {
|
cp.stdout.on('data', async (data) => {
|
||||||
await callbacks.onLog?.(data.toString());
|
await callbacks.onLog?.(data.toString());
|
||||||
@@ -100,7 +105,6 @@ export default class ScheduleService {
|
|||||||
error,
|
error,
|
||||||
);
|
);
|
||||||
await callbacks.onError?.(JSON.stringify(error));
|
await callbacks.onError?.(JSON.stringify(error));
|
||||||
resolve(null);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-14
@@ -6,6 +6,8 @@ import SockService from './sock';
|
|||||||
import CronService from './cron';
|
import CronService from './cron';
|
||||||
import ScheduleService, { TaskCallbacks } from './schedule';
|
import ScheduleService, { TaskCallbacks } from './schedule';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
import { TASK_COMMAND } from '../config/const';
|
||||||
|
import { getPid, killTask } from '../config/util';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ScriptService {
|
export default class ScriptService {
|
||||||
@@ -40,23 +42,25 @@ export default class ScriptService {
|
|||||||
|
|
||||||
public async runScript(filePath: string) {
|
public async runScript(filePath: string) {
|
||||||
const relativePath = path.relative(config.scriptPath, filePath);
|
const relativePath = path.relative(config.scriptPath, filePath);
|
||||||
const command = `task -l ${relativePath} now`;
|
const command = `${TASK_COMMAND} -l ${relativePath} now`;
|
||||||
this.scheduleService.runTask(command, this.taskCallbacks(filePath));
|
const pid = await this.scheduleService.runTask(
|
||||||
|
command,
|
||||||
|
this.taskCallbacks(filePath),
|
||||||
|
'start',
|
||||||
|
);
|
||||||
|
|
||||||
return { code: 200 };
|
return { code: 200, data: pid };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stopScript(filePath: string) {
|
public async stopScript(filePath: string, pid: number) {
|
||||||
const relativePath = path.relative(config.scriptPath, filePath);
|
let str = '';
|
||||||
const err = await this.cronService.killTask(`task -l ${relativePath} now`);
|
if (!pid) {
|
||||||
|
const relativePath = path.relative(config.scriptPath, filePath);
|
||||||
const str = err ? `\n${err}` : '';
|
pid = await getPid(`${TASK_COMMAND} -l ${relativePath} now`);
|
||||||
this.sockService.sendMessage({
|
}
|
||||||
type: 'manuallyRunScript',
|
try {
|
||||||
message: `${str}\n## 执行结束... ${new Date()
|
await killTask(pid);
|
||||||
.toLocaleString('zh', { hour12: false })
|
} catch (error) {}
|
||||||
.replace(' 24:', ' 00:')} `,
|
|
||||||
});
|
|
||||||
|
|
||||||
return { code: 200 };
|
return { code: 200 };
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-7
@@ -14,7 +14,7 @@ export default class SshKeyService {
|
|||||||
|
|
||||||
private generatePrivateKeyFile(alias: string, key: string): void {
|
private generatePrivateKeyFile(alias: string, key: string): void {
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(`${this.sshPath}/${alias}`, key, {
|
fs.writeFileSync(`${this.sshPath}/${alias}`, `${key}${os.EOL}`, {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
mode: '400',
|
mode: '400',
|
||||||
});
|
});
|
||||||
@@ -38,8 +38,16 @@ export default class SshKeyService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateSingleSshConfig(alias: string, host: string): string {
|
private generateSingleSshConfig(
|
||||||
return `\nHost ${alias}\n Hostname ${host}\n IdentityFile ${this.sshPath}/${alias}\n StrictHostKeyChecking no`;
|
alias: string,
|
||||||
|
host: string,
|
||||||
|
proxy?: string,
|
||||||
|
): string {
|
||||||
|
if (host === 'github.com') {
|
||||||
|
host = `ssh.github.com\n Port 443\n HostkeyAlgorithms +ssh-rsa\n PubkeyAcceptedAlgorithms +ssh-rsa`;
|
||||||
|
}
|
||||||
|
const proxyStr = proxy ? ` ProxyCommand nc -v -x ${proxy} %h %p\n` : '';
|
||||||
|
return `\nHost ${alias}\n Hostname ${host}\n IdentityFile ${this.sshPath}/${alias}\n StrictHostKeyChecking no\n${proxyStr}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateSshConfig(configs: string[]) {
|
private generateSshConfig(configs: string[]) {
|
||||||
@@ -69,16 +77,21 @@ export default class SshKeyService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public addSSHKey(key: string, alias: string, host: string): void {
|
public addSSHKey(
|
||||||
|
key: string,
|
||||||
|
alias: string,
|
||||||
|
host: string,
|
||||||
|
proxy?: string,
|
||||||
|
): void {
|
||||||
this.generatePrivateKeyFile(alias, key);
|
this.generatePrivateKeyFile(alias, key);
|
||||||
const config = this.generateSingleSshConfig(alias, host);
|
const config = this.generateSingleSshConfig(alias, host, proxy);
|
||||||
this.removeSshConfig(alias);
|
this.removeSshConfig(alias);
|
||||||
this.generateSshConfig([config]);
|
this.generateSshConfig([config]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeSSHKey(alias: string, host: string): void {
|
public removeSSHKey(alias: string, host: string, proxy?: string): void {
|
||||||
this.removePrivateKeyFile(alias);
|
this.removePrivateKeyFile(alias);
|
||||||
const config = this.generateSingleSshConfig(alias, host);
|
const config = this.generateSingleSshConfig(alias, host, proxy);
|
||||||
this.removeSshConfig(config);
|
this.removeSshConfig(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,15 +13,14 @@ import {
|
|||||||
spawn,
|
spawn,
|
||||||
} from 'child_process';
|
} from 'child_process';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import cron_parser from 'cron-parser';
|
|
||||||
import {
|
import {
|
||||||
getFileContentByName,
|
getFileContentByName,
|
||||||
concurrentRun,
|
concurrentRun,
|
||||||
fileExist,
|
fileExist,
|
||||||
createFile,
|
createFile,
|
||||||
|
killTask,
|
||||||
} from '../config/util';
|
} from '../config/util';
|
||||||
import { promises, existsSync } from 'fs';
|
import { promises, existsSync } from 'fs';
|
||||||
import { promisify } from 'util';
|
|
||||||
import { Op } from 'sequelize';
|
import { Op } from 'sequelize';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import ScheduleService, { TaskCallbacks } from './schedule';
|
import ScheduleService, { TaskCallbacks } from './schedule';
|
||||||
@@ -29,6 +28,7 @@ import { SimpleIntervalSchedule } from 'toad-scheduler';
|
|||||||
import SockService from './sock';
|
import SockService from './sock';
|
||||||
import SshKeyService from './sshKey';
|
import SshKeyService from './sshKey';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
import { LOG_END_SYMBOL } from '../config/const';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SubscriptionService {
|
export default class SubscriptionService {
|
||||||
@@ -76,13 +76,25 @@ export default class SubscriptionService {
|
|||||||
private formatCommand(doc: Subscription, url?: string) {
|
private formatCommand(doc: Subscription, url?: string) {
|
||||||
let command = 'ql ';
|
let command = 'ql ';
|
||||||
let _url = url || this.formatUrl(doc).url;
|
let _url = url || this.formatUrl(doc).url;
|
||||||
const { type, whitelist, blacklist, dependences, branch, extensions } = doc;
|
const {
|
||||||
|
type,
|
||||||
|
whitelist,
|
||||||
|
blacklist,
|
||||||
|
dependences,
|
||||||
|
branch,
|
||||||
|
extensions,
|
||||||
|
proxy,
|
||||||
|
autoAddCron,
|
||||||
|
autoDelCron,
|
||||||
|
} = doc;
|
||||||
if (type === 'file') {
|
if (type === 'file') {
|
||||||
command += `raw "${_url}"`;
|
command += `raw "${_url}"`;
|
||||||
} else {
|
} else {
|
||||||
command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${
|
command += `repo "${_url}" "${whitelist || ''}" "${blacklist || ''}" "${
|
||||||
dependences || ''
|
dependences || ''
|
||||||
}" "${branch || ''}" "${extensions || ''}"`;
|
}" "${branch || ''}" "${extensions || ''}" "${proxy || ''}" "${
|
||||||
|
Boolean(autoAddCron) || ''
|
||||||
|
}" "${Boolean(autoDelCron) || ''}"`;
|
||||||
}
|
}
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
@@ -116,9 +128,10 @@ export default class SubscriptionService {
|
|||||||
(doc.pull_option as any).private_key,
|
(doc.pull_option as any).private_key,
|
||||||
doc.alias,
|
doc.alias,
|
||||||
host,
|
host,
|
||||||
|
doc.proxy,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.sshKeyService.removeSSHKey(doc.alias, host);
|
this.sshKeyService.removeSSHKey(doc.alias, host, doc.proxy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +245,7 @@ export default class SubscriptionService {
|
|||||||
absolutePath,
|
absolutePath,
|
||||||
`\n## 执行结束... ${endTime.format(
|
`\n## 执行结束... ${endTime.format(
|
||||||
'YYYY-MM-DD HH:mm:ss',
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
)} 耗时 ${diff} 秒`,
|
)} 耗时 ${diff} 秒${LOG_END_SYMBOL}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
await SubscriptionModel.update(
|
await SubscriptionModel.update(
|
||||||
@@ -271,7 +284,8 @@ export default class SubscriptionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async update(payload: Subscription): Promise<Subscription> {
|
public async update(payload: Subscription): Promise<Subscription> {
|
||||||
const newDoc = await this.updateDb(payload);
|
const tab = new Subscription(payload);
|
||||||
|
const newDoc = await this.updateDb(tab);
|
||||||
await this.handleTask(newDoc, !newDoc.is_disabled);
|
await this.handleTask(newDoc, !newDoc.is_disabled);
|
||||||
return newDoc;
|
return newDoc;
|
||||||
}
|
}
|
||||||
@@ -341,19 +355,18 @@ export default class SubscriptionService {
|
|||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
if (doc.pid) {
|
if (doc.pid) {
|
||||||
try {
|
try {
|
||||||
process.kill(-doc.pid);
|
await killTask(doc.pid);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.silly(error);
|
this.logger.silly(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const command = this.formatCommand(doc);
|
|
||||||
const err = await this.killTask(command);
|
|
||||||
const absolutePath = await this.handleLogPath(doc.log_path as string);
|
const absolutePath = await this.handleLogPath(doc.log_path as string);
|
||||||
const str = err ? `\n${err}` : '';
|
|
||||||
|
|
||||||
fs.appendFileSync(
|
fs.appendFileSync(
|
||||||
`${absolutePath}`,
|
`${absolutePath}`,
|
||||||
`${str}\n## 执行结束... ${dayjs().format('YYYY-MM-DD HH:mm:ss')} `,
|
`\n## 执行结束... ${dayjs().format(
|
||||||
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
|
)}${LOG_END_SYMBOL}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,41 +376,6 @@ export default class SubscriptionService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async killTask(name: string) {
|
|
||||||
let taskCommand = `ps -ef | grep "${name}" | grep -v grep | awk '{print $1}'`;
|
|
||||||
const execAsync = promisify(exec);
|
|
||||||
try {
|
|
||||||
let pid = (await execAsync(taskCommand)).stdout;
|
|
||||||
if (pid) {
|
|
||||||
pid = (await execAsync(`pstree -p ${pid}`)).stdout;
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let pids = pid.match(/\(\d+/g);
|
|
||||||
const killLogs = [];
|
|
||||||
if (pids && pids.length > 0) {
|
|
||||||
// node 执行脚本时还会有10个子进程,但是ps -ef中不存在,所以截取前三个
|
|
||||||
for (const id of pids) {
|
|
||||||
const c = `kill -9 ${id.slice(1)}`;
|
|
||||||
try {
|
|
||||||
const { stdout, stderr } = await execAsync(c);
|
|
||||||
if (stderr) {
|
|
||||||
killLogs.push(stderr);
|
|
||||||
}
|
|
||||||
if (stdout) {
|
|
||||||
killLogs.push(stdout);
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
killLogs.push(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return killLogs.length > 0 ? JSON.stringify(killLogs) : '';
|
|
||||||
} catch (e) {
|
|
||||||
return JSON.stringify(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async runSingle(subscriptionId: number) {
|
private async runSingle(subscriptionId: number) {
|
||||||
const subscription = await this.getDb({ id: subscriptionId });
|
const subscription = await this.getDb({ id: subscriptionId });
|
||||||
if (subscription.status !== SubscriptionStatus.queued) {
|
if (subscription.status !== SubscriptionStatus.queued) {
|
||||||
|
|||||||
+21
-24
@@ -2,7 +2,6 @@ import { Service, Inject } from 'typedi';
|
|||||||
import winston from 'winston';
|
import winston from 'winston';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import _ from 'lodash';
|
|
||||||
import { AuthDataType, AuthInfo, AuthModel, LoginStatus } from '../data/auth';
|
import { AuthDataType, AuthInfo, AuthModel, LoginStatus } from '../data/auth';
|
||||||
import { NotificationInfo } from '../data/notify';
|
import { NotificationInfo } from '../data/notify';
|
||||||
import NotificationService from './notify';
|
import NotificationService from './notify';
|
||||||
@@ -10,6 +9,7 @@ import ScheduleService from './schedule';
|
|||||||
import { spawn } from 'child_process';
|
import { spawn } from 'child_process';
|
||||||
import SockService from './sock';
|
import SockService from './sock';
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
|
import { parseContentVersion, parseVersion } from '../config/util';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SystemService {
|
export default class SystemService {
|
||||||
@@ -79,32 +79,33 @@ export default class SystemService {
|
|||||||
|
|
||||||
public async checkUpdate() {
|
public async checkUpdate() {
|
||||||
try {
|
try {
|
||||||
const versionRegx = /.*export const version = \'(.*)\'\;/;
|
const currentVersionContent = await parseVersion(config.versionFile);
|
||||||
const logRegx = /.*export const changeLog = \`((.*\n.*)+)\`;/;
|
|
||||||
|
|
||||||
const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8');
|
let lastVersionContent;
|
||||||
const currentVersion = currentVersionFile.match(versionRegx)![1];
|
|
||||||
|
|
||||||
let lastVersion = '';
|
|
||||||
let lastLog = '';
|
|
||||||
try {
|
try {
|
||||||
const result = await got.get(config.lastVersionFile, {
|
const result = await got.get(
|
||||||
timeout: 6000,
|
`${config.lastVersionFile}?t=${Date.now()}`,
|
||||||
retry: 0,
|
{
|
||||||
});
|
timeout: 30000,
|
||||||
const lastVersionFileContent = result.body;
|
},
|
||||||
lastVersion = lastVersionFileContent.match(versionRegx)![1];
|
);
|
||||||
lastLog = lastVersionFileContent.match(logRegx)
|
lastVersionContent = await parseContentVersion(result.body);
|
||||||
? lastVersionFileContent.match(logRegx)![1]
|
|
||||||
: '';
|
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
|
||||||
|
if (!lastVersionContent) {
|
||||||
|
lastVersionContent = currentVersionContent;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 200,
|
code: 200,
|
||||||
data: {
|
data: {
|
||||||
hasNewVersion: this.checkHasNewVersion(currentVersion, lastVersion),
|
hasNewVersion: this.checkHasNewVersion(
|
||||||
lastVersion,
|
currentVersionContent.version,
|
||||||
lastLog,
|
lastVersionContent.version,
|
||||||
|
),
|
||||||
|
lastVersion: lastVersionContent.version,
|
||||||
|
lastLog: lastVersionContent.changeLog,
|
||||||
|
lastLogLink: lastVersionContent.changeLogLink,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -137,10 +138,6 @@ export default class SystemService {
|
|||||||
public async updateSystem() {
|
public async updateSystem() {
|
||||||
const cp = spawn('ql -l update', { shell: '/bin/bash' });
|
const cp = spawn('ql -l update', { shell: '/bin/bash' });
|
||||||
|
|
||||||
this.sockService.sendMessage({
|
|
||||||
type: 'updateSystemVersion',
|
|
||||||
message: `开始更新系统`,
|
|
||||||
});
|
|
||||||
cp.stdout.on('data', (data) => {
|
cp.stdout.on('data', (data) => {
|
||||||
this.sockService.sendMessage({
|
this.sockService.sendMessage({
|
||||||
type: 'updateSystemVersion',
|
type: 'updateSystemVersion',
|
||||||
|
|||||||
+23
-15
@@ -3,7 +3,6 @@ import winston from 'winston';
|
|||||||
import { createRandomString, getNetIp, getPlatform } from '../config/util';
|
import { createRandomString, getNetIp, getPlatform } from '../config/util';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import _ from 'lodash';
|
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { authenticator } from '@otplib/preset-default';
|
import { authenticator } from '@otplib/preset-default';
|
||||||
import { AuthDataType, AuthInfo, AuthModel, LoginStatus } from '../data/auth';
|
import { AuthDataType, AuthInfo, AuthModel, LoginStatus } from '../data/auth';
|
||||||
@@ -24,7 +23,7 @@ export default class UserService {
|
|||||||
@Inject('logger') private logger: winston.Logger,
|
@Inject('logger') private logger: winston.Logger,
|
||||||
private scheduleService: ScheduleService,
|
private scheduleService: ScheduleService,
|
||||||
private sockService: SockService,
|
private sockService: SockService,
|
||||||
) { }
|
) {}
|
||||||
|
|
||||||
public async login(
|
public async login(
|
||||||
payloads: {
|
payloads: {
|
||||||
@@ -67,7 +66,9 @@ export default class UserService {
|
|||||||
|
|
||||||
const retriesTime = Math.pow(3, retries) * 1000;
|
const retriesTime = Math.pow(3, retries) * 1000;
|
||||||
if (retries > 2 && timestamp - lastlogon < retriesTime) {
|
if (retries > 2 && timestamp - lastlogon < retriesTime) {
|
||||||
const waitTime = Math.ceil((retriesTime - (timestamp - lastlogon)) / 1000);
|
const waitTime = Math.ceil(
|
||||||
|
(retriesTime - (timestamp - lastlogon)) / 1000,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
code: 410,
|
code: 410,
|
||||||
message: `失败次数过多,请${waitTime}秒后重试`,
|
message: `失败次数过多,请${waitTime}秒后重试`,
|
||||||
@@ -75,18 +76,23 @@ export default class UserService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
username === cUsername &&
|
||||||
|
password === cPassword &&
|
||||||
|
twoFactorActivated &&
|
||||||
|
needTwoFactor
|
||||||
|
) {
|
||||||
|
this.updateAuthInfo(content, {
|
||||||
|
isTwoFactorChecking: true,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
code: 420,
|
||||||
|
message: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const { ip, address } = await getNetIp(req);
|
const { ip, address } = await getNetIp(req);
|
||||||
if (username === cUsername && password === cPassword) {
|
if (username === cUsername && password === cPassword) {
|
||||||
if (twoFactorActivated && needTwoFactor) {
|
|
||||||
this.updateAuthInfo(content, {
|
|
||||||
isTwoFactorChecking: true,
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
code: 420,
|
|
||||||
message: '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = createRandomString(50, 100);
|
const data = createRandomString(50, 100);
|
||||||
const expiration = twoFactorActivated ? 60 : 20;
|
const expiration = twoFactorActivated ? 60 : 20;
|
||||||
let token = jwt.sign({ data }, config.secret as any, {
|
let token = jwt.sign({ data }, config.secret as any, {
|
||||||
@@ -109,7 +115,8 @@ export default class UserService {
|
|||||||
});
|
});
|
||||||
await this.notificationService.notify(
|
await this.notificationService.notify(
|
||||||
'登录通知',
|
'登录通知',
|
||||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${req.platform
|
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
||||||
|
req.platform
|
||||||
}端 登录成功,ip地址 ${ip}`,
|
}端 登录成功,ip地址 ${ip}`,
|
||||||
);
|
);
|
||||||
await this.getLoginLog();
|
await this.getLoginLog();
|
||||||
@@ -137,7 +144,8 @@ export default class UserService {
|
|||||||
});
|
});
|
||||||
await this.notificationService.notify(
|
await this.notificationService.notify(
|
||||||
'登录通知',
|
'登录通知',
|
||||||
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${req.platform
|
`你于${dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')}在 ${address} ${
|
||||||
|
req.platform
|
||||||
}端 登录失败,ip地址 ${ip}`,
|
}端 登录失败,ip地址 ${ip}`,
|
||||||
);
|
);
|
||||||
await this.getLoginLog();
|
await this.getLoginLog();
|
||||||
|
|||||||
+9
-3
@@ -5,6 +5,7 @@ import LoggerInstance from './loaders/logger';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import config from './config';
|
import config from './config';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import os from 'os';
|
||||||
|
|
||||||
const tokenFile = path.join(config.configPath, 'token.json');
|
const tokenFile = path.join(config.configPath, 'token.json');
|
||||||
|
|
||||||
@@ -25,9 +26,14 @@ async function getToken() {
|
|||||||
|
|
||||||
async function writeFile(data: any) {
|
async function writeFile(data: any) {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
fs.writeFile(tokenFile, JSON.stringify(data), { encoding: 'utf8' }, () => {
|
fs.writeFile(
|
||||||
resolve();
|
tokenFile,
|
||||||
});
|
`${JSON.stringify(data)}${os.EOL}`,
|
||||||
|
{ encoding: 'utf8' },
|
||||||
|
() => {
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-9
@@ -1,4 +1,13 @@
|
|||||||
FROM python:alpine
|
FROM python:3.10-alpine as builder
|
||||||
|
COPY package.json .npmrc pnpm-lock.yaml /tmp/build/
|
||||||
|
RUN set -x \
|
||||||
|
&& apk update \
|
||||||
|
&& apk add nodejs npm git \
|
||||||
|
&& npm i -g pnpm \
|
||||||
|
&& cd /tmp/build \
|
||||||
|
&& pnpm install --prod
|
||||||
|
|
||||||
|
FROM python:3.10-alpine
|
||||||
|
|
||||||
ARG QL_MAINTAINER="whyour"
|
ARG QL_MAINTAINER="whyour"
|
||||||
LABEL maintainer="${QL_MAINTAINER}"
|
LABEL maintainer="${QL_MAINTAINER}"
|
||||||
@@ -13,8 +22,6 @@ ENV PNPM_HOME=/root/.local/share/pnpm \
|
|||||||
QL_DIR=/ql \
|
QL_DIR=/ql \
|
||||||
QL_BRANCH=${QL_BRANCH}
|
QL_BRANCH=${QL_BRANCH}
|
||||||
|
|
||||||
WORKDIR ${QL_DIR}
|
|
||||||
|
|
||||||
RUN set -x \
|
RUN set -x \
|
||||||
&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
|
&& sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
|
||||||
&& apk update -f \
|
&& apk update -f \
|
||||||
@@ -42,19 +49,24 @@ RUN set -x \
|
|||||||
&& git config --global http.postBuffer 524288000 \
|
&& git config --global http.postBuffer 524288000 \
|
||||||
&& npm install -g pnpm \
|
&& npm install -g pnpm \
|
||||||
&& pnpm add -g pm2 ts-node typescript tslib \
|
&& pnpm add -g pm2 ts-node typescript tslib \
|
||||||
&& git clone -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
&& rm -rf /root/.pnpm-store \
|
||||||
|
&& rm -rf /root/.local/share/pnpm/store \
|
||||||
|
&& rm -rf /root/.cache \
|
||||||
|
&& rm -rf /root/.npm
|
||||||
|
|
||||||
|
ARG SOURCE_COMMIT
|
||||||
|
RUN git clone -b ${QL_BRANCH} ${QL_URL} ${QL_DIR} \
|
||||||
&& cd ${QL_DIR} \
|
&& cd ${QL_DIR} \
|
||||||
&& cp -f .env.example .env \
|
&& cp -f .env.example .env \
|
||||||
&& chmod 777 ${QL_DIR}/shell/*.sh \
|
&& chmod 777 ${QL_DIR}/shell/*.sh \
|
||||||
&& chmod 777 ${QL_DIR}/docker/*.sh \
|
&& chmod 777 ${QL_DIR}/docker/*.sh \
|
||||||
&& pnpm install --prod \
|
|
||||||
&& rm -rf /root/.pnpm-store \
|
|
||||||
&& rm -rf /root/.local/share/pnpm/store \
|
|
||||||
&& rm -rf /root/.cache \
|
|
||||||
&& rm -rf /root/.npm \
|
|
||||||
&& git clone -b ${QL_BRANCH} https://github.com/${QL_MAINTAINER}/qinglong-static.git /static \
|
&& git clone -b ${QL_BRANCH} https://github.com/${QL_MAINTAINER}/qinglong-static.git /static \
|
||||||
&& mkdir -p ${QL_DIR}/static \
|
&& mkdir -p ${QL_DIR}/static \
|
||||||
&& cp -rf /static/* ${QL_DIR}/static \
|
&& cp -rf /static/* ${QL_DIR}/static \
|
||||||
&& rm -rf /static
|
&& rm -rf /static
|
||||||
|
|
||||||
|
COPY --from=builder /tmp/build/node_modules/. /ql/node_modules/
|
||||||
|
|
||||||
|
WORKDIR ${QL_DIR}
|
||||||
|
|
||||||
ENTRYPOINT ["./docker/docker-entrypoint.sh"]
|
ENTRYPOINT ["./docker/docker-entrypoint.sh"]
|
||||||
|
|||||||
+20
-12
@@ -4,7 +4,7 @@
|
|||||||
"start": "concurrently -n w: npm:start:*",
|
"start": "concurrently -n w: npm:start:*",
|
||||||
"start:front": "max dev",
|
"start:front": "max dev",
|
||||||
"start:back": "nodemon",
|
"start:back": "nodemon",
|
||||||
"start:public": "ts-node back/public.ts",
|
"start:public": "ts-node --transpile-only ./back/public.ts",
|
||||||
"build:front": "max build",
|
"build:front": "max build",
|
||||||
"build:back": "tsc -p tsconfig.back.json",
|
"build:back": "tsc -p tsconfig.back.json",
|
||||||
"panel": "npm run build:back && node static/build/app.js",
|
"panel": "npm run build:back && node static/build/app.js",
|
||||||
@@ -42,7 +42,8 @@
|
|||||||
"monaco-editor",
|
"monaco-editor",
|
||||||
"rc-field-form",
|
"rc-field-form",
|
||||||
"@types/lodash.merge",
|
"@types/lodash.merge",
|
||||||
"rollup"
|
"rollup",
|
||||||
|
"styled-components"
|
||||||
],
|
],
|
||||||
"allowedVersions": {
|
"allowedVersions": {
|
||||||
"react": "18",
|
"react": "18",
|
||||||
@@ -69,18 +70,19 @@
|
|||||||
"got": "^11.8.2",
|
"got": "^11.8.2",
|
||||||
"hpagent": "^0.1.2",
|
"hpagent": "^0.1.2",
|
||||||
"iconv-lite": "^0.6.3",
|
"iconv-lite": "^0.6.3",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"multer": "^1.4.4",
|
"multer": "^1.4.4",
|
||||||
"nedb": "^1.8.0",
|
"nedb": "^1.8.0",
|
||||||
"node-schedule": "^2.1.0",
|
"node-schedule": "^2.1.0",
|
||||||
"nodemailer": "^6.7.2",
|
"nodemailer": "^6.7.2",
|
||||||
"p-queue": "7.2.0",
|
"pstree.remy": "^1.1.8",
|
||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"sequelize": "^6.20.1",
|
"sequelize": "^6.25.5",
|
||||||
"serve-handler": "^6.1.3",
|
"serve-handler": "^6.1.3",
|
||||||
"sockjs": "^0.3.24",
|
"sockjs": "^0.3.24",
|
||||||
"sqlite3": "npm:@louislam/sqlite3@^15.0.6",
|
"sqlite3": "git+https://github.com/whyour/node-sqlite3.git#v1.0.2",
|
||||||
"toad-scheduler": "^1.6.0",
|
"toad-scheduler": "^1.6.0",
|
||||||
"typedi": "^0.10.0",
|
"typedi": "^0.10.0",
|
||||||
"uuid": "^8.3.2",
|
"uuid": "^8.3.2",
|
||||||
@@ -89,15 +91,17 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ant-design/icons": "^4.7.0",
|
"@ant-design/icons": "^4.7.0",
|
||||||
"@ant-design/pro-layout": "^6.33.1",
|
"@ant-design/pro-layout": "6.38.22",
|
||||||
"@monaco-editor/react": "4.2.1",
|
"@monaco-editor/react": "4.4.6",
|
||||||
|
"@react-hook/resize-observer": "^1.2.6",
|
||||||
"@sentry/react": "^7.12.1",
|
"@sentry/react": "^7.12.1",
|
||||||
"@types/body-parser": "^1.19.2",
|
"@types/body-parser": "^1.19.2",
|
||||||
"@types/cors": "^2.8.12",
|
"@types/cors": "^2.8.12",
|
||||||
"@types/express": "^4.17.13",
|
"@types/express": "^4.17.13",
|
||||||
"@types/express-jwt": "^6.0.4",
|
"@types/express-jwt": "^6.0.4",
|
||||||
|
"@types/js-yaml": "^4.0.5",
|
||||||
"@types/jsonwebtoken": "^8.5.8",
|
"@types/jsonwebtoken": "^8.5.8",
|
||||||
"@types/lodash": "^4.14.179",
|
"@types/lodash": "^4.14.185",
|
||||||
"@types/multer": "^1.4.7",
|
"@types/multer": "^1.4.7",
|
||||||
"@types/nedb": "^1.8.12",
|
"@types/nedb": "^1.8.12",
|
||||||
"@types/node": "^17.0.21",
|
"@types/node": "^17.0.21",
|
||||||
@@ -105,20 +109,22 @@
|
|||||||
"@types/nodemailer": "^6.4.4",
|
"@types/nodemailer": "^6.4.4",
|
||||||
"@types/qrcode.react": "^1.0.2",
|
"@types/qrcode.react": "^1.0.2",
|
||||||
"@types/react": "^18.0.20",
|
"@types/react": "^18.0.20",
|
||||||
|
"@types/react-copy-to-clipboard": "^5.0.4",
|
||||||
"@types/react-dom": "^18.0.6",
|
"@types/react-dom": "^18.0.6",
|
||||||
"@types/serve-handler": "^6.1.1",
|
"@types/serve-handler": "^6.1.1",
|
||||||
"@types/sockjs": "^0.3.33",
|
"@types/sockjs": "^0.3.33",
|
||||||
"@types/sockjs-client": "^1.5.1",
|
"@types/sockjs-client": "^1.5.1",
|
||||||
"@types/uuid": "^8.3.4",
|
"@types/uuid": "^8.3.4",
|
||||||
"@umijs/max": "^4.0.21",
|
"@umijs/max": "^4.0.42",
|
||||||
"@umijs/ssr-darkreader": "^4.9.45",
|
"@umijs/ssr-darkreader": "^4.9.45",
|
||||||
"ansi-to-react": "^6.1.6",
|
"ansi-to-react": "^6.1.6",
|
||||||
"antd": "^4.23.0",
|
"antd": "^4.24.7",
|
||||||
"antd-img-crop": "^4.2.3",
|
"antd-img-crop": "^4.2.3",
|
||||||
"codemirror": "^5.65.2",
|
"codemirror": "^5.65.2",
|
||||||
"compression-webpack-plugin": "9.2.0",
|
"compression-webpack-plugin": "9.2.0",
|
||||||
"concurrently": "^7.0.0",
|
"concurrently": "^7.0.0",
|
||||||
"lint-staged": "^12.3.4",
|
"lint-staged": "^13.0.3",
|
||||||
|
"monaco-editor": "0.33.0",
|
||||||
"nodemon": "^2.0.15",
|
"nodemon": "^2.0.15",
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^2.5.1",
|
||||||
"qiniu": "^7.4.0",
|
"qiniu": "^7.4.0",
|
||||||
@@ -127,6 +133,7 @@
|
|||||||
"rc-tween-one": "^3.0.6",
|
"rc-tween-one": "^3.0.6",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-codemirror2": "^7.2.1",
|
"react-codemirror2": "^7.2.1",
|
||||||
|
"react-copy-to-clipboard": "^5.1.0",
|
||||||
"react-diff-viewer": "^3.1.1",
|
"react-diff-viewer": "^3.1.1",
|
||||||
"react-dnd": "^14.0.2",
|
"react-dnd": "^14.0.2",
|
||||||
"react-dnd-html5-backend": "^14.0.0",
|
"react-dnd-html5-backend": "^14.0.0",
|
||||||
@@ -135,9 +142,10 @@
|
|||||||
"sockjs-client": "^1.6.0",
|
"sockjs-client": "^1.6.0",
|
||||||
"ts-node": "^10.6.0",
|
"ts-node": "^10.6.0",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0",
|
||||||
"typescript": "^4.6.2",
|
"typescript": "4.8.4",
|
||||||
"umi-request": "^1.4.0",
|
"umi-request": "^1.4.0",
|
||||||
"vh-check": "^2.0.5",
|
"vh-check": "^2.0.5",
|
||||||
|
"virtuallist-antd": "^0.7.6",
|
||||||
"webpack": "^5.70.0",
|
"webpack": "^5.70.0",
|
||||||
"yorkie": "^2.0.0"
|
"yorkie": "^2.0.0"
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+15239
File diff suppressed because it is too large
Load Diff
+24
-2
@@ -16,7 +16,7 @@ DefaultCronRule=""
|
|||||||
## ql repo命令拉取脚本时需要拉取的文件后缀,直接写文件后缀名即可
|
## ql repo命令拉取脚本时需要拉取的文件后缀,直接写文件后缀名即可
|
||||||
RepoFileExtensions="js py"
|
RepoFileExtensions="js py"
|
||||||
|
|
||||||
## 代理地址,支持http/https/socks,例如 http://127.0.0.1:7890
|
## 代理地址,支持HTTP/SOCK5,例如 http://127.0.0.1:7890
|
||||||
ProxyUrl=""
|
ProxyUrl=""
|
||||||
|
|
||||||
## 资源告警阙值,默认CPU 80%、内存80%、磁盘90%
|
## 资源告警阙值,默认CPU 80%、内存80%、磁盘90%
|
||||||
@@ -67,7 +67,7 @@ export PUSH_KEY=""
|
|||||||
## 下方填写app提供的设备码,例如:https://api.day.app/123 那么此处的设备码就是123
|
## 下方填写app提供的设备码,例如:https://api.day.app/123 那么此处的设备码就是123
|
||||||
export BARK_PUSH=""
|
export BARK_PUSH=""
|
||||||
## 下方填写推送图标设置,自定义推送图标(需iOS15或以上)
|
## 下方填写推送图标设置,自定义推送图标(需iOS15或以上)
|
||||||
export BARK_ICON="http://qn.whyour.cn/logo.png"
|
export BARK_ICON="https://qn.whyour.cn/logo.png"
|
||||||
## 下方填写推送声音设置,例如choo,具体值请在bark-推送铃声-查看所有铃声
|
## 下方填写推送声音设置,例如choo,具体值请在bark-推送铃声-查看所有铃声
|
||||||
export BARK_SOUND=""
|
export BARK_SOUND=""
|
||||||
## 下方填写推送消息分组,默认为"QingLong"
|
## 下方填写推送消息分组,默认为"QingLong"
|
||||||
@@ -151,4 +151,26 @@ export DEER_KEY=""
|
|||||||
export CHAT_URL=""
|
export CHAT_URL=""
|
||||||
export CHAT_TOKEN=""
|
export CHAT_TOKEN=""
|
||||||
|
|
||||||
|
## 13. aibotk
|
||||||
|
## 官方说明文档:http://wechat.aibotk.com/oapi/oapi?from=ql
|
||||||
|
## aibotk_key (必填)填写智能微秘书个人中心的apikey
|
||||||
|
export AIBOTK_KEY=""
|
||||||
|
## aibotk_type (必填)填写发送的目标 room 或 contact, 填其他的不生效
|
||||||
|
export AIBOTK_TYPE=""
|
||||||
|
## aibotk_name (必填)填写群名或用户昵称,和上面的type类型要对应
|
||||||
|
export AIBOTK_NAME=""
|
||||||
|
|
||||||
|
## 14. SMTP
|
||||||
|
## 暂时只支持在 Python 中调用 notify.py 以发送 SMTP 邮件通知
|
||||||
|
## smtp_server 填写 SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
|
||||||
|
export SMTP_SERVER=""
|
||||||
|
## smtp_ssl 填写 SMTP 发送邮件服务器是否使用 SSL,内容应为 true 或 false
|
||||||
|
export SMTP_SSL="false"
|
||||||
|
## smtp_email 填写 SMTP 收发件邮箱,通知将会由自己发给自己
|
||||||
|
export SMTP_EMAIL=""
|
||||||
|
## smtp_password 填写 SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
||||||
|
export SMTP_PASSWORD=""
|
||||||
|
## smtp_name 填写 SMTP 收发件人姓名,可随意填写
|
||||||
|
export SMTP_NAME=""
|
||||||
|
|
||||||
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可
|
||||||
|
|||||||
+269
-155
@@ -38,6 +38,7 @@ let SCKEY = '';
|
|||||||
//此处填你申请的PushDeer KEY.
|
//此处填你申请的PushDeer KEY.
|
||||||
//(环境变量名 DEER_KEY)
|
//(环境变量名 DEER_KEY)
|
||||||
let PUSHDEER_KEY = '';
|
let PUSHDEER_KEY = '';
|
||||||
|
let PUSHDEER_URL = '';
|
||||||
|
|
||||||
// =======================================Synology Chat通知设置区域===========================================
|
// =======================================Synology Chat通知设置区域===========================================
|
||||||
//此处填你申请的CHAT_URL与CHAT_TOKEN
|
//此处填你申请的CHAT_URL与CHAT_TOKEN
|
||||||
@@ -49,7 +50,7 @@ let CHAT_TOKEN = '';
|
|||||||
//此处填你BarkAPP的信息(IP/设备码,例如:https://api.day.app/XXXXXXXX)
|
//此处填你BarkAPP的信息(IP/设备码,例如:https://api.day.app/XXXXXXXX)
|
||||||
let BARK_PUSH = '';
|
let BARK_PUSH = '';
|
||||||
//BARK app推送图标,自定义推送图标(需iOS15或以上)
|
//BARK app推送图标,自定义推送图标(需iOS15或以上)
|
||||||
let BARK_ICON = 'http://qn.whyour.cn/logo.png';
|
let BARK_ICON = 'https://qn.whyour.cn/logo.png';
|
||||||
//BARK app推送铃声,铃声列表去APP查看复制填写
|
//BARK app推送铃声,铃声列表去APP查看复制填写
|
||||||
let BARK_SOUND = '';
|
let BARK_SOUND = '';
|
||||||
//BARK app推送消息的分组, 默认为"QingLong"
|
//BARK app推送消息的分组, 默认为"QingLong"
|
||||||
@@ -110,6 +111,32 @@ let PUSH_PLUS_USER = '';
|
|||||||
let QQ_SKEY = '';
|
let QQ_SKEY = '';
|
||||||
let QQ_MODE = '';
|
let QQ_MODE = '';
|
||||||
|
|
||||||
|
// =======================================智能微秘书设置区域=======================================
|
||||||
|
//官方文档:http://wechat.aibotk.com/docs/about
|
||||||
|
//AIBOTK_KEY: 填写智能微秘书个人中心的apikey
|
||||||
|
//AIBOTK_TYPE:填写发送的目标 room 或 contact, 填其他的不生效
|
||||||
|
//AIBOTK_NAME: 填写群名或用户昵称,和上面的type类型要对应
|
||||||
|
let AIBOTK_KEY = '';
|
||||||
|
let AIBOTK_TYPE = '';
|
||||||
|
let AIBOTK_NAME = '';
|
||||||
|
|
||||||
|
// =======================================飞书机器人设置区域=======================================
|
||||||
|
//官方文档:https://www.feishu.cn/hc/zh-CN/articles/360024984973
|
||||||
|
//FSKEY 飞书机器人的 FSKEY
|
||||||
|
let FSKEY = '';
|
||||||
|
|
||||||
|
// =======================================SMTP 邮件设置区域=======================================
|
||||||
|
// SMTP_SERVER: 填写 SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
|
||||||
|
// SMTP_SSL: 填写 SMTP 发送邮件服务器是否使用 SSL,内容应为 true 或 false
|
||||||
|
// SMTP_EMAIL: 填写 SMTP 收发件邮箱,通知将会由自己发给自己
|
||||||
|
// SMTP_PASSWORD: 填写 SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
||||||
|
// SMTP_NAME: 填写 SMTP 收发件人姓名,可随意填写
|
||||||
|
let SMTP_SERVER = '';
|
||||||
|
let SMTP_SSL = 'false';
|
||||||
|
let SMTP_EMAIL = '';
|
||||||
|
let SMTP_PASSWORD = '';
|
||||||
|
let SMTP_NAME = '';
|
||||||
|
|
||||||
//==========================云端环境变量的判断与接收=========================
|
//==========================云端环境变量的判断与接收=========================
|
||||||
if (process.env.GOTIFY_URL) {
|
if (process.env.GOTIFY_URL) {
|
||||||
GOTIFY_URL = process.env.GOTIFY_URL;
|
GOTIFY_URL = process.env.GOTIFY_URL;
|
||||||
@@ -137,6 +164,7 @@ if (process.env.PUSH_KEY) {
|
|||||||
|
|
||||||
if (process.env.DEER_KEY) {
|
if (process.env.DEER_KEY) {
|
||||||
PUSHDEER_KEY = process.env.DEER_KEY;
|
PUSHDEER_KEY = process.env.DEER_KEY;
|
||||||
|
PUSHDEER_URL = process.env.DEER_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.CHAT_URL) {
|
if (process.env.CHAT_URL) {
|
||||||
@@ -220,6 +248,36 @@ if (process.env.PUSH_PLUS_TOKEN) {
|
|||||||
if (process.env.PUSH_PLUS_USER) {
|
if (process.env.PUSH_PLUS_USER) {
|
||||||
PUSH_PLUS_USER = process.env.PUSH_PLUS_USER;
|
PUSH_PLUS_USER = process.env.PUSH_PLUS_USER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.AIBOTK_KEY) {
|
||||||
|
AIBOTK_KEY = process.env.AIBOTK_KEY;
|
||||||
|
}
|
||||||
|
if (process.env.AIBOTK_TYPE) {
|
||||||
|
AIBOTK_TYPE = process.env.AIBOTK_TYPE;
|
||||||
|
}
|
||||||
|
if (process.env.AIBOTK_NAME) {
|
||||||
|
AIBOTK_NAME = process.env.AIBOTK_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.FSKEY) {
|
||||||
|
FSKEY = process.env.FSKEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.env.SMTP_SERVER) {
|
||||||
|
SMTP_SERVER = process.env.SMTP_SERVER;
|
||||||
|
}
|
||||||
|
if (process.env.SMTP_SSL) {
|
||||||
|
SMTP_SSL = process.env.SMTP_SSL;
|
||||||
|
}
|
||||||
|
if (process.env.SMTP_EMAIL) {
|
||||||
|
SMTP_EMAIL = process.env.SMTP_EMAIL;
|
||||||
|
}
|
||||||
|
if (process.env.SMTP_PASSWORD) {
|
||||||
|
SMTP_PASSWORD = process.env.SMTP_PASSWORD;
|
||||||
|
}
|
||||||
|
if (process.env.SMTP_NAME) {
|
||||||
|
SMTP_NAME = process.env.SMTP_NAME;
|
||||||
|
}
|
||||||
//==========================云端环境变量的判断与接收=========================
|
//==========================云端环境变量的判断与接收=========================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -255,6 +313,9 @@ async function sendNotify(
|
|||||||
gotifyNotify(text, desp), //gotify
|
gotifyNotify(text, desp), //gotify
|
||||||
ChatNotify(text, desp), //synolog chat
|
ChatNotify(text, desp), //synolog chat
|
||||||
PushDeerNotify(text, desp), //PushDeer
|
PushDeerNotify(text, desp), //PushDeer
|
||||||
|
aibotkNotify(text, desp), //智能微秘书
|
||||||
|
fsBotNotify(text, desp), //飞书机器人
|
||||||
|
smtpNotify(text, desp), //SMTP 邮件
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +356,7 @@ function gotifyNotify(text, desp) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function gobotNotify(text, desp, time = 2100) {
|
function gobotNotify(text, desp) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (GOBOT_URL) {
|
if (GOBOT_URL) {
|
||||||
const options = {
|
const options = {
|
||||||
@@ -306,38 +367,34 @@ function gobotNotify(text, desp, time = 2100) {
|
|||||||
},
|
},
|
||||||
timeout,
|
timeout,
|
||||||
};
|
};
|
||||||
setTimeout(() => {
|
$.post(options, (err, resp, data) => {
|
||||||
$.post(options, (err, resp, data) => {
|
try {
|
||||||
try {
|
if (err) {
|
||||||
if (err) {
|
console.log('发送go-cqhttp通知调用API失败!!\n');
|
||||||
console.log('发送go-cqhttp通知调用API失败!!\n');
|
console.log(err);
|
||||||
console.log(err);
|
} else {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
if (data.retcode === 0) {
|
||||||
|
console.log('go-cqhttp发送通知消息成功🎉\n');
|
||||||
|
} else if (data.retcode === 100) {
|
||||||
|
console.log(`go-cqhttp发送通知消息异常: ${data.errmsg}\n`);
|
||||||
} else {
|
} else {
|
||||||
data = JSON.parse(data);
|
console.log(`go-cqhttp发送通知消息异常\n${JSON.stringify(data)}`);
|
||||||
if (data.retcode === 0) {
|
|
||||||
console.log('go-cqhttp发送通知消息成功🎉\n');
|
|
||||||
} else if (data.retcode === 100) {
|
|
||||||
console.log(`go-cqhttp发送通知消息异常: ${data.errmsg}\n`);
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
`go-cqhttp发送通知消息异常\n${JSON.stringify(data)}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
$.logErr(e, resp);
|
|
||||||
} finally {
|
|
||||||
resolve(data);
|
|
||||||
}
|
}
|
||||||
});
|
} catch (e) {
|
||||||
}, time);
|
$.logErr(e, resp);
|
||||||
|
} finally {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function serverNotify(text, desp, time = 2100) {
|
function serverNotify(text, desp) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (SCKEY) {
|
if (SCKEY) {
|
||||||
//微信server酱推送通知一个\n不会换行,需要两个\n才能换行,故做此替换
|
//微信server酱推送通知一个\n不会换行,需要两个\n才能换行,故做此替换
|
||||||
@@ -352,33 +409,29 @@ function serverNotify(text, desp, time = 2100) {
|
|||||||
},
|
},
|
||||||
timeout,
|
timeout,
|
||||||
};
|
};
|
||||||
setTimeout(() => {
|
$.post(options, (err, resp, data) => {
|
||||||
$.post(options, (err, resp, data) => {
|
try {
|
||||||
try {
|
if (err) {
|
||||||
if (err) {
|
console.log('发送通知调用API失败!!\n');
|
||||||
console.log('发送通知调用API失败!!\n');
|
console.log(err);
|
||||||
console.log(err);
|
} else {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
//server酱和Server酱·Turbo版的返回json格式不太一样
|
||||||
|
if (data.errno === 0 || data.data.errno === 0) {
|
||||||
|
console.log('server酱发送通知消息成功🎉\n');
|
||||||
|
} else if (data.errno === 1024) {
|
||||||
|
// 一分钟内发送相同的内容会触发
|
||||||
|
console.log(`server酱发送通知消息异常: ${data.errmsg}\n`);
|
||||||
} else {
|
} else {
|
||||||
data = JSON.parse(data);
|
console.log(`server酱发送通知消息异常\n${JSON.stringify(data)}`);
|
||||||
//server酱和Server酱·Turbo版的返回json格式不太一样
|
|
||||||
if (data.errno === 0 || data.data.errno === 0) {
|
|
||||||
console.log('server酱发送通知消息成功🎉\n');
|
|
||||||
} else if (data.errno === 1024) {
|
|
||||||
// 一分钟内发送相同的内容会触发
|
|
||||||
console.log(`server酱发送通知消息异常: ${data.errmsg}\n`);
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
`server酱发送通知消息异常\n${JSON.stringify(data)}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
$.logErr(e, resp);
|
|
||||||
} finally {
|
|
||||||
resolve(data);
|
|
||||||
}
|
}
|
||||||
});
|
} catch (e) {
|
||||||
}, time);
|
$.logErr(e, resp);
|
||||||
|
} finally {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
@@ -391,42 +444,36 @@ function PushDeerNotify(text, desp) {
|
|||||||
// PushDeer 建议对消息内容进行 urlencode
|
// PushDeer 建议对消息内容进行 urlencode
|
||||||
desp = encodeURI(desp);
|
desp = encodeURI(desp);
|
||||||
const options = {
|
const options = {
|
||||||
url: `https://api2.pushdeer.com/message/push`,
|
url: PUSHDEER_URL || `https://api2.pushdeer.com/message/push`,
|
||||||
body: `pushkey=${PUSHDEER_KEY}&text=${text}&desp=${desp}&type=markdown`,
|
body: `pushkey=${PUSHDEER_KEY}&text=${text}&desp=${desp}&type=markdown`,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
},
|
},
|
||||||
timeout,
|
timeout,
|
||||||
};
|
};
|
||||||
$.post(
|
$.post(options, (err, resp, data) => {
|
||||||
options,
|
try {
|
||||||
(err, resp, data) => {
|
if (err) {
|
||||||
try {
|
console.log('发送通知调用API失败!!\n');
|
||||||
if (err) {
|
console.log(err);
|
||||||
console.log('发送通知调用API失败!!\n');
|
} else {
|
||||||
console.log(err);
|
data = JSON.parse(data);
|
||||||
|
// 通过返回的result的长度来判断是否成功
|
||||||
|
if (
|
||||||
|
data.content.result.length !== undefined &&
|
||||||
|
data.content.result.length > 0
|
||||||
|
) {
|
||||||
|
console.log('PushDeer发送通知消息成功🎉\n');
|
||||||
} else {
|
} else {
|
||||||
data = JSON.parse(data);
|
console.log(`PushDeer发送通知消息异常\n${JSON.stringify(data)}`);
|
||||||
// 通过返回的result的长度来判断是否成功
|
|
||||||
if (
|
|
||||||
data.content.result.length !== undefined &&
|
|
||||||
data.content.result.length > 0
|
|
||||||
) {
|
|
||||||
console.log('PushDeer发送通知消息成功🎉\n');
|
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
`PushDeer发送通知消息异常\n${JSON.stringify(data)}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
|
||||||
$.logErr(e, resp);
|
|
||||||
} finally {
|
|
||||||
resolve(data);
|
|
||||||
}
|
}
|
||||||
},
|
} catch (e) {
|
||||||
time,
|
$.logErr(e, resp);
|
||||||
);
|
} finally {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
@@ -470,83 +517,6 @@ function ChatNotify(text, desp) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function CoolPush(text, desp) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
if (QQ_SKEY) {
|
|
||||||
let options = {
|
|
||||||
url: `https://push.xuthus.cc/${QQ_MODE}/${QQ_SKEY}`,
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// 已知敏感词
|
|
||||||
text = text.replace(/京豆/g, '豆豆');
|
|
||||||
desp = desp.replace(/京豆/g, '');
|
|
||||||
desp = desp.replace(/🐶/g, '');
|
|
||||||
desp = desp.replace(/红包/g, 'H包');
|
|
||||||
|
|
||||||
switch (QQ_MODE) {
|
|
||||||
case 'email':
|
|
||||||
options.json = {
|
|
||||||
t: text,
|
|
||||||
c: desp,
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
options.body = `${text}\n\n${desp}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let pushMode = function (t) {
|
|
||||||
switch (t) {
|
|
||||||
case 'send':
|
|
||||||
return '个人';
|
|
||||||
case 'group':
|
|
||||||
return 'QQ群';
|
|
||||||
case 'wx':
|
|
||||||
return '微信';
|
|
||||||
case 'ww':
|
|
||||||
return '企业微信';
|
|
||||||
case 'email':
|
|
||||||
return '邮件';
|
|
||||||
default:
|
|
||||||
return '未知方式';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$.post(options, (err, resp, data) => {
|
|
||||||
try {
|
|
||||||
if (err) {
|
|
||||||
console.log(`发送${pushMode(QQ_MODE)}通知调用API失败!!\n`);
|
|
||||||
console.log(err);
|
|
||||||
} else {
|
|
||||||
data = JSON.parse(data);
|
|
||||||
if (data.code === 200) {
|
|
||||||
console.log(`酷推发送${pushMode(QQ_MODE)}通知消息成功🎉\n`);
|
|
||||||
} else if (data.code === 400) {
|
|
||||||
console.log(
|
|
||||||
`QQ酷推(Cool Push)发送${pushMode(QQ_MODE)}推送失败:${
|
|
||||||
data.msg
|
|
||||||
}\n`,
|
|
||||||
);
|
|
||||||
} else if (data.code === 503) {
|
|
||||||
console.log(`QQ酷推出错,${data.message}:${data.data}\n`);
|
|
||||||
} else {
|
|
||||||
console.log(`酷推推送异常: ${JSON.stringify(data)}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
$.logErr(e, resp);
|
|
||||||
} finally {
|
|
||||||
resolve(data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function BarkNotify(text, desp, params = {}) {
|
function BarkNotify(text, desp, params = {}) {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
if (BARK_PUSH) {
|
if (BARK_PUSH) {
|
||||||
@@ -649,7 +619,7 @@ function ddBotNotify(text, desp) {
|
|||||||
json: {
|
json: {
|
||||||
msgtype: 'text',
|
msgtype: 'text',
|
||||||
text: {
|
text: {
|
||||||
content: ` ${text}\n\n${desp}`,
|
content: `${text}\n\n${desp}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
headers: {
|
headers: {
|
||||||
@@ -716,7 +686,7 @@ function qywxBotNotify(text, desp) {
|
|||||||
json: {
|
json: {
|
||||||
msgtype: 'text',
|
msgtype: 'text',
|
||||||
text: {
|
text: {
|
||||||
content: ` ${text}\n\n${desp}`,
|
content: `${text}\n\n${desp}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
headers: {
|
headers: {
|
||||||
@@ -983,6 +953,150 @@ function pushPlusNotify(text, desp) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function aibotkNotify(text, desp) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (AIBOTK_KEY && AIBOTK_TYPE && AIBOTK_NAME) {
|
||||||
|
let json = {};
|
||||||
|
let url = '';
|
||||||
|
switch (AIBOTK_TYPE) {
|
||||||
|
case 'room':
|
||||||
|
url = 'https://api-bot.aibotk.com/openapi/v1/chat/room';
|
||||||
|
json = {
|
||||||
|
apiKey: `${AIBOTK_KEY}`,
|
||||||
|
roomName: `${AIBOTK_NAME}`,
|
||||||
|
message: {
|
||||||
|
type: 1,
|
||||||
|
content: `【青龙快讯】\n\n${text}\n${desp}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
case 'contact':
|
||||||
|
url = 'https://api-bot.aibotk.com/openapi/v1/chat/contact';
|
||||||
|
json = {
|
||||||
|
apiKey: `${AIBOTK_KEY}`,
|
||||||
|
name: `${AIBOTK_NAME}`,
|
||||||
|
message: {
|
||||||
|
type: 1,
|
||||||
|
content: `【青龙快讯】\n\n${text}\n${desp}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
const options = {
|
||||||
|
url: url,
|
||||||
|
json,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
timeout,
|
||||||
|
};
|
||||||
|
$.post(options, (err, resp, data) => {
|
||||||
|
try {
|
||||||
|
if (err) {
|
||||||
|
console.log('智能微秘书发送通知消息失败!!\n');
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
if (data.code === 0) {
|
||||||
|
console.log('智能微秘书发送通知消息成功🎉。\n');
|
||||||
|
} else {
|
||||||
|
console.log(`${data.error}\n`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
$.logErr(e, resp);
|
||||||
|
} finally {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function fsBotNotify(text, desp) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (FSKEY) {
|
||||||
|
const options = {
|
||||||
|
url: `https://open.feishu.cn/open-apis/bot/v2/hook/${FSKEY}`,
|
||||||
|
json: { msg_type: 'text', content: { text: `${text}\n\n${desp}` } },
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
timeout,
|
||||||
|
};
|
||||||
|
$.post(options, (err, resp, data) => {
|
||||||
|
try {
|
||||||
|
if (err) {
|
||||||
|
console.log('发送通知调用API失败!!\n');
|
||||||
|
console.log(err);
|
||||||
|
} else {
|
||||||
|
data = JSON.parse(data);
|
||||||
|
if (data.StatusCode === 0) {
|
||||||
|
console.log('飞书发送通知消息成功🎉\n');
|
||||||
|
} else {
|
||||||
|
console.log(`${data.msg}\n`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
$.logErr(e, resp);
|
||||||
|
} finally {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function smtpNotify(text, desp) {
|
||||||
|
if (![SMTP_SERVER, SMTP_EMAIL, SMTP_PASSWORD].every(Boolean)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const nodemailer = require('nodemailer');
|
||||||
|
const transporter = nodemailer.createTransport(
|
||||||
|
`${SMTP_SSL === 'true' ? 'smtps:' : 'smtp:'}//${SMTP_SERVER}`,
|
||||||
|
{
|
||||||
|
auth: {
|
||||||
|
user: SMTP_EMAIL,
|
||||||
|
pass: SMTP_PASSWORD,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const addr = SMTP_NAME ? `"${SMTP_NAME}" <${SMTP_EMAIL}>` : SMTP_EMAIL;
|
||||||
|
const info = await transporter.sendMail({
|
||||||
|
from: addr,
|
||||||
|
to: addr,
|
||||||
|
subject: text,
|
||||||
|
text: desp,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!!info.messageId) {
|
||||||
|
console.log('SMTP发送通知消息成功🎉\n');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
console.log('SMTP发送通知消息失败!!\n');
|
||||||
|
} catch (e) {
|
||||||
|
console.log('SMTP发送通知消息出现错误!!\n');
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function smtpNotify(text, desp) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
if (SMTP_SERVER && SMTP_SSL && SMTP_EMAIL && SMTP_PASSWORD && SMTP_NAME) {
|
||||||
|
// todo: Node.js并没有内置的 smtp 实现,需要调用外部库,因为不清楚这个文件的模块依赖情况,所以留给有缘人实现
|
||||||
|
} else {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
sendNotify,
|
sendNotify,
|
||||||
BARK_PUSH,
|
BARK_PUSH,
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ import re
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import smtplib
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from email.header import Header
|
||||||
|
from email.utils import formataddr
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@@ -61,6 +65,7 @@ push_config = {
|
|||||||
'PUSH_KEY': '', # server 酱的 PUSH_KEY,兼容旧版与 Turbo 版
|
'PUSH_KEY': '', # server 酱的 PUSH_KEY,兼容旧版与 Turbo 版
|
||||||
|
|
||||||
'DEER_KEY': '', # PushDeer 的 PUSHDEER_KEY
|
'DEER_KEY': '', # PushDeer 的 PUSHDEER_KEY
|
||||||
|
'DEER_URL': '', # PushDeer 的 PUSHDEER_URL
|
||||||
|
|
||||||
'CHAT_URL': '', # synology chat url
|
'CHAT_URL': '', # synology chat url
|
||||||
'CHAT_TOKEN': '', # synology chat token
|
'CHAT_TOKEN': '', # synology chat token
|
||||||
@@ -81,6 +86,16 @@ push_config = {
|
|||||||
'TG_PROXY_AUTH': '', # tg 代理认证参数
|
'TG_PROXY_AUTH': '', # tg 代理认证参数
|
||||||
'TG_PROXY_HOST': '', # tg 机器人的 TG_PROXY_HOST
|
'TG_PROXY_HOST': '', # tg 机器人的 TG_PROXY_HOST
|
||||||
'TG_PROXY_PORT': '', # tg 机器人的 TG_PROXY_PORT
|
'TG_PROXY_PORT': '', # tg 机器人的 TG_PROXY_PORT
|
||||||
|
|
||||||
|
'AIBOTK_KEY': '', # 智能微秘书 个人中心的apikey 文档地址:http://wechat.aibotk.com/docs/about
|
||||||
|
'AIBOTK_TYPE': '', # 智能微秘书 发送目标 room 或 contact
|
||||||
|
'AIBOTK_NAME': '', # 智能微秘书 发送群名 或者好友昵称和type要对应好
|
||||||
|
|
||||||
|
'SMTP_SERVER': '', # SMTP 发送邮件服务器,形如 smtp.exmail.qq.com:465
|
||||||
|
'SMTP_SSL': 'false', # SMTP 发送邮件服务器是否使用 SSL,填写 true 或 false
|
||||||
|
'SMTP_EMAIL': '', # SMTP 收发件邮箱,通知将会由自己发给自己
|
||||||
|
'SMTP_PASSWORD': '', # SMTP 登录密码,也可能为特殊口令,视具体邮件服务商说明而定
|
||||||
|
'SMTP_NAME': '', # SMTP 收发件人姓名,可随意填写
|
||||||
}
|
}
|
||||||
notify_function = []
|
notify_function = []
|
||||||
# fmt: on
|
# fmt: on
|
||||||
@@ -276,6 +291,9 @@ def pushdeer(title: str, content: str) -> None:
|
|||||||
print("PushDeer 服务启动")
|
print("PushDeer 服务启动")
|
||||||
data = {"text": title, "desp": content, "type": "markdown", "pushkey": push_config.get("DEER_KEY")}
|
data = {"text": title, "desp": content, "type": "markdown", "pushkey": push_config.get("DEER_KEY")}
|
||||||
url = 'https://api2.pushdeer.com/message/push'
|
url = 'https://api2.pushdeer.com/message/push'
|
||||||
|
if push_config.get("DEER_URL"):
|
||||||
|
url = push_config.get("DEER_URL")
|
||||||
|
|
||||||
response = requests.post(url, data=data).json()
|
response = requests.post(url, data=data).json()
|
||||||
|
|
||||||
if len(response.get("content").get("result")) > 0:
|
if len(response.get("content").get("result")) > 0:
|
||||||
@@ -521,6 +539,63 @@ def telegram_bot(title: str, content: str) -> None:
|
|||||||
print("tg 推送失败!")
|
print("tg 推送失败!")
|
||||||
|
|
||||||
|
|
||||||
|
def aibotk(title: str, content: str) -> None:
|
||||||
|
"""
|
||||||
|
使用 智能微秘书 推送消息。
|
||||||
|
"""
|
||||||
|
if not push_config.get("AIBOTK_KEY") or not push_config.get("AIBOTK_TYPE") or not push_config.get("AIBOTK_NAME"):
|
||||||
|
print("智能微秘书 的 AIBOTK_KEY 或者 AIBOTK_TYPE 或者 AIBOTK_NAME 未设置!!\n取消推送")
|
||||||
|
return
|
||||||
|
print("智能微秘书 服务启动")
|
||||||
|
|
||||||
|
if push_config.get("AIBOTK_TYPE") == 'room':
|
||||||
|
url = "https://api-bot.aibotk.com/openapi/v1/chat/room"
|
||||||
|
data = {
|
||||||
|
"apiKey": push_config.get("AIBOTK_KEY"),
|
||||||
|
"roomName": push_config.get("AIBOTK_NAME"),
|
||||||
|
"message": {"type": 1, "content": f'【青龙快讯】\n\n${title}\n${content}' }
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
url = "https://api-bot.aibotk.com/openapi/v1/chat/contact"
|
||||||
|
data = {
|
||||||
|
"apiKey": push_config.get("AIBOTK_KEY"),
|
||||||
|
"name": push_config.get("AIBOTK_NAME"),
|
||||||
|
"message": {"type": 1, "content": f'【青龙快讯】\n\n${title}\n${content}' }
|
||||||
|
}
|
||||||
|
body = json.dumps(data).encode(encoding="utf-8")
|
||||||
|
headers = {"Content-Type": "application/json"}
|
||||||
|
response = requests.post(url=url, data=body, headers=headers).json()
|
||||||
|
print(response)
|
||||||
|
if response["code"] == 0:
|
||||||
|
print("智能微秘书 推送成功!")
|
||||||
|
else:
|
||||||
|
print(f'智能微秘书 推送失败!{response["error"]}')
|
||||||
|
|
||||||
|
|
||||||
|
def smtp(title: str, content: str) -> None:
|
||||||
|
"""
|
||||||
|
使用 SMTP 邮件 推送消息。
|
||||||
|
"""
|
||||||
|
if not push_config.get("SMTP_SERVER") or not push_config.get("SMTP_SSL") or not push_config.get("SMTP_EMAIL") or not push_config.get("SMTP_PASSWORD") or not push_config.get("SMTP_NAME"):
|
||||||
|
print("SMTP 邮件 的 SMTP_SERVER 或者 SMTP_SSL 或者 SMTP_EMAIL 或者 SMTP_PASSWORD 或者 SMTP_NAME 未设置!!\n取消推送")
|
||||||
|
return
|
||||||
|
print("SMTP 邮件 服务启动")
|
||||||
|
|
||||||
|
message = MIMEText(content, 'plain', 'utf-8')
|
||||||
|
message['From'] = formataddr((Header(push_config.get("SMTP_NAME"), 'utf-8').encode(), push_config.get("SMTP_EMAIL")))
|
||||||
|
message['To'] = formataddr((Header(push_config.get("SMTP_NAME"), 'utf-8').encode(), push_config.get("SMTP_EMAIL")))
|
||||||
|
message['Subject'] = Header(title, 'utf-8')
|
||||||
|
|
||||||
|
try:
|
||||||
|
smtp_server = smtplib.SMTP_SSL(push_config.get("SMTP_SERVER")) if push_config.get("SMTP_SSL") == 'true' else smtplib.SMTP(push_config.get("SMTP_SERVER"))
|
||||||
|
smtp_server.login(push_config.get("SMTP_EMAIL"), push_config.get("SMTP_PASSWORD"))
|
||||||
|
smtp_server.sendmail(push_config.get("SMTP_EMAIL"), push_config.get("SMTP_EMAIL"), message.as_bytes())
|
||||||
|
smtp_server.close()
|
||||||
|
print("SMTP 邮件 推送成功!")
|
||||||
|
except Exception as e:
|
||||||
|
print(f'SMTP 邮件 推送失败!{e}')
|
||||||
|
|
||||||
|
|
||||||
def one() -> str:
|
def one() -> str:
|
||||||
"""
|
"""
|
||||||
获取一条一言。
|
获取一条一言。
|
||||||
@@ -561,6 +636,10 @@ if push_config.get("QYWX_KEY"):
|
|||||||
notify_function.append(wecom_bot)
|
notify_function.append(wecom_bot)
|
||||||
if push_config.get("TG_BOT_TOKEN") and push_config.get("TG_USER_ID"):
|
if push_config.get("TG_BOT_TOKEN") and push_config.get("TG_USER_ID"):
|
||||||
notify_function.append(telegram_bot)
|
notify_function.append(telegram_bot)
|
||||||
|
if push_config.get("AIBOTK_KEY") and push_config.get("AIBOTK_TYPE") and push_config.get("AIBOTK_NAME"):
|
||||||
|
notify_function.append(aibotk)
|
||||||
|
if push_config.get("SMTP_SERVER") and push_config.get("SMTP_SSL") and push_config.get("SMTP_EMAIL") and push_config.get("SMTP_PASSWORD") and push_config.get("SMTP_NAME"):
|
||||||
|
notify_function.append(smtp)
|
||||||
|
|
||||||
|
|
||||||
def send(title: str, content: str) -> None:
|
def send(title: str, content: str) -> None:
|
||||||
|
|||||||
+2
-1
@@ -5,8 +5,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"crypto-js": "^4.0.0",
|
"crypto-js": "^4.0.0",
|
||||||
"download": "^8.0.0",
|
"download": "^8.0.0",
|
||||||
"http-server": "^0.12.3",
|
|
||||||
"got": "^11.5.1",
|
"got": "^11.5.1",
|
||||||
|
"http-server": "^0.12.3",
|
||||||
|
"nodemailer": "^6.8.0",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"tough-cookie": "^4.0.0",
|
"tough-cookie": "^4.0.0",
|
||||||
|
|||||||
+2
-2
@@ -5,14 +5,14 @@ const envFound = dotenv.config();
|
|||||||
const accessKey = process.env.QINIU_AK;
|
const accessKey = process.env.QINIU_AK;
|
||||||
const secretKey = process.env.QINIU_SK;
|
const secretKey = process.env.QINIU_SK;
|
||||||
const mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
|
const mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
|
||||||
const key = 'version.ts';
|
const key = 'version.yaml';
|
||||||
const options = {
|
const options = {
|
||||||
scope: `${process.env.QINIU_SCOPE}:${key}`,
|
scope: `${process.env.QINIU_SCOPE}:${key}`,
|
||||||
};
|
};
|
||||||
const putPolicy = new qiniu.rs.PutPolicy(options);
|
const putPolicy = new qiniu.rs.PutPolicy(options);
|
||||||
const uploadToken = putPolicy.uploadToken(mac);
|
const uploadToken = putPolicy.uploadToken(mac);
|
||||||
|
|
||||||
const localFile = 'src/version.ts';
|
const localFile = 'version.yaml';
|
||||||
const config = new qiniu.conf.Config({ zone: qiniu.zone.Zone_z1 });
|
const config = new qiniu.conf.Config({ zone: qiniu.zone.Zone_z1 });
|
||||||
const formUploader = new qiniu.form_up.FormUploader(config);
|
const formUploader = new qiniu.form_up.FormUploader(config);
|
||||||
const putExtra = new qiniu.form_up.PutExtra(
|
const putExtra = new qiniu.form_up.PutExtra(
|
||||||
|
|||||||
+10
-1
@@ -1,7 +1,16 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
get_token() {
|
get_token() {
|
||||||
token=$(cat $file_auth_token | jq -r .value)
|
if [[ -f $file_auth_token ]]; then
|
||||||
|
token=$(cat $file_auth_token | jq -r .value)
|
||||||
|
else
|
||||||
|
local token_command="ts-node-transpile-only ${dir_root}/back/token.ts"
|
||||||
|
local token_file="${dir_root}static/build/token.js"
|
||||||
|
if [[ -f $token_file ]]; then
|
||||||
|
token_command="node ${token_file}"
|
||||||
|
fi
|
||||||
|
token=$(eval "$token_command")
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
add_cron_api() {
|
add_cron_api() {
|
||||||
|
|||||||
+8
-3
@@ -87,13 +87,18 @@ check_pm2() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start_public() {
|
||||||
|
echo -e "=====> 启动公开服务\n"
|
||||||
|
pm2 delete public --source-map-support --time &>/dev/null
|
||||||
|
pm2 start $dir_static/build/public.js -n public --source-map-support --time &>/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
echo -e "=====> 开始检测"
|
echo -e "=====> 开始检测"
|
||||||
npm i -g pnpm
|
npm i -g pnpm
|
||||||
pnpm setup &>/dev/null
|
|
||||||
source ~/.bashrc
|
|
||||||
pnpm install -g &>/dev/null
|
|
||||||
pnpm add -g pm2
|
pnpm add -g pm2
|
||||||
|
patch_version
|
||||||
|
start_public
|
||||||
copy_dep
|
copy_dep
|
||||||
check_ql
|
check_ql
|
||||||
check_nginx
|
check_nginx
|
||||||
|
|||||||
+281
@@ -0,0 +1,281 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
## 导入通用变量与函数
|
||||||
|
dir_shell=$QL_DIR/shell
|
||||||
|
. $dir_shell/share.sh
|
||||||
|
. $dir_shell/api.sh
|
||||||
|
|
||||||
|
trap "single_hanle" 2 20 15 14
|
||||||
|
single_hanle() {
|
||||||
|
handle_task_after "$@"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
random_delay() {
|
||||||
|
local random_delay_max=$RandomDelay
|
||||||
|
if [[ $random_delay_max ]] && [[ $random_delay_max -gt 0 ]]; then
|
||||||
|
local file_param=$1
|
||||||
|
local file_extensions=${RandomDelayFileExtensions-"js"}
|
||||||
|
local ignored_minutes=${RandomDelayIgnoredMinutes-"0 30"}
|
||||||
|
|
||||||
|
if [[ -n $file_extensions ]]; then
|
||||||
|
if ! echo "$file_param" | grep -qE "\.${file_extensions// /$|\\.}$"; then
|
||||||
|
# echo -e "\n当前文件需要准点运行, 放弃随机延迟\n"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
local current_min
|
||||||
|
current_min=$(date "+%-M")
|
||||||
|
for minute in $ignored_minutes; do
|
||||||
|
if [[ $current_min -eq $minute ]]; then
|
||||||
|
# echo -e "\n当前时间需要准点运行, 放弃随机延迟\n"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
local delay_second=$(($(gen_random_num "$random_delay_max") + 1))
|
||||||
|
echo -e "\n命令未添加 \"now\",随机延迟 $delay_second 秒后执行\n"
|
||||||
|
sleep $delay_second
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
## scripts目录下所有可运行脚本数组
|
||||||
|
gen_array_scripts() {
|
||||||
|
local dir_current=$(pwd)
|
||||||
|
local i="-1"
|
||||||
|
cd $dir_scripts
|
||||||
|
for file in $(ls); do
|
||||||
|
if [[ -f $file ]] && [[ $file == *.js && $file != sendNotify.js ]]; then
|
||||||
|
let i++
|
||||||
|
array_scripts[i]=$(echo "$file" | perl -pe "s|$dir_scripts/||g")
|
||||||
|
array_scripts_name[i]=$(grep "new Env" $file | awk -F "'|\"" '{print $2}' | head -1)
|
||||||
|
[[ -z ${array_scripts_name[i]} ]] && array_scripts_name[i]="<未识别出活动名称>"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
cd $dir_current
|
||||||
|
}
|
||||||
|
|
||||||
|
## 使用说明
|
||||||
|
usage() {
|
||||||
|
gen_array_scripts
|
||||||
|
echo -e "task命令运行本程序自动添加进crontab的脚本,需要输入脚本的绝对路径或去掉 “$dir_scripts/” 目录后的相对路径(定时任务中请写作相对路径),用法为:"
|
||||||
|
echo -e "1.$cmd_task <file_name> # 依次执行,如果设置了随机延迟,将随机延迟一定秒数"
|
||||||
|
echo -e "2.$cmd_task <file_name> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中"
|
||||||
|
echo -e "3.$cmd_task <file_name> conc <环境变量名称> <账号编号,空格分隔>(可选的) # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中,且可指定账号执行"
|
||||||
|
echo -e "4.$cmd_task <file_name> desi <环境变量名称> <账号编号,空格分隔> # 指定账号执行,无论是否设置了随机延迟,均立即运行"
|
||||||
|
if [[ ${#array_scripts[*]} -gt 0 ]]; then
|
||||||
|
echo -e "\n当前有以下脚本可以运行:"
|
||||||
|
for ((i = 0; i < ${#array_scripts[*]}; i++)); do
|
||||||
|
echo -e "$(($i + 1)). ${array_scripts_name[i]}:${array_scripts[i]}"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo -e "\n暂无脚本可以执行"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
## run nohup,$1:文件名,不含路径,带后缀
|
||||||
|
run_nohup() {
|
||||||
|
local file_name=$1
|
||||||
|
nohup node $file_name &>$log_path &
|
||||||
|
}
|
||||||
|
|
||||||
|
check_server() {
|
||||||
|
if [[ $cpu_warn ]] && [[ $mem_warn ]] && [[ $disk_warn ]]; then
|
||||||
|
local top_result=$(top -b -n 1)
|
||||||
|
cpu_use=$(echo "$top_result" | grep CPU | grep -v -E 'grep|PID' | awk '{print $2}' | cut -f 1 -d "%" | head -n 1)
|
||||||
|
|
||||||
|
mem_free=$(free -m | grep "Mem" | awk '{print $3}' | head -n 1)
|
||||||
|
mem_total=$(free -m | grep "Mem" | awk '{print $2}' | head -n 1)
|
||||||
|
mem_use=$(printf "%d%%" $((mem_free * 100 / mem_total)) | cut -f 1 -d "%" | head -n 1)
|
||||||
|
|
||||||
|
disk_use=$(df -P | grep /dev | grep -v -E '(tmp|boot|shm)' | awk '{print $5}' | cut -f 1 -d "%" | head -n 1)
|
||||||
|
if [[ $cpu_use -gt $cpu_warn ]] && [[ $cpu_warn ]] || [[ $mem_free -lt $mem_warn ]] || [[ $disk_use -gt $disk_warn ]]; then
|
||||||
|
local resource=$(echo "$top_result" | grep -v -E 'grep|Mem|idle|Load|tr' | awk '{$2="";$3="";$4="";$5="";$7="";print $0}' | head -n 10 | tr '\n' '|' | sed s/\|/\\\\n/g)
|
||||||
|
notify_api "服务器资源异常警告" "当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use% \n资源占用详情 \n\n $resource"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_task_before() {
|
||||||
|
begin_time=$(format_time "$time_format" "$time")
|
||||||
|
begin_timestamp=$(format_timestamp "$time_format" "$time")
|
||||||
|
|
||||||
|
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
||||||
|
|
||||||
|
echo -e "## 开始执行... $begin_time\n"
|
||||||
|
|
||||||
|
[[ $is_macos -eq 0 ]] && check_server
|
||||||
|
|
||||||
|
if [[ -s $task_error_log_path ]]; then
|
||||||
|
eval cat $task_error_log_path $cmd
|
||||||
|
eval echo -e "加载 config.sh 出错,请手动检查" $cmd
|
||||||
|
eval echo $cmd
|
||||||
|
fi
|
||||||
|
|
||||||
|
. $file_task_before "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_task_after() {
|
||||||
|
. $file_task_after "$@"
|
||||||
|
|
||||||
|
local etime=$(date "+$time_format")
|
||||||
|
local end_time=$(format_time "$time_format" "$etime")
|
||||||
|
local end_timestamp=$(format_timestamp "$time_format" "$etime")
|
||||||
|
local diff_time=$(($end_timestamp - $begin_timestamp))
|
||||||
|
|
||||||
|
echo -e "\n\n## 执行结束... $end_time 耗时 $diff_time 秒 "
|
||||||
|
|
||||||
|
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||||
|
}
|
||||||
|
|
||||||
|
## 正常运行单个脚本,$1:传入参数
|
||||||
|
run_normal() {
|
||||||
|
local file_param=$1
|
||||||
|
if [[ $# -eq 1 ]]; then
|
||||||
|
random_delay "$file_param"
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd $dir_scripts
|
||||||
|
local relative_path="${file_param%/*}"
|
||||||
|
if [[ ${file_param} != /* ]] && [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
||||||
|
cd ${relative_path}
|
||||||
|
file_param=${file_param/$relative_path\//}
|
||||||
|
fi
|
||||||
|
|
||||||
|
$timeoutCmd $which_program $file_param
|
||||||
|
}
|
||||||
|
|
||||||
|
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
|
||||||
|
run_concurrent() {
|
||||||
|
local file_param="$1"
|
||||||
|
local env_param="$2"
|
||||||
|
local num_param=$(echo "$3" | perl -pe "s|.*$2(.*)|\1|")
|
||||||
|
if [[ ! $env_param ]]; then
|
||||||
|
echo -e "\n 缺少并发运行的环境变量参数"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local envs=$(eval echo "\$${env_param}")
|
||||||
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
|
local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
||||||
|
local runArr=($(eval echo $tempArr))
|
||||||
|
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
||||||
|
|
||||||
|
local n=0
|
||||||
|
for i in ${runArr[@]}; do
|
||||||
|
array_run[n]=${array[$i - 1]}
|
||||||
|
let n++
|
||||||
|
done
|
||||||
|
|
||||||
|
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
||||||
|
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
||||||
|
|
||||||
|
local envs=$(eval echo "\$${env_param}")
|
||||||
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
|
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
||||||
|
|
||||||
|
cd $dir_scripts
|
||||||
|
local relative_path="${file_param%/*}"
|
||||||
|
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
||||||
|
cd ${relative_path}
|
||||||
|
file_param=${file_param/$relative_path\//}
|
||||||
|
fi
|
||||||
|
for i in "${!array[@]}"; do
|
||||||
|
export ${env_param}=${array[i]}
|
||||||
|
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
|
||||||
|
eval $timeoutCmd $which_program $file_param &>$single_log_path &
|
||||||
|
done
|
||||||
|
|
||||||
|
wait
|
||||||
|
for i in "${!array[@]}"; do
|
||||||
|
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
|
||||||
|
cat $single_log_path
|
||||||
|
[[ -f $single_log_path ]] && rm -f $single_log_path
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
run_designated() {
|
||||||
|
local file_param="$1"
|
||||||
|
local env_param="$2"
|
||||||
|
local num_param=$(echo "$3" | perl -pe "s|.*$2(.*)|\1|")
|
||||||
|
if [[ ! $env_param ]] || [[ ! $num_param ]]; then
|
||||||
|
echo -e "\n 缺少单独运行的参数 task xxx.js desi Test 1 3"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local envs=$(eval echo "\$${env_param}")
|
||||||
|
local array=($(echo $envs | sed 's/&/ /g'))
|
||||||
|
local tempArr=$(echo $num_param | sed "s/-max/-${#array[@]}/g" | sed "s/max-/${#array[@]}-/g" | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
||||||
|
local runArr=($(eval echo $tempArr))
|
||||||
|
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
||||||
|
|
||||||
|
local n=0
|
||||||
|
for i in ${runArr[@]}; do
|
||||||
|
array_run[n]=${array[$i - 1]}
|
||||||
|
let n++
|
||||||
|
done
|
||||||
|
|
||||||
|
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
||||||
|
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
||||||
|
|
||||||
|
cd $dir_scripts
|
||||||
|
local relative_path="${file_param%/*}"
|
||||||
|
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
||||||
|
cd ${relative_path}
|
||||||
|
file_param=${file_param/$relative_path\//}
|
||||||
|
fi
|
||||||
|
$timeoutCmd $which_program $file_param
|
||||||
|
}
|
||||||
|
|
||||||
|
## 运行其他命令
|
||||||
|
run_else() {
|
||||||
|
local file_param="$1"
|
||||||
|
|
||||||
|
cd $dir_scripts
|
||||||
|
local relative_path="${file_param%/*}"
|
||||||
|
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
||||||
|
cd ${relative_path}
|
||||||
|
file_param=${file_param/$relative_path\//}
|
||||||
|
fi
|
||||||
|
|
||||||
|
shift
|
||||||
|
|
||||||
|
$timeoutCmd $which_program $file_param "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
## 命令检测
|
||||||
|
main() {
|
||||||
|
if [[ $1 == *.js ]] || [[ $1 == *.py ]] || [[ $1 == *.pyc ]] || [[ $1 == *.sh ]] || [[ $1 == *.ts ]]; then
|
||||||
|
case $# in
|
||||||
|
1)
|
||||||
|
run_normal "$1"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
case $2 in
|
||||||
|
now)
|
||||||
|
run_normal "$1" "$2"
|
||||||
|
;;
|
||||||
|
conc)
|
||||||
|
run_concurrent "$1" "$3" "$*"
|
||||||
|
;;
|
||||||
|
desi)
|
||||||
|
run_designated "$1" "$3" "$*"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
run_else "$@"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
elif [[ $# -eq 0 ]]; then
|
||||||
|
echo
|
||||||
|
usage
|
||||||
|
else
|
||||||
|
run_else "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
handle_task_before "$@"
|
||||||
|
main "$@"
|
||||||
|
handle_task_after "$@"
|
||||||
+1
-1
@@ -13,7 +13,7 @@ git push
|
|||||||
echo -e "更新cdn文件"
|
echo -e "更新cdn文件"
|
||||||
ts-node sample/tool.ts
|
ts-node sample/tool.ts
|
||||||
|
|
||||||
string=$(cat src/version.ts | grep "version" | egrep "[^\']*" -o | egrep "\d\.*")
|
string=$(cat version.yaml | grep "version" | egrep "[^ ]*" -o | egrep "\d\.*")
|
||||||
version="v$string"
|
version="v$string"
|
||||||
echo -e "当前版本$version"
|
echo -e "当前版本$version"
|
||||||
|
|
||||||
|
|||||||
+22
-19
@@ -79,12 +79,16 @@ import_config() {
|
|||||||
default_cron="$(random_range 0 59) $(random_range 0 23) * * *"
|
default_cron="$(random_range 0 59) $(random_range 0 23) * * *"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cpu_warn=${CpuWarn:-80}
|
cpu_warn=${CpuWarn}
|
||||||
mem_warn=${MemoryWarn:-80}
|
mem_warn=${MemoryWarn}
|
||||||
disk_warn=${DiskWarn:-90}
|
disk_warn=${DiskWarn}
|
||||||
}
|
}
|
||||||
|
|
||||||
set_proxy() {
|
set_proxy() {
|
||||||
|
local proxy="$1"
|
||||||
|
if [[ $proxy ]]; then
|
||||||
|
proxy_url="$proxy"
|
||||||
|
fi
|
||||||
if [[ $proxy_url ]]; then
|
if [[ $proxy_url ]]; then
|
||||||
export http_proxy="${proxy_url}"
|
export http_proxy="${proxy_url}"
|
||||||
export https_proxy="${proxy_url}"
|
export https_proxy="${proxy_url}"
|
||||||
@@ -303,13 +307,14 @@ update_depend() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
git_clone_scripts() {
|
git_clone_scripts() {
|
||||||
local url=$1
|
local url="$1"
|
||||||
local dir=$2
|
local dir="$2"
|
||||||
local branch=$3
|
local branch="$3"
|
||||||
|
local proxy="$4"
|
||||||
[[ $branch ]] && local part_cmd="-b $branch "
|
[[ $branch ]] && local part_cmd="-b $branch "
|
||||||
echo -e "开始克隆仓库 $url 到 $dir\n"
|
echo -e "开始克隆仓库 $url 到 $dir\n"
|
||||||
|
|
||||||
set_proxy
|
set_proxy "$proxy"
|
||||||
git clone $part_cmd $url $dir
|
git clone $part_cmd $url $dir
|
||||||
exit_status=$?
|
exit_status=$?
|
||||||
unset_proxy
|
unset_proxy
|
||||||
@@ -319,15 +324,15 @@ git_pull_scripts() {
|
|||||||
local dir_current=$(pwd)
|
local dir_current=$(pwd)
|
||||||
local dir_work="$1"
|
local dir_work="$1"
|
||||||
local branch="$2"
|
local branch="$2"
|
||||||
|
local proxy="$3"
|
||||||
cd $dir_work
|
cd $dir_work
|
||||||
echo -e "开始更新仓库:$dir_work\n"
|
echo -e "开始更新仓库:$dir_work\n"
|
||||||
|
|
||||||
set_proxy
|
set_proxy "$proxy"
|
||||||
git fetch --all
|
git fetch --all
|
||||||
exit_status=$?
|
exit_status=$?
|
||||||
git pull &>/dev/null
|
git pull &>/dev/null
|
||||||
unset_proxy
|
unset_proxy
|
||||||
reset_branch "$branch"
|
|
||||||
|
|
||||||
cd $dir_current
|
cd $dir_current
|
||||||
}
|
}
|
||||||
@@ -338,19 +343,21 @@ reset_romote_url() {
|
|||||||
local url=$2
|
local url=$2
|
||||||
local branch="$3"
|
local branch="$3"
|
||||||
|
|
||||||
|
cd $dir_work
|
||||||
if [[ -d "$dir_work/.git" ]]; then
|
if [[ -d "$dir_work/.git" ]]; then
|
||||||
cd $dir_work
|
|
||||||
[[ -f ".git/index.lock" ]] && rm -f .git/index.lock >/dev/null
|
[[ -f ".git/index.lock" ]] && rm -f .git/index.lock >/dev/null
|
||||||
git remote set-url origin $url &>/dev/null
|
git remote set-url origin $url &>/dev/null
|
||||||
|
else
|
||||||
local part_cmd=""
|
git init
|
||||||
reset_branch "$branch"
|
git remote add origin $url &>/dev/null
|
||||||
cd $dir_current
|
|
||||||
fi
|
fi
|
||||||
|
reset_branch "$branch"
|
||||||
|
cd $dir_current
|
||||||
}
|
}
|
||||||
|
|
||||||
reset_branch() {
|
reset_branch() {
|
||||||
local branch="$1"
|
local branch="$1"
|
||||||
|
local part_cmd=""
|
||||||
if [[ $branch ]]; then
|
if [[ $branch ]]; then
|
||||||
part_cmd="origin/${branch}"
|
part_cmd="origin/${branch}"
|
||||||
git checkout -B "$branch" &>/dev/null
|
git checkout -B "$branch" &>/dev/null
|
||||||
@@ -375,10 +382,6 @@ reload_pm2() {
|
|||||||
echo -e "启动定时任务服务\n"
|
echo -e "启动定时任务服务\n"
|
||||||
pm2 delete schedule --source-map-support --time &>/dev/null
|
pm2 delete schedule --source-map-support --time &>/dev/null
|
||||||
pm2 start $dir_static/build/schedule.js -n schedule --source-map-support --time &>/dev/null
|
pm2 start $dir_static/build/schedule.js -n schedule --source-map-support --time &>/dev/null
|
||||||
|
|
||||||
echo -e "启动公开服务\n"
|
|
||||||
pm2 delete public --source-map-support --time &>/dev/null
|
|
||||||
pm2 start $dir_static/build/public.js -n public --source-map-support --time &>/dev/null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
diff_time() {
|
diff_time() {
|
||||||
@@ -486,4 +489,4 @@ detect_macos
|
|||||||
define_cmd
|
define_cmd
|
||||||
fix_config
|
fix_config
|
||||||
|
|
||||||
import_config $1 >$task_error_log_path 2>&1
|
import_config $1 2>$task_error_log_path
|
||||||
|
|||||||
+35
-305
@@ -21,78 +21,12 @@ define_program() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
random_delay() {
|
|
||||||
local random_delay_max=$RandomDelay
|
|
||||||
if [[ $random_delay_max ]] && [[ $random_delay_max -gt 0 ]]; then
|
|
||||||
local file_param=$1
|
|
||||||
local file_extensions=${RandomDelayFileExtensions-"js"}
|
|
||||||
local ignored_minutes=${RandomDelayIgnoredMinutes-"0 30"}
|
|
||||||
|
|
||||||
if [[ -n $file_extensions ]]; then
|
|
||||||
if ! echo "$file_param" | grep -qE "\.${file_extensions// /$|\\.}$"; then
|
|
||||||
# echo -e "\n当前文件需要准点运行, 放弃随机延迟\n"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
local current_min
|
|
||||||
current_min=$(date "+%-M")
|
|
||||||
for minute in $ignored_minutes; do
|
|
||||||
if [[ $current_min -eq $minute ]]; then
|
|
||||||
# echo -e "\n当前时间需要准点运行, 放弃随机延迟\n"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
local delay_second=$(($(gen_random_num "$random_delay_max") + 1))
|
|
||||||
echo -e "\n命令未添加 \"now\",随机延迟 $delay_second 秒后再执行任务,如需立即终止,请按 CTRL+C...\n"
|
|
||||||
sleep $delay_second
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
## scripts目录下所有可运行脚本数组
|
|
||||||
gen_array_scripts() {
|
|
||||||
local dir_current=$(pwd)
|
|
||||||
local i="-1"
|
|
||||||
cd $dir_scripts
|
|
||||||
for file in $(ls); do
|
|
||||||
if [[ -f $file ]] && [[ $file == *.js && $file != sendNotify.js ]]; then
|
|
||||||
let i++
|
|
||||||
array_scripts[i]=$(echo "$file" | perl -pe "s|$dir_scripts/||g")
|
|
||||||
array_scripts_name[i]=$(grep "new Env" $file | awk -F "'|\"" '{print $2}' | head -1)
|
|
||||||
[[ -z ${array_scripts_name[i]} ]] && array_scripts_name[i]="<未识别出活动名称>"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
cd $dir_current
|
|
||||||
}
|
|
||||||
|
|
||||||
## 使用说明
|
|
||||||
usage() {
|
|
||||||
define_cmd
|
|
||||||
gen_array_scripts
|
|
||||||
echo -e "task命令运行本程序自动添加进crontab的脚本,需要输入脚本的绝对路径或去掉 “$dir_scripts/” 目录后的相对路径(定时任务中请写作相对路径),用法为:"
|
|
||||||
echo -e "1.$cmd_task <file_name> # 依次执行,如果设置了随机延迟,将随机延迟一定秒数"
|
|
||||||
echo -e "2.$cmd_task <file_name> now # 依次执行,无论是否设置了随机延迟,均立即运行,前台会输出日志,同时记录在日志文件中"
|
|
||||||
echo -e "3.$cmd_task <file_name> conc <环境变量名称> <账号编号,空格分隔>(可选的) # 并发执行,无论是否设置了随机延迟,均立即运行,前台不产生日志,直接记录在日志文件中,且可指定账号执行"
|
|
||||||
echo -e "4.$cmd_task <file_name> desi <环境变量名称> <账号编号,空格分隔> # 指定账号执行,无论是否设置了随机延迟,均立即运行"
|
|
||||||
if [[ ${#array_scripts[*]} -gt 0 ]]; then
|
|
||||||
echo -e "\n当前有以下脚本可以运行:"
|
|
||||||
for ((i = 0; i < ${#array_scripts[*]}; i++)); do
|
|
||||||
echo -e "$(($i + 1)). ${array_scripts_name[i]}:${array_scripts[i]}"
|
|
||||||
done
|
|
||||||
else
|
|
||||||
echo -e "\n暂无脚本可以执行"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
## run nohup,$1:文件名,不含路径,带后缀
|
|
||||||
run_nohup() {
|
|
||||||
local file_name=$1
|
|
||||||
nohup node $file_name &>$log_path &
|
|
||||||
}
|
|
||||||
|
|
||||||
handle_log_path() {
|
handle_log_path() {
|
||||||
define_program "$file_param"
|
local file_param=$1
|
||||||
|
|
||||||
|
if [[ -z $file_param ]];then
|
||||||
|
file_param="task"
|
||||||
|
fi
|
||||||
|
|
||||||
local suffix=""
|
local suffix=""
|
||||||
if [[ ! -z $ID ]]; then
|
if [[ ! -z $ID ]]; then
|
||||||
@@ -114,247 +48,43 @@ handle_log_path() {
|
|||||||
log_dir="${log_dir_tmp%.*}${suffix}"
|
log_dir="${log_dir_tmp%.*}${suffix}"
|
||||||
log_path="$log_dir/$log_time.log"
|
log_path="$log_dir/$log_time.log"
|
||||||
cmd=">> $dir_log/$log_path 2>&1"
|
cmd=">> $dir_log/$log_path 2>&1"
|
||||||
[[ "$show_log" == "true" ]] && cmd=""
|
if [[ "$show_log" == "true" ]]; then
|
||||||
make_dir "$dir_log/$log_dir"
|
cmd=""
|
||||||
}
|
else
|
||||||
|
make_dir "$dir_log/$log_dir"
|
||||||
check_server() {
|
|
||||||
cpu_use=$(top -b -n 1 | grep CPU | grep -v -E 'grep|PID' | awk '{print $2}' | cut -f 1 -d "%")
|
|
||||||
|
|
||||||
mem_free=$(free -m | grep "Mem" | awk '{print $3}')
|
|
||||||
mem_total=$(free -m | grep "Mem" | awk '{print $2}')
|
|
||||||
mem_use=$(printf "%d%%" $((mem_free * 100 / mem_total)) | cut -f 1 -d "%")
|
|
||||||
|
|
||||||
disk_use=$(df -P | grep /dev | grep -v -E '(tmp|boot|shm)' | awk '{print $5}' | cut -f 1 -d "%")
|
|
||||||
|
|
||||||
eval echo -e "\#\# 当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use% \\\n" $cmd
|
|
||||||
if [[ $cpu_use -gt $cpu_warn ]] || [[ $mem_free -lt $mem_warn ]] || [[ $disk_use -gt $disk_warn ]]; then
|
|
||||||
echo -e "\#\# 服务器资源占用异常,本次任务跳过执行" $cmd
|
|
||||||
notify_api "服务器资源异常警告" "当前CPU占用 $cpu_use% 内存占用 $mem_use% 磁盘占用 $disk_use%"
|
|
||||||
|
|
||||||
end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
diff_time=$(($end_timestamp - $begin_timestamp))
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
|
||||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_task_before() {
|
format_params() {
|
||||||
handle_log_path
|
time_format="%Y-%m-%d %H:%M:%S"
|
||||||
|
|
||||||
begin_time=$(format_time "$time_format" "$time")
|
|
||||||
begin_timestamp=$(format_timestamp "$time_format" "$time")
|
|
||||||
|
|
||||||
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
|
||||||
|
|
||||||
[[ $is_macos -eq 0 ]] && check_server
|
|
||||||
|
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
|
||||||
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
|
||||||
eval . $file_task_before "$@" $cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
## 正常运行单个脚本,$1:传入参数
|
|
||||||
run_normal() {
|
|
||||||
local file_param=$1
|
|
||||||
if [[ $# -eq 1 ]]; then
|
|
||||||
random_delay "$file_param"
|
|
||||||
fi
|
|
||||||
|
|
||||||
handle_task_before
|
|
||||||
|
|
||||||
cd $dir_scripts
|
|
||||||
local relative_path="${file_param%/*}"
|
|
||||||
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
|
||||||
cd ${relative_path}
|
|
||||||
file_param=${file_param/$relative_path\//}
|
|
||||||
fi
|
|
||||||
|
|
||||||
eval $timeoutCmd $which_program $file_param $cmd
|
|
||||||
|
|
||||||
eval . $file_task_after "$@" $cmd
|
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
local end_timestamp=$(date "+%s")
|
|
||||||
local diff_time=$(expr $end_timestamp - $begin_timestamp)
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
|
||||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
## 并发执行时,设定的 RandomDelay 不会生效,即所有任务立即执行
|
|
||||||
run_concurrent() {
|
|
||||||
local file_param="$1"
|
|
||||||
local env_param="$2"
|
|
||||||
local num_param=$(echo "$3" | perl -pe "s|.*$2(.*)|\1|")
|
|
||||||
if [[ ! $env_param ]]; then
|
|
||||||
echo -e "\n 缺少并发运行的环境变量参数"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
handle_task_before
|
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
|
||||||
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
|
||||||
local runArr=($(eval echo $tempArr))
|
|
||||||
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
|
||||||
|
|
||||||
local n=0
|
|
||||||
for i in ${runArr[@]}; do
|
|
||||||
array_run[n]=${array[$i - 1]}
|
|
||||||
let n++
|
|
||||||
done
|
|
||||||
|
|
||||||
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
|
||||||
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
|
||||||
single_log_time=$(date "+%Y-%m-%d-%H-%M-%S.%N")
|
|
||||||
|
|
||||||
cd $dir_scripts
|
|
||||||
local relative_path="${file_param%/*}"
|
|
||||||
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
|
||||||
cd ${relative_path}
|
|
||||||
file_param=${file_param/$relative_path\//}
|
|
||||||
fi
|
|
||||||
for i in "${!array[@]}"; do
|
|
||||||
export ${env_param}=${array[i]}
|
|
||||||
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
|
|
||||||
eval $timeoutCmd $which_program $file_param &>$single_log_path &
|
|
||||||
done
|
|
||||||
|
|
||||||
wait
|
|
||||||
for i in "${!array[@]}"; do
|
|
||||||
single_log_path="$dir_log/$log_dir/${single_log_time}_$((i + 1)).log"
|
|
||||||
eval cat $single_log_path $cmd
|
|
||||||
[[ -f $single_log_path ]] && rm -f $single_log_path
|
|
||||||
done
|
|
||||||
|
|
||||||
eval . $file_task_after "$@" $cmd
|
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
local end_timestamp=$(date "+%s")
|
|
||||||
local diff_time=$(($end_timestamp - $begin_timestamp))
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
|
||||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
run_designated() {
|
|
||||||
local file_param="$1"
|
|
||||||
local env_param="$2"
|
|
||||||
local num_param=$(echo "$3" | perl -pe "s|.*$2(.*)|\1|")
|
|
||||||
if [[ ! $env_param ]] || [[ ! $num_param ]]; then
|
|
||||||
echo -e "\n 缺少单独运行的参数 task xxx.js desi Test 1 3"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
handle_task_before
|
|
||||||
|
|
||||||
local envs=$(eval echo "\$${env_param}")
|
|
||||||
local array=($(echo $envs | sed 's/&/ /g'))
|
|
||||||
local tempArr=$(echo $num_param | perl -pe "s|(\d+)(-\|~\|_)(\d+)|{\1..\3}|g")
|
|
||||||
local runArr=($(eval echo $tempArr))
|
|
||||||
runArr=($(awk -v RS=' ' '!a[$1]++' <<<${runArr[@]}))
|
|
||||||
|
|
||||||
local n=0
|
|
||||||
for i in ${runArr[@]}; do
|
|
||||||
array_run[n]=${array[$i - 1]}
|
|
||||||
let n++
|
|
||||||
done
|
|
||||||
|
|
||||||
local cookieStr=$(echo ${array_run[*]} | sed 's/\ /\&/g')
|
|
||||||
[[ ! -z $cookieStr ]] && export ${env_param}=${cookieStr}
|
|
||||||
|
|
||||||
cd $dir_scripts
|
|
||||||
local relative_path="${file_param%/*}"
|
|
||||||
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
|
||||||
cd ${relative_path}
|
|
||||||
file_param=${file_param/$relative_path\//}
|
|
||||||
fi
|
|
||||||
eval $timeoutCmd $which_program $file_param $cmd
|
|
||||||
|
|
||||||
eval . $file_task_after "$@" $cmd
|
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
local end_timestamp=$(date "+%s")
|
|
||||||
local diff_time=$(($end_timestamp - $begin_timestamp))
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
|
||||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
## 运行其他命令
|
|
||||||
run_else() {
|
|
||||||
local file_param="$1"
|
|
||||||
|
|
||||||
handle_task_before
|
|
||||||
|
|
||||||
cd $dir_scripts
|
|
||||||
local relative_path="${file_param%/*}"
|
|
||||||
if [[ ! -z ${relative_path} ]] && [[ ${file_param} =~ "/" ]]; then
|
|
||||||
cd ${relative_path}
|
|
||||||
file_param=${file_param/$relative_path\//}
|
|
||||||
fi
|
|
||||||
|
|
||||||
shift
|
|
||||||
eval $timeoutCmd $which_program "$file_param" "$@" $cmd
|
|
||||||
|
|
||||||
eval . $file_task_after "$file_param" "$@" $cmd
|
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
local end_timestamp=$(date "+%s")
|
|
||||||
local diff_time=$(($end_timestamp - $begin_timestamp))
|
|
||||||
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
|
||||||
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒" $cmd
|
|
||||||
}
|
|
||||||
|
|
||||||
## 命令检测
|
|
||||||
main() {
|
|
||||||
show_log="false"
|
|
||||||
while getopts ":l" opt; do
|
|
||||||
case $opt in
|
|
||||||
l)
|
|
||||||
show_log="true"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
[[ "$show_log" == "true" ]] && shift $(($OPTIND - 1))
|
|
||||||
|
|
||||||
timeoutCmd=""
|
timeoutCmd=""
|
||||||
if type timeout &>/dev/null; then
|
if type timeout &>/dev/null; then
|
||||||
timeoutCmd="timeout -k 10s $command_timeout_time "
|
timeoutCmd="timeout --foreground -s 14 -k 10s $command_timeout_time "
|
||||||
fi
|
|
||||||
|
|
||||||
time_format="%Y-%m-%d %H:%M:%S"
|
|
||||||
if [[ $1 == *.js ]] || [[ $1 == *.py ]] || [[ $1 == *.pyc ]] || [[ $1 == *.sh ]] || [[ $1 == *.ts ]]; then
|
|
||||||
case $# in
|
|
||||||
1)
|
|
||||||
run_normal "$1"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
case $2 in
|
|
||||||
now)
|
|
||||||
run_normal "$1" "$2"
|
|
||||||
;;
|
|
||||||
conc)
|
|
||||||
run_concurrent "$1" "$3" "$*"
|
|
||||||
;;
|
|
||||||
desi)
|
|
||||||
run_designated "$1" "$3" "$*"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
run_else "$@"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
[[ -f "$dir_log/$log_path" ]] && cat "$dir_log/$log_path"
|
|
||||||
elif [[ $# -eq 0 ]]; then
|
|
||||||
echo
|
|
||||||
usage
|
|
||||||
else
|
|
||||||
run_else "$@"
|
|
||||||
fi
|
fi
|
||||||
|
# params=$(echo "$@" | sed -E 's/([^ ])&([^ ])/\1\\\&\2/g')
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
while getopts ":lm:" opt; do
|
||||||
|
case $opt in
|
||||||
|
l)
|
||||||
|
show_log="true"
|
||||||
|
;;
|
||||||
|
m)
|
||||||
|
max_time="$OPTARG"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
[[ $show_log ]] && shift $(($OPTIND - 1))
|
||||||
|
if [[ $max_time ]]; then
|
||||||
|
shift $(($OPTIND - 1))
|
||||||
|
command_timeout_time="$max_time"
|
||||||
|
fi
|
||||||
|
|
||||||
|
format_params "$@"
|
||||||
|
define_program "$@"
|
||||||
|
handle_log_path "$@"
|
||||||
|
|
||||||
|
eval . $dir_shell/otask.sh "$cmd"
|
||||||
|
[[ -f "$dir_log/$log_path" ]] && cat "$dir_log/$log_path"
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
+103
-89
@@ -26,33 +26,6 @@ diff_cron() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
## 检测配置文件版本
|
|
||||||
detect_config_version() {
|
|
||||||
## 识别出两个文件的版本号
|
|
||||||
ver_config_sample=$(grep " Version: " $file_config_sample | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
|
||||||
[[ -f $file_config_user ]] && ver_config_user=$(grep " Version: " $file_config_user | perl -pe "s|.+v((\d+\.?){3})|\1|")
|
|
||||||
|
|
||||||
## 删除旧的发送记录文件
|
|
||||||
[[ -f $send_mark ]] && [[ $(cat $send_mark) != $ver_config_sample ]] && rm -f $send_mark
|
|
||||||
|
|
||||||
## 识别出更新日期和更新内容
|
|
||||||
update_date=$(grep " Date: " $file_config_sample | awk -F ": " '{print $2}')
|
|
||||||
update_content=$(grep " Update Content: " $file_config_sample | awk -F ": " '{print $2}')
|
|
||||||
|
|
||||||
## 如果是今天,并且版本号不一致,则发送通知
|
|
||||||
if [[ -f $file_config_user ]] && [[ $ver_config_user != $ver_config_sample ]] && [[ $update_date == $(date "+%Y-%m-%d") ]]; then
|
|
||||||
if [[ ! -f $send_mark ]]; then
|
|
||||||
local notify_title="配置文件更新通知"
|
|
||||||
local notify_content="更新日期: $update_date\n用户版本: $ver_config_user\n新的版本: $ver_config_sample\n更新内容: $update_content\n更新说明: 如需使用新功能请对照config.sample.sh,将相关新参数手动增加到你自己的config.sh中,否则请无视本消息。本消息只在该新版本配置文件更新当天发送一次。\n"
|
|
||||||
echo -e $notify_content
|
|
||||||
notify_api "$notify_title" "$notify_content"
|
|
||||||
[[ $? -eq 0 ]] && echo $ver_config_sample >$send_mark
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
[[ -f $send_mark ]] && rm -f $send_mark
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
## 输出是否有新的或失效的定时任务,$1:新的或失效的任务清单文件路径,$2:新/失效
|
## 输出是否有新的或失效的定时任务,$1:新的或失效的任务清单文件路径,$2:新/失效
|
||||||
output_list_add_drop() {
|
output_list_add_drop() {
|
||||||
local list=$1
|
local list=$1
|
||||||
@@ -144,6 +117,9 @@ update_repo() {
|
|||||||
local dependence="$4"
|
local dependence="$4"
|
||||||
local branch="$5"
|
local branch="$5"
|
||||||
local extensions="$6"
|
local extensions="$6"
|
||||||
|
local proxy="$7"
|
||||||
|
local autoAddCron="$8"
|
||||||
|
local autoDelCron="$9"
|
||||||
local tmp="${url%/*}"
|
local tmp="${url%/*}"
|
||||||
local authorTmp1="${tmp##*/}"
|
local authorTmp1="${tmp##*/}"
|
||||||
local authorTmp2="${authorTmp1##*:}"
|
local authorTmp2="${authorTmp1##*:}"
|
||||||
@@ -156,13 +132,14 @@ update_repo() {
|
|||||||
local formatUrl="$url"
|
local formatUrl="$url"
|
||||||
if [[ -d ${repo_path}/.git ]]; then
|
if [[ -d ${repo_path}/.git ]]; then
|
||||||
reset_romote_url ${repo_path} "${formatUrl}" "${branch}"
|
reset_romote_url ${repo_path} "${formatUrl}" "${branch}"
|
||||||
git_pull_scripts ${repo_path} "${branch}"
|
git_pull_scripts ${repo_path} "${branch}" "${proxy}"
|
||||||
else
|
else
|
||||||
git_clone_scripts "${formatUrl}" ${repo_path} "${branch}"
|
rm -rf ${repo_path} &>/dev/null
|
||||||
|
git_clone_scripts "${formatUrl}" ${repo_path} "${branch}" "${proxy}"
|
||||||
fi
|
fi
|
||||||
if [[ $exit_status -eq 0 ]]; then
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
echo -e "\n更新${repo_path}成功...\n"
|
echo -e "\n更新${repo_path}成功...\n"
|
||||||
diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions"
|
diff_scripts "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions" "$autoAddCron" "$autoDelCron"
|
||||||
else
|
else
|
||||||
echo -e "\n更新${repo_path}失败,请检查网络...\n"
|
echo -e "\n更新${repo_path}失败,请检查网络...\n"
|
||||||
fi
|
fi
|
||||||
@@ -186,7 +163,7 @@ update_raw() {
|
|||||||
echo -e "下载 ${raw_file_name} 成功...\n"
|
echo -e "下载 ${raw_file_name} 成功...\n"
|
||||||
cd $dir_raw
|
cd $dir_raw
|
||||||
local filename="raw_${raw_file_name}"
|
local filename="raw_${raw_file_name}"
|
||||||
local cron_id=$(cat $list_crontab_user | grep -E "$cmd_task $filename" | perl -pe "s|.*ID=(.*) $cmd_task $filename\.*|\1|" | head -1 | head -1 | awk -F " " '{print $1}')
|
local cron_id=$(cat $list_crontab_user | grep -E "$cmd_task.* $filename" | perl -pe "s|.*ID=(.*) $cmd_task.* $filename\.*|\1|" | head -1 | head -1 | awk -F " " '{print $1}')
|
||||||
cp -f $raw_file_name $dir_scripts/${filename}
|
cp -f $raw_file_name $dir_scripts/${filename}
|
||||||
cron_line=$(
|
cron_line=$(
|
||||||
perl -ne "{
|
perl -ne "{
|
||||||
@@ -230,10 +207,10 @@ run_extra_shell() {
|
|||||||
|
|
||||||
## 脚本用法
|
## 脚本用法
|
||||||
usage() {
|
usage() {
|
||||||
echo -e "本脚本用法:"
|
echo -e "ql命令使用方法:"
|
||||||
echo -e "1. $cmd_update update # 更新并重启青龙"
|
echo -e "1. $cmd_update update # 更新并重启青龙"
|
||||||
echo -e "2. $cmd_update extra # 运行自定义脚本"
|
echo -e "2. $cmd_update extra # 运行自定义脚本"
|
||||||
echo -e "3. $cmd_update raw <fileurl> # 更新单个脚本文件"
|
echo -e "3. $cmd_update raw <fileurl> # 更新单个脚本文件"
|
||||||
echo -e "4. $cmd_update repo <repourl> <path> <blacklist> <dependence> <branch> <extensions> # 更新单个仓库的脚本"
|
echo -e "4. $cmd_update repo <repourl> <path> <blacklist> <dependence> <branch> <extensions> # 更新单个仓库的脚本"
|
||||||
echo -e "5. $cmd_update rmlog <days> # 删除旧日志"
|
echo -e "5. $cmd_update rmlog <days> # 删除旧日志"
|
||||||
echo -e "6. $cmd_update bot # 启动tg-bot"
|
echo -e "6. $cmd_update bot # 启动tg-bot"
|
||||||
@@ -244,23 +221,27 @@ usage() {
|
|||||||
|
|
||||||
## 更新qinglong
|
## 更新qinglong
|
||||||
update_qinglong() {
|
update_qinglong() {
|
||||||
patch_version &>/dev/null
|
local mirror="github"
|
||||||
|
local githubStatus=$(curl -s -m 2 -IL "https://github.com" | grep 200)
|
||||||
|
if [ "$githubStatus" == "" ]; then
|
||||||
|
mirror="gitee"
|
||||||
|
fi
|
||||||
|
echo -e "使用 ${mirror} 源更新...\n"
|
||||||
export isFirstStartServer=false
|
export isFirstStartServer=false
|
||||||
|
|
||||||
local all_branch=$(git branch -a)
|
local all_branch=$(cd ${dir_root} && git branch -a)
|
||||||
local primary_branch="master"
|
local primary_branch="master"
|
||||||
if [[ "${all_branch}" =~ "${current_branch}" ]]; then
|
if [[ "${all_branch}" =~ "${current_branch}" ]]; then
|
||||||
primary_branch="${current_branch}"
|
primary_branch="${current_branch}"
|
||||||
fi
|
fi
|
||||||
[[ -f $dir_root/package.json ]] && ql_depend_old=$(cat $dir_root/package.json)
|
[[ -f $dir_root/package.json ]] && ql_depend_old=$(cat $dir_root/package.json)
|
||||||
reset_romote_url ${dir_root} "https://github.com/whyour/qinglong.git" ${primary_branch}
|
reset_romote_url ${dir_root} "https://${mirror}.com/whyour/qinglong.git" ${primary_branch}
|
||||||
git_pull_scripts $dir_root ${primary_branch}
|
git_pull_scripts $dir_root ${primary_branch}
|
||||||
|
|
||||||
if [[ $exit_status -eq 0 ]]; then
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
echo -e "\n更新青龙源文件成功...\n"
|
echo -e "\n更新青龙源文件成功...\n"
|
||||||
|
reset_romote_url ${dir_root} "https://${mirror}.com/whyour/qinglong.git" ${primary_branch}
|
||||||
cp -f $file_config_sample $dir_config/config.sample.sh
|
cp -f $file_config_sample $dir_config/config.sample.sh
|
||||||
detect_config_version
|
|
||||||
update_depend
|
update_depend
|
||||||
|
|
||||||
[[ -f $dir_root/package.json ]] && ql_depend_new=$(cat $dir_root/package.json)
|
[[ -f $dir_root/package.json ]] && ql_depend_new=$(cat $dir_root/package.json)
|
||||||
@@ -275,17 +256,17 @@ update_qinglong() {
|
|||||||
update_qinglong_static() {
|
update_qinglong_static() {
|
||||||
local no_restart="$1"
|
local no_restart="$1"
|
||||||
local primary_branch="$2"
|
local primary_branch="$2"
|
||||||
local url="https://github.com/whyour/qinglong-static.git"
|
local url="https://${mirror}.com/whyour/qinglong-static.git"
|
||||||
if [[ -d ${ql_static_repo}/.git ]]; then
|
if [[ -d ${ql_static_repo}/.git ]]; then
|
||||||
reset_romote_url ${ql_static_repo} ${url} ${primary_branch}
|
reset_romote_url ${ql_static_repo} ${url} ${primary_branch}
|
||||||
git_pull_scripts ${ql_static_repo} ${primary_branch}
|
git_pull_scripts ${ql_static_repo} ${primary_branch}
|
||||||
else
|
else
|
||||||
|
rm -rf ${ql_static_repo} &>/dev/null
|
||||||
git_clone_scripts ${url} ${ql_static_repo} ${primary_branch}
|
git_clone_scripts ${url} ${ql_static_repo} ${primary_branch}
|
||||||
fi
|
fi
|
||||||
if [[ $exit_status -eq 0 ]]; then
|
if [[ $exit_status -eq 0 ]]; then
|
||||||
echo -e "\n更新青龙静态资源成功...\n"
|
echo -e "\n更新青龙静态资源成功...\n"
|
||||||
local static_version=$(cat $dir_root/src/version.ts | perl -pe "s|.*\'(.*)\';\.*|\1|" | head -1)
|
reset_romote_url ${ql_static_repo} ${url} ${primary_branch}
|
||||||
echo -e "\n当前版本 $static_version...\n"
|
|
||||||
|
|
||||||
rm -rf $dir_static/*
|
rm -rf $dir_static/*
|
||||||
cp -rf $ql_static_repo/* $dir_static
|
cp -rf $ql_static_repo/* $dir_static
|
||||||
@@ -309,6 +290,15 @@ diff_scripts() {
|
|||||||
local blackword="$4"
|
local blackword="$4"
|
||||||
local dependence="$5"
|
local dependence="$5"
|
||||||
local extensions="$6"
|
local extensions="$6"
|
||||||
|
local autoAddCron="$7"
|
||||||
|
local autoDelCron="$8"
|
||||||
|
|
||||||
|
if [[ ! $autoAddCron ]];then
|
||||||
|
autoAddCron=${AutoAddCron}
|
||||||
|
fi
|
||||||
|
if [[ ! $autoDelCron ]];then
|
||||||
|
autoDelCron=${AutoDelCron}
|
||||||
|
fi
|
||||||
|
|
||||||
gen_list_repo "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions"
|
gen_list_repo "$repo_path" "$author" "$path" "$blackword" "$dependence" "$extensions"
|
||||||
|
|
||||||
@@ -318,13 +308,13 @@ diff_scripts() {
|
|||||||
|
|
||||||
if [[ -s $list_drop ]]; then
|
if [[ -s $list_drop ]]; then
|
||||||
output_list_add_drop $list_drop "失效"
|
output_list_add_drop $list_drop "失效"
|
||||||
if [[ ${AutoDelCron} == true ]]; then
|
if [[ ${autoDelCron} == true ]]; then
|
||||||
del_cron $list_drop $uniq_path
|
del_cron $list_drop $uniq_path
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ -s $list_add ]]; then
|
if [[ -s $list_add ]]; then
|
||||||
output_list_add_drop $list_add "新"
|
output_list_add_drop $list_add "新"
|
||||||
if [[ ${AutoAddCron} == true ]]; then
|
if [[ ${autoAddCron} == true ]]; then
|
||||||
add_cron $list_add $uniq_path
|
add_cron $list_add $uniq_path
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -389,12 +379,12 @@ gen_list_repo() {
|
|||||||
filename=$(basename $file)
|
filename=$(basename $file)
|
||||||
cp -f $file "$dir_scripts/${uniq_path}/${filename}"
|
cp -f $file "$dir_scripts/${uniq_path}/${filename}"
|
||||||
echo "${uniq_path}/${filename}" >>"$dir_list_tmp/${uniq_path}_scripts.list"
|
echo "${uniq_path}/${filename}" >>"$dir_list_tmp/${uniq_path}_scripts.list"
|
||||||
cron_id=$(cat $list_crontab_user | grep -E "$cmd_task ${uniq_path}_${filename}" | perl -pe "s|.*ID=(.*) $cmd_task ${uniq_path}_${filename}\.*|\1|" | head -1 | awk -F " " '{print $1}')
|
# cron_id=$(cat $list_crontab_user | grep -E "$cmd_task.* ${uniq_path}_${filename}" | perl -pe "s|.*ID=(.*) $cmd_task.* ${uniq_path}_${filename}\.*|\1|" | head -1 | awk -F " " '{print $1}')
|
||||||
if [[ $cron_id ]]; then
|
# if [[ $cron_id ]]; then
|
||||||
result=$(update_cron_command_api "$cmd_task ${uniq_path}/${filename}:$cron_id")
|
# result=$(update_cron_command_api "$cmd_task ${uniq_path}/${filename}:$cron_id")
|
||||||
fi
|
# fi
|
||||||
done
|
done
|
||||||
grep -E "${cmd_task} ${uniq_path}" ${list_crontab_user} | perl -pe "s|.*ID=(.*) ${cmd_task} (${uniq_path}.*)\.*|\2|" | awk -F " " '{print $1}' | sort -u >"$dir_list_tmp/${uniq_path}_user.list"
|
grep -E "${cmd_task}.* ${uniq_path}" ${list_crontab_user} | perl -pe "s|.*ID=(.*) ${cmd_task}.* (${uniq_path}.*)\.*|\2|" | awk -F " " '{print $1}' | sort -u >"$dir_list_tmp/${uniq_path}_user.list"
|
||||||
cd $dir_current
|
cd $dir_current
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,37 +415,61 @@ main() {
|
|||||||
done
|
done
|
||||||
[[ "$show_log" == "true" ]] && shift $(($OPTIND - 1))
|
[[ "$show_log" == "true" ]] && shift $(($OPTIND - 1))
|
||||||
|
|
||||||
local p1=$1
|
local p1="${1}"
|
||||||
local p2=$2
|
local p2="${2}"
|
||||||
local p3=$3
|
local p3="${3}"
|
||||||
local p4=$4
|
local p4="${4}"
|
||||||
local p5=$5
|
local p5="${5}"
|
||||||
local p6=$6
|
local p6="${6}"
|
||||||
local p7=$7
|
local p7="${7}"
|
||||||
|
local p8="${8}"
|
||||||
|
local p9="${9}"
|
||||||
|
local p10="${10}"
|
||||||
|
local log_dir="${p1}"
|
||||||
|
make_dir "$dir_log/$log_dir"
|
||||||
local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
local log_time=$(date "+%Y-%m-%d-%H-%M-%S")
|
||||||
local log_path="$dir_log/update/${log_time}_$p1.log"
|
local log_path="${log_dir}/${log_time}.log"
|
||||||
local begin_time=$(date '+%Y-%m-%d %H:%M:%S')
|
local file_path="$dir_log/$log_path"
|
||||||
|
|
||||||
|
cmd=">> $file_path 2>&1"
|
||||||
|
[[ "$show_log" == "true" ]] && cmd=""
|
||||||
|
|
||||||
|
local time_format="%Y-%m-%d %H:%M:%S"
|
||||||
|
local time=$(date "+$time_format")
|
||||||
|
local begin_timestamp=$(format_timestamp "$time_format" "$time")
|
||||||
|
[[ $ID ]] && update_cron "\"$ID\"" "0" "$$" "$log_path" "$begin_timestamp"
|
||||||
|
|
||||||
|
local begin_time=$(format_time "$time_format" "$time")
|
||||||
|
|
||||||
|
if [[ "$p1" != "repo" ]] && [[ "$p1" != "raw" ]]; then
|
||||||
|
eval echo -e "\#\# 开始执行... $begin_time\\\n" $cmd
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -s $task_error_log_path ]]; then
|
||||||
|
eval cat $task_error_log_path $cmd
|
||||||
|
eval echo -e "加载 config.sh 出错,请手动检查" $cmd
|
||||||
|
eval echo $cmd
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$show_log" == "true" ]] && [[ $ID ]]; then
|
||||||
|
eval echo -e "请移除 -l 参数" $cmd
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
case $p1 in
|
case $p1 in
|
||||||
update)
|
update)
|
||||||
cmd=">> $log_path 2>&1"
|
|
||||||
[[ "$show_log" == "true" ]] && cmd=""
|
|
||||||
eval echo -e "## 开始执行... $begin_time\n" $cmd
|
|
||||||
[[ -f $task_error_log_path ]] && eval cat $task_error_log_path $cmd
|
|
||||||
eval update_qinglong "$2" $cmd
|
eval update_qinglong "$2" $cmd
|
||||||
;;
|
;;
|
||||||
extra)
|
extra)
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
eval run_extra_shell $cmd
|
||||||
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
|
||||||
run_extra_shell >>$log_path
|
|
||||||
;;
|
;;
|
||||||
repo)
|
repo)
|
||||||
get_uniq_path "$p2" "$p6"
|
get_uniq_path "$p2" "$p6"
|
||||||
if [[ -n $p2 ]]; then
|
if [[ -n $p2 ]]; then
|
||||||
update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7"
|
update_repo "$p2" "$p3" "$p4" "$p5" "$p6" "$p7" "$p8" "$p9" "$p10"
|
||||||
else
|
else
|
||||||
echo -e "命令输入错误...\n"
|
eval echo -e "命令输入错误...\\\n" $cmd
|
||||||
usage
|
eval usage $cmd
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
raw)
|
raw)
|
||||||
@@ -463,47 +477,47 @@ main() {
|
|||||||
if [[ -n $p2 ]]; then
|
if [[ -n $p2 ]]; then
|
||||||
update_raw "$p2"
|
update_raw "$p2"
|
||||||
else
|
else
|
||||||
echo -e "命令输入错误...\n"
|
eval echo -e "命令输入错误...\\\n" $cmd
|
||||||
usage
|
eval usage $cmd
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
rmlog)
|
rmlog)
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
eval . $dir_shell/rmlog.sh "$p2" $cmd
|
||||||
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
|
||||||
. $dir_shell/rmlog.sh "$p2" >>$log_path
|
|
||||||
;;
|
;;
|
||||||
bot)
|
bot)
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
eval . $dir_shell/bot.sh $cmd
|
||||||
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
|
||||||
. $dir_shell/bot.sh >>$log_path
|
|
||||||
;;
|
;;
|
||||||
check)
|
check)
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
eval . $dir_shell/check.sh $cmd
|
||||||
[[ -f $task_error_log_path ]] && cat $task_error_log_path >>$log_path
|
|
||||||
. $dir_shell/check.sh >>$log_path
|
|
||||||
;;
|
;;
|
||||||
resetlet)
|
resetlet)
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
|
||||||
auth_value=$(cat $file_auth_user | jq '.retries =0' -c)
|
auth_value=$(cat $file_auth_user | jq '.retries =0' -c)
|
||||||
echo -e "重置登录错误次数成功 \n $auth_value" >>$log_path
|
|
||||||
echo "$auth_value" >$file_auth_user
|
echo "$auth_value" >$file_auth_user
|
||||||
|
eval echo -e "重置登录错误次数成功" $cmd
|
||||||
;;
|
;;
|
||||||
resettfa)
|
resettfa)
|
||||||
echo -e "## 开始执行... $begin_time\n" >>$log_path
|
|
||||||
auth_value=$(cat $file_auth_user | jq '.twoFactorActivated =false' | jq '.twoFactorActived =false' -c)
|
auth_value=$(cat $file_auth_user | jq '.twoFactorActivated =false' | jq '.twoFactorActived =false' -c)
|
||||||
echo -e "禁用两步验证成功 \n $auth_value" >>$log_path
|
|
||||||
echo "$auth_value" >$file_auth_user
|
echo "$auth_value" >$file_auth_user
|
||||||
|
eval echo -e "禁用两步验证成功" $cmd
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "命令输入错误...\n"
|
eval echo -e "命令输入错误...\\\n" $cmd
|
||||||
usage
|
eval usage $cmd
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
local end_time=$(date '+%Y-%m-%d %H:%M:%S')
|
|
||||||
local diff_time=$(diff_time "%Y-%m-%d %H:%M:%S" "$begin_time" "$end_time")
|
local etime=$(date "+$time_format")
|
||||||
if [[ $p1 != "repo" ]] && [[ $p1 != "raw" ]]; then
|
local end_time=$(format_time "$time_format" "$etime")
|
||||||
echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒" >>$log_path
|
local end_timestamp=$(format_timestamp "$time_format" "$etime")
|
||||||
cat $log_path
|
local diff_time=$(($end_timestamp - $begin_timestamp))
|
||||||
|
[[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time"
|
||||||
|
|
||||||
|
if [[ "$p1" != "repo" ]] && [[ "$p1" != "raw" ]]; then
|
||||||
|
eval echo -e "\\\n\#\# 执行结束... $end_time 耗时 $diff_time 秒 " $cmd
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f $file_path ]]; then
|
||||||
|
cat $file_path
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import React, { useRef, useState, useEffect } from 'react';
|
||||||
|
import { Tooltip, Typography } from 'antd';
|
||||||
|
import { CopyOutlined, CheckOutlined } from '@ant-design/icons';
|
||||||
|
import { CopyToClipboard } from 'react-copy-to-clipboard';
|
||||||
|
|
||||||
|
const { Link } = Typography;
|
||||||
|
|
||||||
|
const Copy = ({ text }: { text: string }) => {
|
||||||
|
const [copied, setCopied] = useState(false);
|
||||||
|
const copyIdRef = useRef<number>();
|
||||||
|
|
||||||
|
const copyText = (e?: React.MouseEvent) => {
|
||||||
|
e?.preventDefault();
|
||||||
|
e?.stopPropagation();
|
||||||
|
|
||||||
|
setCopied(true);
|
||||||
|
|
||||||
|
cleanCopyId();
|
||||||
|
copyIdRef.current = window.setTimeout(() => {
|
||||||
|
setCopied(false);
|
||||||
|
}, 3000);
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanCopyId = () => {
|
||||||
|
window.clearTimeout(copyIdRef.current!);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link onClick={copyText} style={{ marginLeft: 1 }}>
|
||||||
|
<CopyToClipboard text={text}>
|
||||||
|
<Tooltip key="copy" title={copied ? '复制成功' : '复制'}>
|
||||||
|
{copied ? <CheckOutlined /> : <CopyOutlined />}
|
||||||
|
</Tooltip>
|
||||||
|
</CopyToClipboard>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Copy;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { createFromIconfontCN } from '@ant-design/icons';
|
import { createFromIconfontCN } from '@ant-design/icons';
|
||||||
|
|
||||||
const IconFont = createFromIconfontCN({
|
const IconFont = createFromIconfontCN({
|
||||||
scriptUrl: ['//at.alicdn.com/t/font_3354854_ds8pa06q1qa.js'],
|
scriptUrl: ['//at.alicdn.com/t/c/font_3354854_ob5y15ewlyq.js'],
|
||||||
});
|
});
|
||||||
|
|
||||||
export default IconFont;
|
export default IconFont;
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { MutableRefObject, useLayoutEffect, useState } from 'react';
|
||||||
|
import useResizeObserver from '@react-hook/resize-observer'
|
||||||
|
import { getTableScroll } from '@/utils';
|
||||||
|
|
||||||
|
export default <T extends HTMLElement>(target: MutableRefObject<T>, extraHeight?: number) => {
|
||||||
|
const [height, setHeight] = useState<number>()
|
||||||
|
|
||||||
|
useResizeObserver(target, (entry) => {
|
||||||
|
let _targe = entry.target as any
|
||||||
|
if (!_targe.classList.contains('ant-table-wrapper')) {
|
||||||
|
_targe = entry.target.querySelector('.ant-table-wrapper')
|
||||||
|
}
|
||||||
|
setHeight(getTableScroll({ extraHeight, target: _targe as HTMLElement }))
|
||||||
|
})
|
||||||
|
return height
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
ContainerOutlined,
|
ContainerOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import IconFont from '@/components/iconfont';
|
import IconFont from '@/components/iconfont';
|
||||||
|
import { BasicLayoutProps } from '@ant-design/pro-layout';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
route: {
|
route: {
|
||||||
@@ -93,4 +94,4 @@ export default {
|
|||||||
contentWidth: 'Fixed',
|
contentWidth: 'Fixed',
|
||||||
splitMenus: false,
|
splitMenus: false,
|
||||||
siderWidth: 180,
|
siderWidth: 180,
|
||||||
} as any;
|
} as BasicLayoutProps;
|
||||||
|
|||||||
+16
-5
@@ -10,8 +10,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.ant-modal-body {
|
.ant-modal-body {
|
||||||
max-height: calc(85vh - 110px);
|
max-height: calc(80vh - 110px);
|
||||||
max-height: calc(85vh - var(--vh-offset, 110px));
|
max-height: calc(80vh - var(--vh-offset, 110px));
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,8 +179,8 @@
|
|||||||
|
|
||||||
.Resizer {
|
.Resizer {
|
||||||
background: @component-background;
|
background: @component-background;
|
||||||
opacity: 0.2;
|
opacity: 0.8;
|
||||||
z-index: 1;
|
z-index: 100;
|
||||||
-moz-box-sizing: border-box;
|
-moz-box-sizing: border-box;
|
||||||
-webkit-box-sizing: border-box;
|
-webkit-box-sizing: border-box;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
@@ -253,10 +253,11 @@ textarea:-webkit-autofill:focus,
|
|||||||
select:-webkit-autofill,
|
select:-webkit-autofill,
|
||||||
select:-webkit-autofill:hover,
|
select:-webkit-autofill:hover,
|
||||||
select:-webkit-autofill:focus {
|
select:-webkit-autofill:focus {
|
||||||
border: none;
|
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
transition: background-color 5000s ease-in-out 0s;
|
transition: background-color 5000s ease-in-out 0s;
|
||||||
-webkit-text-fill-color: @text-color;
|
-webkit-text-fill-color: @text-color;
|
||||||
|
caret-color: @text-color;
|
||||||
|
color: @text-color;
|
||||||
}
|
}
|
||||||
|
|
||||||
::placeholder {
|
::placeholder {
|
||||||
@@ -342,3 +343,13 @@ select:-webkit-autofill:focus {
|
|||||||
width: auto !important;
|
width: auto !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
word-break: break-all !important;
|
||||||
|
white-space: break-spaces !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.virtuallist .ant-table-tbody > tr > td > div {
|
||||||
|
white-space: unset !important;
|
||||||
|
}
|
||||||
|
|||||||
+62
-32
@@ -13,9 +13,20 @@ import config from '@/utils/config';
|
|||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
import vhCheck from 'vh-check';
|
import vhCheck from 'vh-check';
|
||||||
import { version, changeLogLink, changeLog } from '../version';
|
|
||||||
import { useCtx, useTheme } from '@/utils/hooks';
|
import { useCtx, useTheme } from '@/utils/hooks';
|
||||||
import { message, Badge, Modal, Avatar, Dropdown, Menu, Image } from 'antd';
|
import {
|
||||||
|
message,
|
||||||
|
Badge,
|
||||||
|
Modal,
|
||||||
|
Avatar,
|
||||||
|
Dropdown,
|
||||||
|
Menu,
|
||||||
|
Image,
|
||||||
|
Popover,
|
||||||
|
Descriptions,
|
||||||
|
Tooltip,
|
||||||
|
MenuProps,
|
||||||
|
} from 'antd';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import SockJS from 'sockjs-client';
|
import SockJS from 'sockjs-client';
|
||||||
import * as Sentry from '@sentry/react';
|
import * as Sentry from '@sentry/react';
|
||||||
@@ -32,6 +43,17 @@ export interface SharedContext {
|
|||||||
reloadUser: (needLoading?: boolean) => void;
|
reloadUser: (needLoading?: boolean) => void;
|
||||||
reloadTheme: () => void;
|
reloadTheme: () => void;
|
||||||
socketMessage: any;
|
socketMessage: any;
|
||||||
|
systemInfo: TSystemInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TSystemInfo {
|
||||||
|
branch: 'develop' | 'master';
|
||||||
|
isInitialized: boolean;
|
||||||
|
lastCommitId: string;
|
||||||
|
lastCommitTime: number;
|
||||||
|
version: string;
|
||||||
|
changeLog: string;
|
||||||
|
changeLogLink: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
@@ -40,7 +62,7 @@ export default function () {
|
|||||||
const { theme, reloadTheme } = useTheme();
|
const { theme, reloadTheme } = useTheme();
|
||||||
const [user, setUser] = useState<any>({});
|
const [user, setUser] = useState<any>({});
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
const [systemInfo, setSystemInfo] = useState<{ isInitialized: boolean }>();
|
const [systemInfo, setSystemInfo] = useState<TSystemInfo>();
|
||||||
const ws = useRef<any>(null);
|
const ws = useRef<any>(null);
|
||||||
const [socketMessage, setSocketMessage] = useState<any>();
|
const [socketMessage, setSocketMessage] = useState<any>();
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
@@ -69,6 +91,7 @@ export default function () {
|
|||||||
if (!data.isInitialized) {
|
if (!data.isInitialized) {
|
||||||
history.push('/initialization');
|
history.push('/initialization');
|
||||||
} else {
|
} else {
|
||||||
|
init(data.version);
|
||||||
getUser();
|
getUser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +146,6 @@ export default function () {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
vhCheck();
|
vhCheck();
|
||||||
init();
|
|
||||||
|
|
||||||
const _theme = localStorage.getItem('qinglong_dark_theme') || 'auto';
|
const _theme = localStorage.getItem('qinglong_dark_theme') || 'auto';
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
@@ -201,9 +223,6 @@ export default function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (['/login', '/initialization', '/error'].includes(location.pathname)) {
|
if (['/login', '/initialization', '/error'].includes(location.pathname)) {
|
||||||
document.title = `${
|
|
||||||
(config.documentTitleMap as any)[location.pathname]
|
|
||||||
} - 控制面板`;
|
|
||||||
if (systemInfo?.isInitialized && location.pathname === '/initialization') {
|
if (systemInfo?.isInitialized && location.pathname === '/initialization') {
|
||||||
history.push('/crontab');
|
history.push('/crontab');
|
||||||
}
|
}
|
||||||
@@ -230,13 +249,17 @@ export default function () {
|
|||||||
!navigator.userAgent.includes('Chrome');
|
!navigator.userAgent.includes('Chrome');
|
||||||
const isQQBrowser = navigator.userAgent.includes('QQBrowser');
|
const isQQBrowser = navigator.userAgent.includes('QQBrowser');
|
||||||
|
|
||||||
const menu = (
|
const menu: MenuProps = {
|
||||||
<Menu
|
items: [
|
||||||
className="side-menu-user-drop-menu"
|
{
|
||||||
items={[{ label: '退出登录', key: 'logout', icon: <LogoutOutlined /> }]}
|
label: '退出登录',
|
||||||
onClick={logout}
|
className: 'side-menu-user-drop-menu',
|
||||||
/>
|
onClick: logout,
|
||||||
);
|
key: 'logout',
|
||||||
|
icon: <LogoutOutlined />,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
return loading ? (
|
return loading ? (
|
||||||
<PageLoading />
|
<PageLoading />
|
||||||
) : (
|
) : (
|
||||||
@@ -244,29 +267,36 @@ export default function () {
|
|||||||
selectedKeys={[location.pathname]}
|
selectedKeys={[location.pathname]}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
ErrorBoundary={Sentry.ErrorBoundary}
|
ErrorBoundary={Sentry.ErrorBoundary}
|
||||||
logo={<Image preview={false} src="http://qn.whyour.cn/logo.png" />}
|
logo={<Image preview={false} src="https://qn.whyour.cn/logo.png" />}
|
||||||
|
// @ts-ignore
|
||||||
title={
|
title={
|
||||||
<>
|
<>
|
||||||
<span style={{ fontSize: 16 }}>控制面板</span>
|
<span style={{ fontSize: 16 }}>控制面板</span>
|
||||||
<a
|
<a
|
||||||
href={changeLogLink}
|
href={systemInfo?.changeLogLink}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span
|
<Tooltip
|
||||||
style={{
|
title={systemInfo?.branch === 'develop' ? '开发版' : '正式版'}
|
||||||
fontSize: isFirefox ? 9 : 12,
|
|
||||||
color: '#666',
|
|
||||||
marginLeft: 2,
|
|
||||||
zoom: isSafari ? 0.66 : 0.8,
|
|
||||||
letterSpacing: isQQBrowser ? -2 : 0,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
v{version}
|
<Badge size="small" dot={systemInfo?.branch === 'develop'}>
|
||||||
</span>
|
<span
|
||||||
|
style={{
|
||||||
|
fontSize: isFirefox ? 9 : 12,
|
||||||
|
color: '#666',
|
||||||
|
marginLeft: 2,
|
||||||
|
zoom: isSafari ? 0.66 : 0.8,
|
||||||
|
letterSpacing: isQQBrowser ? -2 : 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
v{systemInfo?.version}
|
||||||
|
</span>
|
||||||
|
</Badge>
|
||||||
|
</Tooltip>
|
||||||
</a>
|
</a>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
@@ -281,16 +311,15 @@ export default function () {
|
|||||||
return <Link to={menuItemProps.path}>{defaultDom}</Link>;
|
return <Link to={menuItemProps.path}>{defaultDom}</Link>;
|
||||||
}}
|
}}
|
||||||
pageTitleRender={(props, pageName, info) => {
|
pageTitleRender={(props, pageName, info) => {
|
||||||
if (info && typeof info.pageName === 'string') {
|
const title =
|
||||||
return `${info.pageName} - 控制面板`;
|
(config.documentTitleMap as any)[location.pathname] || '未找到';
|
||||||
}
|
return `${title} - 控制面板`;
|
||||||
return '控制面板';
|
|
||||||
}}
|
}}
|
||||||
onCollapse={setCollapsed}
|
onCollapse={setCollapsed}
|
||||||
collapsed={collapsed}
|
collapsed={collapsed}
|
||||||
rightContentRender={() =>
|
rightContentRender={() =>
|
||||||
ctx.isPhone && (
|
ctx.isPhone && (
|
||||||
<Dropdown overlay={menu} placement="bottomRight" trigger={['click']}>
|
<Dropdown menu={menu} placement="bottomRight" trigger={['click']}>
|
||||||
<span className="side-menu-user-wrapper">
|
<span className="side-menu-user-wrapper">
|
||||||
<Avatar
|
<Avatar
|
||||||
shape="square"
|
shape="square"
|
||||||
@@ -312,7 +341,7 @@ export default function () {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{!collapsed && !ctx.isPhone && (
|
{!collapsed && !ctx.isPhone && (
|
||||||
<Dropdown overlay={menu} placement="topLeft" trigger={['hover']}>
|
<Dropdown menu={menu} placement="topLeft" trigger={['hover']}>
|
||||||
<span className="side-menu-user-wrapper">
|
<span className="side-menu-user-wrapper">
|
||||||
<Avatar
|
<Avatar
|
||||||
shape="square"
|
shape="square"
|
||||||
@@ -342,6 +371,7 @@ export default function () {
|
|||||||
reloadUser,
|
reloadUser,
|
||||||
reloadTheme,
|
reloadTheme,
|
||||||
socketMessage,
|
socketMessage,
|
||||||
|
systemInfo,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ProLayout>
|
</ProLayout>
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Button, Result, Typography } from 'antd';
|
||||||
|
|
||||||
|
const { Link } = Typography;
|
||||||
|
|
||||||
|
const NotFound: React.FC = () => (
|
||||||
|
<Result
|
||||||
|
status="404"
|
||||||
|
title="404"
|
||||||
|
extra={
|
||||||
|
<Button type="primary">
|
||||||
|
<Link href="/">返回首页</Link>
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default NotFound;
|
||||||
@@ -80,6 +80,7 @@ const Config = () => {
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
extra={[
|
extra={[
|
||||||
<TreeSelect
|
<TreeSelect
|
||||||
|
treeExpandAction="click"
|
||||||
className="config-select"
|
className="config-select"
|
||||||
value={select}
|
value={select}
|
||||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import config from '@/utils/config';
|
|||||||
import CronLogModal from './logModal';
|
import CronLogModal from './logModal';
|
||||||
import Editor from '@monaco-editor/react';
|
import Editor from '@monaco-editor/react';
|
||||||
import IconFont from '@/components/iconfont';
|
import IconFont from '@/components/iconfont';
|
||||||
|
import { getCommandScript } from '@/utils';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
@@ -147,22 +148,10 @@ const CronDetailModal = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getScript = () => {
|
const getScript = () => {
|
||||||
const cmd = cron.command.split(' ') as string[];
|
const result = getCommandScript(cron.command);
|
||||||
if (cmd[0] === 'task') {
|
if (Array.isArray(result)) {
|
||||||
setValidTabs(validTabs);
|
setValidTabs(validTabs);
|
||||||
if (cmd[1].startsWith('/ql/data/scripts')) {
|
const [s, p] = result;
|
||||||
cmd[1] = cmd[1].replace('/ql/data/scripts/', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
let p: string, s: string;
|
|
||||||
let index = cmd[1].lastIndexOf('/');
|
|
||||||
if (index >= 0) {
|
|
||||||
s = cmd[1].slice(index + 1);
|
|
||||||
p = cmd[1].slice(0, index);
|
|
||||||
} else {
|
|
||||||
s = cmd[1];
|
|
||||||
p = '';
|
|
||||||
}
|
|
||||||
setScriptInfo({ parent: p, filename: s });
|
setScriptInfo({ parent: p, filename: s });
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}scripts/${s}?path=${p || ''}`)
|
.get(`${config.apiPrefix}scripts/${s}?path=${p || ''}`)
|
||||||
@@ -171,7 +160,7 @@ const CronDetailModal = ({
|
|||||||
setValue(data);
|
setValue(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else if (result) {
|
||||||
setValidTabs([validTabs[0]]);
|
setValidTabs([validTabs[0]]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,13 +4,10 @@
|
|||||||
|
|
||||||
.crontab-detail {
|
.crontab-detail {
|
||||||
.card-wrapper {
|
.card-wrapper {
|
||||||
height: 80vh;
|
|
||||||
height: calc(80vh - var(--vh-offset, 0px));
|
|
||||||
|
|
||||||
.ant-card:last-child {
|
.ant-card:last-child {
|
||||||
.ant-card-body {
|
.ant-card-body {
|
||||||
height: calc(80vh - 238px);
|
height: calc(80vh - 367px);
|
||||||
height: calc(80vh - var(--vh-offset, 0px) - 238px);
|
height: calc(80vh - var(--vh-offset, 0px) - 367px);
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,3 +173,21 @@ tr.drop-over-upward td {
|
|||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.view-filters-container.active {
|
||||||
|
.filter-item > div > .ant-form-item-control {
|
||||||
|
margin-left: 40px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-modal {
|
||||||
|
.log-container {
|
||||||
|
overflow-y: auto;
|
||||||
|
min-height: 300px;
|
||||||
|
max-height: calc(80vh - 110px);
|
||||||
|
max-height: calc(80vh - var(--vh-offset, 110px));
|
||||||
|
|
||||||
|
padding: 24px;
|
||||||
|
margin: -24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+185
-222
@@ -1,4 +1,4 @@
|
|||||||
import React, { PureComponent, Fragment, useState, useEffect } from 'react';
|
import React, { useState, useEffect, useRef, useMemo } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
message,
|
message,
|
||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
Popover,
|
Popover,
|
||||||
Tabs,
|
Tabs,
|
||||||
TablePaginationConfig,
|
TablePaginationConfig,
|
||||||
|
MenuProps,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import {
|
import {
|
||||||
ClockCircleOutlined,
|
ClockCircleOutlined,
|
||||||
@@ -43,14 +44,16 @@ import CronLogModal from './logModal';
|
|||||||
import CronDetailModal from './detail';
|
import CronDetailModal from './detail';
|
||||||
import cron_parser from 'cron-parser';
|
import cron_parser from 'cron-parser';
|
||||||
import { diffTime } from '@/utils/date';
|
import { diffTime } from '@/utils/date';
|
||||||
import { getTableScroll } from '@/utils/index';
|
|
||||||
import { history, useOutletContext } from '@umijs/max';
|
import { history, useOutletContext } from '@umijs/max';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
import ViewCreateModal from './viewCreateModal';
|
import ViewCreateModal from './viewCreateModal';
|
||||||
import ViewManageModal from './viewManageModal';
|
import ViewManageModal from './viewManageModal';
|
||||||
import pagination from 'antd/lib/pagination';
|
|
||||||
import { FilterValue, SorterResult } from 'antd/lib/table/interface';
|
import { FilterValue, SorterResult } from 'antd/lib/table/interface';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
|
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
||||||
|
import { getCommandScript, parseCrontab } from '@/utils';
|
||||||
|
import { ColumnProps } from 'antd/lib/table';
|
||||||
|
import { VList } from 'virtuallist-antd';
|
||||||
|
|
||||||
const { Text, Paragraph } = Typography;
|
const { Text, Paragraph } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
@@ -82,9 +85,23 @@ enum OperationPath {
|
|||||||
'unpin',
|
'unpin',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ICrontab {
|
||||||
|
name: string;
|
||||||
|
command: string;
|
||||||
|
schedule: string;
|
||||||
|
id: number;
|
||||||
|
status: number;
|
||||||
|
isDisabled?: 1 | 0;
|
||||||
|
isPinned?: 1 | 0;
|
||||||
|
labels?: string[];
|
||||||
|
last_running_time?: number;
|
||||||
|
last_execution_time?: number;
|
||||||
|
nextRunTime: Date;
|
||||||
|
}
|
||||||
|
|
||||||
const Crontab = () => {
|
const Crontab = () => {
|
||||||
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
||||||
const columns: any = [
|
const columns: ColumnProps<ICrontab>[] = [
|
||||||
{
|
{
|
||||||
title: '名称',
|
title: '名称',
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
@@ -138,16 +155,16 @@ const Crontab = () => {
|
|||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
sorter: {
|
sorter: {
|
||||||
compare: (a: any, b: any) => a?.name?.localeCompare(b?.name),
|
compare: (a, b) => a?.name?.localeCompare(b?.name),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '命令',
|
title: '命令/脚本',
|
||||||
dataIndex: 'command',
|
dataIndex: 'command',
|
||||||
key: 'command',
|
key: 'command',
|
||||||
width: 300,
|
width: 300,
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
render: (text: string, record: any) => {
|
render: (text, record) => {
|
||||||
return (
|
return (
|
||||||
<Paragraph
|
<Paragraph
|
||||||
style={{
|
style={{
|
||||||
@@ -178,7 +195,7 @@ const Crontab = () => {
|
|||||||
width: 110,
|
width: 110,
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
sorter: {
|
sorter: {
|
||||||
compare: (a: any, b: any) => a.schedule.localeCompare(b.schedule),
|
compare: (a, b) => a.schedule.localeCompare(b.schedule),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -188,11 +205,11 @@ const Crontab = () => {
|
|||||||
key: 'last_execution_time',
|
key: 'last_execution_time',
|
||||||
width: 150,
|
width: 150,
|
||||||
sorter: {
|
sorter: {
|
||||||
compare: (a: any, b: any) => {
|
compare: (a, b) => {
|
||||||
return a.last_execution_time - b.last_execution_time;
|
return (a.last_execution_time || 0) - (b.last_execution_time || 0);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
render: (text: string, record: any) => {
|
render: (text, record) => {
|
||||||
const language = navigator.language || navigator.languages[0];
|
const language = navigator.language || navigator.languages[0];
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
@@ -222,7 +239,7 @@ const Crontab = () => {
|
|||||||
return a.last_running_time - b.last_running_time;
|
return a.last_running_time - b.last_running_time;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
render: (text: string, record: any) => {
|
render: (text, record) => {
|
||||||
return record.last_running_time
|
return record.last_running_time
|
||||||
? diffTime(record.last_running_time)
|
? diffTime(record.last_running_time)
|
||||||
: '-';
|
: '-';
|
||||||
@@ -237,7 +254,7 @@ const Crontab = () => {
|
|||||||
return a.nextRunTime - b.nextRunTime;
|
return a.nextRunTime - b.nextRunTime;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
render: (text: string, record: any) => {
|
render: (text, record) => {
|
||||||
const language = navigator.language || navigator.languages[0];
|
const language = navigator.language || navigator.languages[0];
|
||||||
return record.nextRunTime
|
return record.nextRunTime
|
||||||
.toLocaleString(language, {
|
.toLocaleString(language, {
|
||||||
@@ -246,13 +263,12 @@ const Crontab = () => {
|
|||||||
.replace(' 24:', ' 00:');
|
.replace(' 24:', ' 00:');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
title: '状态',
|
title: '状态',
|
||||||
key: 'status',
|
key: 'status',
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
width: 85,
|
width: 88,
|
||||||
filters: [
|
filters: [
|
||||||
{
|
{
|
||||||
text: '运行中',
|
text: '运行中',
|
||||||
@@ -271,14 +287,14 @@ const Crontab = () => {
|
|||||||
value: 3,
|
value: 3,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
onFilter: (value: number, record: any) => {
|
onFilter: (value, record) => {
|
||||||
if (record.isDisabled && record.status !== 0) {
|
if (record.isDisabled && record.status !== 0) {
|
||||||
return value === 2;
|
return value === 2;
|
||||||
} else {
|
} else {
|
||||||
return record.status === value;
|
return record.status === value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: (text: string, record: any) => (
|
render: (text, record) => (
|
||||||
<>
|
<>
|
||||||
{(!record.isDisabled || record.status !== CrontabStatus.idle) && (
|
{(!record.isDisabled || record.status !== CrontabStatus.idle) && (
|
||||||
<>
|
<>
|
||||||
@@ -315,7 +331,7 @@ const Crontab = () => {
|
|||||||
key: 'action',
|
key: 'action',
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
width: 100,
|
width: 100,
|
||||||
render: (text: string, record: any, index: number) => {
|
render: (text, record, index) => {
|
||||||
const isPc = !isPhone;
|
const isPc = !isPhone;
|
||||||
return (
|
return (
|
||||||
<Space size="middle">
|
<Space size="middle">
|
||||||
@@ -376,7 +392,6 @@ const Crontab = () => {
|
|||||||
filters: any;
|
filters: any;
|
||||||
}>({} as any);
|
}>({} as any);
|
||||||
const [viewConf, setViewConf] = useState<any>();
|
const [viewConf, setViewConf] = useState<any>();
|
||||||
const [tableScrollHeight, setTableScrollHeight] = useState<number>();
|
|
||||||
const [isDetailModalVisible, setIsDetailModalVisible] = useState(false);
|
const [isDetailModalVisible, setIsDetailModalVisible] = useState(false);
|
||||||
const [detailCron, setDetailCron] = useState<any>();
|
const [detailCron, setDetailCron] = useState<any>();
|
||||||
const [searchValue, setSearchValue] = useState('');
|
const [searchValue, setSearchValue] = useState('');
|
||||||
@@ -388,26 +403,16 @@ const Crontab = () => {
|
|||||||
const [cronViews, setCronViews] = useState<any[]>([]);
|
const [cronViews, setCronViews] = useState<any[]>([]);
|
||||||
const [enabledCronViews, setEnabledCronViews] = useState<any[]>([]);
|
const [enabledCronViews, setEnabledCronViews] = useState<any[]>([]);
|
||||||
const [moreMenuActive, setMoreMenuActive] = useState(false);
|
const [moreMenuActive, setMoreMenuActive] = useState(false);
|
||||||
|
const tableRef = useRef<any>();
|
||||||
|
const tableScrollHeight = useTableScrollHeight(tableRef);
|
||||||
|
|
||||||
const goToScriptManager = (record: any) => {
|
const goToScriptManager = (record: any) => {
|
||||||
const cmd = record.command.split(' ') as string[];
|
const result = getCommandScript(record.command);
|
||||||
if (cmd[0] === 'task') {
|
if (Array.isArray(result)) {
|
||||||
if (cmd[1].startsWith('/ql/data/scripts')) {
|
const [s, p] = result;
|
||||||
cmd[1] = cmd[1].replace('/ql/data/scripts/', '');
|
|
||||||
}
|
|
||||||
|
|
||||||
let p: string, s: string;
|
|
||||||
let index = cmd[1].lastIndexOf('/');
|
|
||||||
if (index >= 0) {
|
|
||||||
s = cmd[1].slice(index + 1);
|
|
||||||
p = cmd[1].slice(0, index);
|
|
||||||
} else {
|
|
||||||
s = cmd[1];
|
|
||||||
p = '';
|
|
||||||
}
|
|
||||||
history.push(`/script?p=${p}&s=${s}`);
|
history.push(`/script?p=${p}&s=${s}`);
|
||||||
} else if (cmd[1] === 'repo') {
|
} else if (result) {
|
||||||
location.href = cmd[2];
|
location.href = result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -429,6 +434,7 @@ const Crontab = () => {
|
|||||||
url += `&queryString=${JSON.stringify({
|
url += `&queryString=${JSON.stringify({
|
||||||
filters: viewConf.filters,
|
filters: viewConf.filters,
|
||||||
sorts: viewConf.sorts,
|
sorts: viewConf.sorts,
|
||||||
|
filterRelation: viewConf.filterRelation || 'and',
|
||||||
})}`;
|
})}`;
|
||||||
}
|
}
|
||||||
request
|
request
|
||||||
@@ -440,10 +446,7 @@ const Crontab = () => {
|
|||||||
data.map((x) => {
|
data.map((x) => {
|
||||||
return {
|
return {
|
||||||
...x,
|
...x,
|
||||||
nextRunTime: cron_parser
|
nextRunTime: parseCrontab(x.schedule),
|
||||||
.parseExpression(x.schedule)
|
|
||||||
.next()
|
|
||||||
.toDate(),
|
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
@@ -681,15 +684,13 @@ const Crontab = () => {
|
|||||||
arrow={{ pointAtCenter: true }}
|
arrow={{ pointAtCenter: true }}
|
||||||
placement="bottomRight"
|
placement="bottomRight"
|
||||||
trigger={['click']}
|
trigger={['click']}
|
||||||
overlay={
|
menu={{
|
||||||
<Menu
|
items: getMenuItems(record),
|
||||||
items={getMenuItems(record)}
|
onClick: ({ key, domEvent }) => {
|
||||||
onClick={({ key, domEvent }) => {
|
domEvent.stopPropagation();
|
||||||
domEvent.stopPropagation();
|
action(key, record, index);
|
||||||
action(key, record, index);
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<a onClick={(e) => e.stopPropagation()}>
|
<a onClick={(e) => e.stopPropagation()}>
|
||||||
<EllipsisOutlined />
|
<EllipsisOutlined />
|
||||||
@@ -716,34 +717,15 @@ const Crontab = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = (cron?: any) => {
|
const handleCancel = () => {
|
||||||
setIsModalVisible(false);
|
setIsModalVisible(false);
|
||||||
if (cron) {
|
getCrons();
|
||||||
handleCrons(cron);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSearch = (value: string) => {
|
const onSearch = (value: string) => {
|
||||||
setSearchText(value.trim());
|
setSearchText(value.trim());
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCrons = (cron: any) => {
|
|
||||||
const index = value.findIndex((x) => x.id === cron.id);
|
|
||||||
const result = [...value];
|
|
||||||
cron.nextRunTime = cron_parser
|
|
||||||
.parseExpression(cron.schedule)
|
|
||||||
.next()
|
|
||||||
.toDate();
|
|
||||||
if (index === -1) {
|
|
||||||
result.unshift(cron);
|
|
||||||
} else {
|
|
||||||
result.splice(index, 1, {
|
|
||||||
...cron,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
setValue(result);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCronDetail = (cron: any) => {
|
const getCronDetail = (cron: any) => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}crons/${cron.id}`)
|
.get(`${config.apiPrefix}crons/${cron.id}`)
|
||||||
@@ -751,10 +733,7 @@ const Crontab = () => {
|
|||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
const index = value.findIndex((x) => x.id === cron.id);
|
const index = value.findIndex((x) => x.id === cron.id);
|
||||||
const result = [...value];
|
const result = [...value];
|
||||||
data.nextRunTime = cron_parser
|
data.nextRunTime = parseCrontab(data.schedule);
|
||||||
.parseExpression(data.schedule)
|
|
||||||
.next()
|
|
||||||
.toDate();
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
result.splice(index, 1, {
|
result.splice(index, 1, {
|
||||||
...cron,
|
...cron,
|
||||||
@@ -769,16 +748,10 @@ const Crontab = () => {
|
|||||||
|
|
||||||
const onSelectChange = (selectedIds: any[]) => {
|
const onSelectChange = (selectedIds: any[]) => {
|
||||||
setSelectedRowIds(selectedIds);
|
setSelectedRowIds(selectedIds);
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
if (selectedRowIds.length === 0 || selectedIds.length === 0) {
|
|
||||||
setTableScrollHeight(getTableScroll());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const rowSelection = {
|
const rowSelection = {
|
||||||
selectedRowIds,
|
selectedRowKeys: selectedRowIds,
|
||||||
onChange: onSelectChange,
|
onChange: onSelectChange,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -862,7 +835,7 @@ const Crontab = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (viewConf && enabledCronViews && enabledCronViews.length > 0) {
|
if (viewConf && enabledCronViews && enabledCronViews.length > 0) {
|
||||||
const view = enabledCronViews.slice(2).find((x) => x.id === viewConf.id);
|
const view = enabledCronViews.slice(4).find((x) => x.id === viewConf.id);
|
||||||
setMoreMenuActive(!!view);
|
setMoreMenuActive(!!view);
|
||||||
}
|
}
|
||||||
}, [viewConf, enabledCronViews]);
|
}, [viewConf, enabledCronViews]);
|
||||||
@@ -874,96 +847,9 @@ const Crontab = () => {
|
|||||||
sorter: {},
|
sorter: {},
|
||||||
filters: {},
|
filters: {},
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
|
||||||
setTableScrollHeight(getTableScroll());
|
|
||||||
});
|
|
||||||
getCronViews();
|
getCronViews();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const panelContent = (
|
|
||||||
<>
|
|
||||||
{selectedRowIds.length > 0 && (
|
|
||||||
<div style={{ marginBottom: 16 }}>
|
|
||||||
<Button type="primary" style={{ marginBottom: 5 }} onClick={delCrons}>
|
|
||||||
批量删除
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
onClick={() => operateCrons(0)}
|
|
||||||
style={{ marginLeft: 8, marginBottom: 5 }}
|
|
||||||
>
|
|
||||||
批量启用
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
onClick={() => operateCrons(1)}
|
|
||||||
style={{ marginLeft: 8, marginRight: 8 }}
|
|
||||||
>
|
|
||||||
批量禁用
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
style={{ marginRight: 8 }}
|
|
||||||
onClick={() => operateCrons(2)}
|
|
||||||
>
|
|
||||||
批量运行
|
|
||||||
</Button>
|
|
||||||
<Button type="primary" onClick={() => operateCrons(3)}>
|
|
||||||
批量停止
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
onClick={() => operateCrons(4)}
|
|
||||||
style={{ marginLeft: 8, marginRight: 8 }}
|
|
||||||
>
|
|
||||||
批量置顶
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
onClick={() => operateCrons(5)}
|
|
||||||
style={{ marginLeft: 8, marginRight: 8 }}
|
|
||||||
>
|
|
||||||
批量取消置顶
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
onClick={() => setIsLabelModalVisible(true)}
|
|
||||||
style={{ marginLeft: 8, marginRight: 8 }}
|
|
||||||
>
|
|
||||||
批量修改标签
|
|
||||||
</Button>
|
|
||||||
<span style={{ marginLeft: 8 }}>
|
|
||||||
已选择
|
|
||||||
<a>{selectedRowIds?.length}</a>项
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<Table
|
|
||||||
columns={columns}
|
|
||||||
pagination={{
|
|
||||||
current: pageConf.page,
|
|
||||||
pageSize: pageConf.size,
|
|
||||||
showSizeChanger: true,
|
|
||||||
simple: isPhone,
|
|
||||||
total,
|
|
||||||
showTotal: (total: number, range: number[]) =>
|
|
||||||
`第 ${range[0]}-${range[1]} 条/总共 ${total} 条`,
|
|
||||||
pageSizeOptions: [10, 20, 50, 100, 200, 500, total || 10000].sort(
|
|
||||||
(a, b) => a - b,
|
|
||||||
),
|
|
||||||
}}
|
|
||||||
dataSource={value}
|
|
||||||
rowKey="id"
|
|
||||||
size="middle"
|
|
||||||
scroll={{ x: 1000, y: tableScrollHeight }}
|
|
||||||
loading={loading}
|
|
||||||
rowSelection={rowSelection}
|
|
||||||
rowClassName={getRowClassName}
|
|
||||||
onChange={onPageChange}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
const viewAction = (key: string) => {
|
const viewAction = (key: string) => {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'new':
|
case 'new':
|
||||||
@@ -979,41 +865,39 @@ const Crontab = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const menu = (
|
const menu: MenuProps = {
|
||||||
<Menu
|
onClick: ({ key, domEvent }) => {
|
||||||
onClick={({ key, domEvent }) => {
|
domEvent.stopPropagation();
|
||||||
domEvent.stopPropagation();
|
viewAction(key);
|
||||||
viewAction(key);
|
},
|
||||||
}}
|
items: [
|
||||||
items={[
|
...[...enabledCronViews].slice(4).map((x) => ({
|
||||||
...[...enabledCronViews].slice(2).map((x) => ({
|
label: (
|
||||||
label: (
|
<Space style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
<Space style={{ display: 'flex', justifyContent: 'space-between' }}>
|
<span>{x.name}</span>
|
||||||
<span>{x.name}</span>
|
{viewConf?.id === x.id && (
|
||||||
{viewConf?.id === x.id && (
|
<CheckOutlined style={{ color: '#1890ff' }} />
|
||||||
<CheckOutlined style={{ color: '#1890ff' }} />
|
)}
|
||||||
)}
|
</Space>
|
||||||
</Space>
|
),
|
||||||
),
|
key: x.id,
|
||||||
key: x.id,
|
icon: <UnorderedListOutlined />,
|
||||||
icon: <UnorderedListOutlined />,
|
})),
|
||||||
})),
|
{
|
||||||
{
|
type: 'divider' as 'group',
|
||||||
type: 'divider',
|
},
|
||||||
},
|
{
|
||||||
{
|
label: '新建视图',
|
||||||
label: '新建视图',
|
key: 'new',
|
||||||
key: 'new',
|
icon: <PlusOutlined />,
|
||||||
icon: <PlusOutlined />,
|
},
|
||||||
},
|
{
|
||||||
{
|
label: '视图管理',
|
||||||
label: '视图管理',
|
key: 'manage',
|
||||||
key: 'manage',
|
icon: <SettingOutlined />,
|
||||||
icon: <SettingOutlined />,
|
},
|
||||||
},
|
],
|
||||||
]}
|
};
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
const getCronViews = () => {
|
const getCronViews = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -1032,10 +916,18 @@ const Crontab = () => {
|
|||||||
|
|
||||||
const tabClick = (key: string) => {
|
const tabClick = (key: string) => {
|
||||||
const view = enabledCronViews.find((x) => x.id == key);
|
const view = enabledCronViews.find((x) => x.id == key);
|
||||||
|
setSelectedRowIds([]);
|
||||||
setPageConf({ ...pageConf, page: 1 });
|
setPageConf({ ...pageConf, page: 1 });
|
||||||
setViewConf(view ? view : null);
|
setViewConf(view ? view : null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const vComponents = useMemo(() => {
|
||||||
|
return VList({
|
||||||
|
height: tableScrollHeight!,
|
||||||
|
resetTopWhenDataChange: false,
|
||||||
|
});
|
||||||
|
}, [tableScrollHeight]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="ql-container-wrapper crontab-wrapper ql-container-wrapper-has-tab"
|
className="ql-container-wrapper crontab-wrapper ql-container-wrapper-has-tab"
|
||||||
@@ -1066,7 +958,7 @@ const Crontab = () => {
|
|||||||
className={`crontab-view ${moreMenuActive ? 'more-active' : ''}`}
|
className={`crontab-view ${moreMenuActive ? 'more-active' : ''}`}
|
||||||
tabBarExtraContent={
|
tabBarExtraContent={
|
||||||
<Dropdown
|
<Dropdown
|
||||||
overlay={menu}
|
menu={menu}
|
||||||
trigger={['click']}
|
trigger={['click']}
|
||||||
overlayStyle={{ minWidth: 200 }}
|
overlayStyle={{ minWidth: 200 }}
|
||||||
>
|
>
|
||||||
@@ -1081,27 +973,98 @@ const Crontab = () => {
|
|||||||
}
|
}
|
||||||
onTabClick={tabClick}
|
onTabClick={tabClick}
|
||||||
items={[
|
items={[
|
||||||
{
|
...[...enabledCronViews].slice(0, 4).map((x) => ({
|
||||||
key: 'all',
|
|
||||||
label: '全部任务',
|
|
||||||
children: panelContent,
|
|
||||||
},
|
|
||||||
...[...enabledCronViews].slice(0, 2).map((x) => ({
|
|
||||||
key: x.id,
|
key: x.id,
|
||||||
label: x.name,
|
label: x.name,
|
||||||
children: panelContent,
|
|
||||||
})),
|
})),
|
||||||
]}
|
]}
|
||||||
>
|
/>
|
||||||
<Tabs.TabPane tab="全部任务" key="all">
|
<div ref={tableRef}>
|
||||||
{panelContent}
|
{selectedRowIds.length > 0 && (
|
||||||
</Tabs.TabPane>
|
<div style={{ marginBottom: 16 }}>
|
||||||
{[...enabledCronViews].slice(0, 2).map((x) => (
|
<Button
|
||||||
<Tabs.TabPane tab={x.name} key={x.id}>
|
type="primary"
|
||||||
{panelContent}
|
style={{ marginBottom: 5 }}
|
||||||
</Tabs.TabPane>
|
onClick={delCrons}
|
||||||
))}
|
>
|
||||||
</Tabs>
|
批量删除
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => operateCrons(0)}
|
||||||
|
style={{ marginLeft: 8, marginBottom: 5 }}
|
||||||
|
>
|
||||||
|
批量启用
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => operateCrons(1)}
|
||||||
|
style={{ marginLeft: 8, marginRight: 8 }}
|
||||||
|
>
|
||||||
|
批量禁用
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
style={{ marginRight: 8 }}
|
||||||
|
onClick={() => operateCrons(2)}
|
||||||
|
>
|
||||||
|
批量运行
|
||||||
|
</Button>
|
||||||
|
<Button type="primary" onClick={() => operateCrons(3)}>
|
||||||
|
批量停止
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => operateCrons(4)}
|
||||||
|
style={{ marginLeft: 8, marginRight: 8 }}
|
||||||
|
>
|
||||||
|
批量置顶
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => operateCrons(5)}
|
||||||
|
style={{ marginLeft: 8, marginRight: 8 }}
|
||||||
|
>
|
||||||
|
批量取消置顶
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
onClick={() => setIsLabelModalVisible(true)}
|
||||||
|
style={{ marginLeft: 8, marginRight: 8 }}
|
||||||
|
>
|
||||||
|
批量修改标签
|
||||||
|
</Button>
|
||||||
|
<span style={{ marginLeft: 8 }}>
|
||||||
|
已选择
|
||||||
|
<a>{selectedRowIds?.length}</a>项
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<Table
|
||||||
|
columns={columns}
|
||||||
|
pagination={{
|
||||||
|
current: pageConf.page,
|
||||||
|
pageSize: pageConf.size,
|
||||||
|
showSizeChanger: true,
|
||||||
|
simple: isPhone,
|
||||||
|
total,
|
||||||
|
showTotal: (total: number, range: number[]) =>
|
||||||
|
`第 ${range[0]}-${range[1]} 条/总共 ${total} 条`,
|
||||||
|
pageSizeOptions: [10, 20, 50, 100, 200, 500, total || 10000].sort(
|
||||||
|
(a, b) => a - b,
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
dataSource={value}
|
||||||
|
rowKey="id"
|
||||||
|
size="middle"
|
||||||
|
scroll={{ x: 1000, y: tableScrollHeight }}
|
||||||
|
loading={loading}
|
||||||
|
rowSelection={rowSelection}
|
||||||
|
rowClassName={getRowClassName}
|
||||||
|
onChange={onPageChange}
|
||||||
|
components={vComponents}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<CronLogModal
|
<CronLogModal
|
||||||
visible={isLogModalVisible}
|
visible={isLogModalVisible}
|
||||||
handleCancel={() => {
|
handleCancel={() => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { Modal, message, Input, Form, Statistic, Button } from 'antd';
|
import { Modal, message, Input, Form, Statistic, Button } from 'antd';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
CheckCircleOutlined,
|
CheckCircleOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { PageLoading } from '@ant-design/pro-layout';
|
import { PageLoading } from '@ant-design/pro-layout';
|
||||||
|
import { logEnded } from '@/utils';
|
||||||
|
|
||||||
enum CrontabStatus {
|
enum CrontabStatus {
|
||||||
'running',
|
'running',
|
||||||
@@ -33,7 +34,7 @@ const CronLogModal = ({
|
|||||||
const [loading, setLoading] = useState<any>(true);
|
const [loading, setLoading] = useState<any>(true);
|
||||||
const [executing, setExecuting] = useState<any>(true);
|
const [executing, setExecuting] = useState<any>(true);
|
||||||
const [isPhone, setIsPhone] = useState(false);
|
const [isPhone, setIsPhone] = useState(false);
|
||||||
const [theme, setTheme] = useState<string>('');
|
const scrollInfoRef = useRef({ value: 0, down: true });
|
||||||
|
|
||||||
const getCronLog = (isFirst?: boolean) => {
|
const getCronLog = (isFirst?: boolean) => {
|
||||||
if (isFirst) {
|
if (isFirst) {
|
||||||
@@ -44,14 +45,20 @@ const CronLogModal = ({
|
|||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (
|
if (
|
||||||
code === 200 &&
|
code === 200 &&
|
||||||
localStorage.getItem('logCron') === String(cron.id)
|
localStorage.getItem('logCron') === String(cron.id) &&
|
||||||
|
data !== value
|
||||||
) {
|
) {
|
||||||
const log = data as string;
|
const log = data as string;
|
||||||
setValue(log || '暂无日志');
|
setValue(log || '暂无日志');
|
||||||
setExecuting(
|
const hasNext = Boolean(
|
||||||
log && !log.includes('执行结束') && !log.includes('重启面板'),
|
log &&
|
||||||
|
!logEnded(log) &&
|
||||||
|
!log.includes('重启面板') &&
|
||||||
|
!log.includes('任务未运行或运行失败,请尝试手动运行'),
|
||||||
);
|
);
|
||||||
if (log && !log.includes('执行结束') && !log.includes('重启面板')) {
|
setExecuting(hasNext);
|
||||||
|
autoScroll();
|
||||||
|
if (hasNext) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
getCronLog();
|
getCronLog();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
@@ -88,11 +95,33 @@ const CronLogModal = ({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const autoScroll = () => {
|
||||||
|
if (!scrollInfoRef.current.down) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
document
|
||||||
|
.querySelector('#log-flag')!
|
||||||
|
.scrollIntoView({ behavior: 'smooth' });
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
const cancel = () => {
|
const cancel = () => {
|
||||||
localStorage.removeItem('logCron');
|
localStorage.removeItem('logCron');
|
||||||
handleCancel();
|
handleCancel();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleScroll = (e) => {
|
||||||
|
const sTop = e.target.scrollTop;
|
||||||
|
if (scrollInfoRef.current.down) {
|
||||||
|
scrollInfoRef.current = {
|
||||||
|
value: sTop,
|
||||||
|
down: sTop > scrollInfoRef.current.value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const titleElement = () => {
|
const titleElement = () => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -137,23 +166,26 @@ const CronLogModal = ({
|
|||||||
</Button>,
|
</Button>,
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{loading ? (
|
<div onScroll={handleScroll} className="log-container">
|
||||||
<PageLoading />
|
{loading ? (
|
||||||
) : (
|
<PageLoading />
|
||||||
<pre
|
) : (
|
||||||
style={
|
<pre
|
||||||
isPhone
|
style={
|
||||||
? {
|
isPhone
|
||||||
fontFamily: 'Source Code Pro',
|
? {
|
||||||
width: 375,
|
fontFamily: 'Source Code Pro',
|
||||||
zoom: 0.83,
|
width: 375,
|
||||||
}
|
zoom: 0.83,
|
||||||
: {}
|
}
|
||||||
}
|
: {}
|
||||||
>
|
}
|
||||||
{value}
|
>
|
||||||
</pre>
|
{value}
|
||||||
)}
|
</pre>
|
||||||
|
)}
|
||||||
|
<div id="log-flag"></div>
|
||||||
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -74,13 +74,13 @@ const CronModal = ({
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="command"
|
name="command"
|
||||||
label="命令"
|
label="命令/脚本"
|
||||||
rules={[{ required: true, whitespace: true }]}
|
rules={[{ required: true, whitespace: true }]}
|
||||||
>
|
>
|
||||||
<Input.TextArea
|
<Input.TextArea
|
||||||
rows={4}
|
rows={4}
|
||||||
autoSize={true}
|
autoSize={true}
|
||||||
placeholder="请输入要执行的命令"
|
placeholder="支持输入脚本路径/任意系统可执行命令/task 脚本路径"
|
||||||
/>
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
|
|||||||
@@ -12,19 +12,28 @@ import {
|
|||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
|
||||||
|
import IconFont from '@/components/iconfont';
|
||||||
|
import get from 'lodash/get';
|
||||||
|
|
||||||
const PROPERTIES = [
|
const PROPERTIES = [
|
||||||
{ name: '命令', value: 'command' },
|
{ name: '命令', value: 'command' },
|
||||||
{ name: '名称', value: 'name' },
|
{ name: '名称', value: 'name' },
|
||||||
{ name: '定时规则', value: 'schedule' },
|
{ name: '定时规则', value: 'schedule' },
|
||||||
{ name: '状态', value: 'status' },
|
{ name: '状态', value: 'status' },
|
||||||
|
{ name: '标签', value: 'labels' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const EOperation: any = {
|
||||||
|
Reg: '',
|
||||||
|
NotReg: '',
|
||||||
|
In: 'select',
|
||||||
|
Nin: 'select',
|
||||||
|
};
|
||||||
const OPERATIONS = [
|
const OPERATIONS = [
|
||||||
{ name: '包含', value: 'Reg' },
|
{ name: '包含', value: 'Reg' },
|
||||||
{ name: '不包含', value: 'NotReg' },
|
{ name: '不包含', value: 'NotReg' },
|
||||||
{ name: '属于', value: 'In' },
|
{ name: '属于', value: 'In', type: 'select' },
|
||||||
{ name: '不属于', value: 'Nin' },
|
{ name: '不属于', value: 'Nin', type: 'select' },
|
||||||
// { name: '等于', value: 'Eq' },
|
// { name: '等于', value: 'Eq' },
|
||||||
// { name: '不等于', value: 'Ne' },
|
// { name: '不等于', value: 'Ne' },
|
||||||
// { name: '为空', value: 'IsNull' },
|
// { name: '为空', value: 'IsNull' },
|
||||||
@@ -36,11 +45,18 @@ const SORTTYPES = [
|
|||||||
{ name: '倒序', value: 'DESC' },
|
{ name: '倒序', value: 'DESC' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const STATUS = [
|
const STATUS_MAP = {
|
||||||
{ name: '运行中', value: 0 },
|
status: [
|
||||||
{ name: '空闲中', value: 1 },
|
{ name: '运行中', value: 0 },
|
||||||
{ name: '已禁用', value: 2 },
|
{ name: '空闲中', value: 1 },
|
||||||
];
|
{ name: '已禁用', value: 2 },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ViewFilterRelation {
|
||||||
|
'and' = '且',
|
||||||
|
'or' = '或',
|
||||||
|
}
|
||||||
|
|
||||||
const ViewCreateModal = ({
|
const ViewCreateModal = ({
|
||||||
view,
|
view,
|
||||||
@@ -53,10 +69,11 @@ const ViewCreateModal = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [operationMap, setOperationMap] = useState<any>();
|
const [filterRelation, setFilterRelation] = useState<'and' | 'or'>('and');
|
||||||
|
|
||||||
const handleOk = async (values: any) => {
|
const handleOk = async (values: any) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
values.filterRelation = filterRelation;
|
||||||
const method = view ? 'put' : 'post';
|
const method = view ? 'put' : 'post';
|
||||||
try {
|
try {
|
||||||
const { code, data } = await request[method](
|
const { code, data } = await request[method](
|
||||||
@@ -87,12 +104,7 @@ const ViewCreateModal = ({
|
|||||||
}, [view, visible]);
|
}, [view, visible]);
|
||||||
|
|
||||||
const operationElement = (
|
const operationElement = (
|
||||||
<Select
|
<Select style={{ width: 80 }}>
|
||||||
style={{ width: 100 }}
|
|
||||||
onChange={() => {
|
|
||||||
setOperationMap({});
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{OPERATIONS.map((x) => (
|
{OPERATIONS.map((x) => (
|
||||||
<Select.Option key={x.name} value={x.value}>
|
<Select.Option key={x.name} value={x.value}>
|
||||||
{x.name}
|
{x.name}
|
||||||
@@ -123,15 +135,17 @@ const ViewCreateModal = ({
|
|||||||
</Select>
|
</Select>
|
||||||
);
|
);
|
||||||
|
|
||||||
const statusElement = (
|
const statusElement = (property: keyof typeof STATUS_MAP) => {
|
||||||
<Select mode="multiple" allowClear placeholder="请选择状态">
|
return (
|
||||||
{STATUS.map((x) => (
|
<Select mode="tags" allowClear placeholder="输入后回车增加自定义选项">
|
||||||
<Select.Option key={x.name} value={x.value}>
|
{STATUS_MAP[property]?.map((x) => (
|
||||||
{x.name}
|
<Select.Option key={x.name} value={x.value}>
|
||||||
</Select.Option>
|
{x.name}
|
||||||
))}
|
</Select.Option>
|
||||||
</Select>
|
))}
|
||||||
);
|
</Select>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
@@ -164,57 +178,145 @@ const ViewCreateModal = ({
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.List name="filters">
|
<Form.List name="filters">
|
||||||
{(fields, { add, remove }) => (
|
{(fields, { add, remove }) => (
|
||||||
<>
|
<div
|
||||||
{fields.map(({ key, name, ...restField }, index) => (
|
style={{ position: 'relative' }}
|
||||||
<Form.Item
|
className={`view-filters-container ${
|
||||||
label={index === 0 ? '筛选条件' : ''}
|
fields.length > 1 ? 'active' : ''
|
||||||
key={key}
|
}`}
|
||||||
style={{ marginBottom: 0 }}
|
>
|
||||||
required
|
{fields.length > 1 && (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
width: 50,
|
||||||
|
borderRadius: 10,
|
||||||
|
border: '1px solid rgb(190, 220, 255)',
|
||||||
|
borderRight: 'none',
|
||||||
|
height: 56 * (fields.length - 1),
|
||||||
|
top: 46,
|
||||||
|
left: 15,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Space className="view-create-modal-filters" align="baseline">
|
<Button
|
||||||
<Form.Item
|
type="primary"
|
||||||
{...restField}
|
size="small"
|
||||||
name={[name, 'property']}
|
style={{
|
||||||
rules={[{ required: true }]}
|
position: 'absolute',
|
||||||
|
top: '50%',
|
||||||
|
translate: '-50% -50%',
|
||||||
|
padding: '0 0 0 3px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
onClick={() => {
|
||||||
|
setFilterRelation(
|
||||||
|
filterRelation === 'and' ? 'or' : 'and',
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<>
|
||||||
|
<span>{ViewFilterRelation[filterRelation]}</span>
|
||||||
|
<IconFont type="ql-icon-d-caret" />
|
||||||
|
</>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div>
|
||||||
|
{fields.map(({ key, name, ...restField }, index) => (
|
||||||
|
<Form.Item
|
||||||
|
label={index === 0 ? '筛选条件' : ''}
|
||||||
|
key={key}
|
||||||
|
style={{ marginBottom: 0 }}
|
||||||
|
required
|
||||||
|
className="filter-item"
|
||||||
|
>
|
||||||
|
<Space
|
||||||
|
className="view-create-modal-filters"
|
||||||
|
align="baseline"
|
||||||
|
style={
|
||||||
|
fields.length > 1 ? { width: 'calc(100% - 40px)' } : {}
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{propertyElement(PROPERTIES, { width: 120 })}
|
<Form.Item
|
||||||
</Form.Item>
|
{...restField}
|
||||||
<Form.Item
|
name={[name, 'property']}
|
||||||
{...restField}
|
rules={[{ required: true }]}
|
||||||
name={[name, 'operation']}
|
>
|
||||||
rules={[{ required: true }]}
|
{propertyElement(PROPERTIES, { width: 90 })}
|
||||||
>
|
</Form.Item>
|
||||||
{operationElement}
|
<Form.Item
|
||||||
</Form.Item>
|
{...restField}
|
||||||
<Form.Item
|
name={[name, 'operation']}
|
||||||
{...restField}
|
rules={[{ required: true }]}
|
||||||
name={[name, 'value']}
|
>
|
||||||
rules={[{ required: true, message: '请输入内容' }]}
|
{operationElement}
|
||||||
>
|
</Form.Item>
|
||||||
{['In', 'Nin'].includes(
|
<Form.Item
|
||||||
form.getFieldValue(['filters', index, 'operation']),
|
noStyle
|
||||||
) ? (
|
shouldUpdate={(prevValues, nextValues) => {
|
||||||
statusElement
|
const preOperation =
|
||||||
) : (
|
EOperation[
|
||||||
<Input placeholder="请输入内容" />
|
get(prevValues, ['filters', name, 'operation'])
|
||||||
|
];
|
||||||
|
const nextOperation =
|
||||||
|
EOperation[
|
||||||
|
get(nextValues, ['filters', name, 'operation'])
|
||||||
|
];
|
||||||
|
const flag = preOperation !== nextOperation;
|
||||||
|
if (flag) {
|
||||||
|
form.setFieldValue(
|
||||||
|
['filters', name, 'value'],
|
||||||
|
nextOperation === 'select' ? [] : '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{() => {
|
||||||
|
const property = form.getFieldValue([
|
||||||
|
'filters',
|
||||||
|
index,
|
||||||
|
'property',
|
||||||
|
]) as 'status';
|
||||||
|
const operate = form.getFieldValue([
|
||||||
|
'filters',
|
||||||
|
name,
|
||||||
|
'operation',
|
||||||
|
]);
|
||||||
|
return (
|
||||||
|
<Form.Item
|
||||||
|
{...restField}
|
||||||
|
name={[name, 'value']}
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: '请输入内容' },
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{EOperation[operate] === 'select' ? (
|
||||||
|
statusElement(property)
|
||||||
|
) : (
|
||||||
|
<Input placeholder="请输入内容" />
|
||||||
|
)}
|
||||||
|
</Form.Item>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</Form.Item>
|
||||||
|
{index !== 0 && (
|
||||||
|
<MinusCircleOutlined onClick={() => remove(name)} />
|
||||||
)}
|
)}
|
||||||
</Form.Item>
|
</Space>
|
||||||
{index !== 0 && (
|
</Form.Item>
|
||||||
<MinusCircleOutlined onClick={() => remove(name)} />
|
))}
|
||||||
)}
|
<Form.Item>
|
||||||
</Space>
|
<a
|
||||||
|
onClick={() =>
|
||||||
|
add({ property: 'command', operation: 'Reg' })
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<PlusOutlined />
|
||||||
|
新增筛选条件
|
||||||
|
</a>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
))}
|
</div>
|
||||||
<Form.Item>
|
</div>
|
||||||
<a
|
|
||||||
onClick={() => add({ property: 'command', operation: 'Reg' })}
|
|
||||||
>
|
|
||||||
<PlusOutlined />
|
|
||||||
新增筛选条件
|
|
||||||
</a>
|
|
||||||
</Form.Item>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</Form.List>
|
</Form.List>
|
||||||
<Form.List name="sorts">
|
<Form.List name="sorts">
|
||||||
|
|||||||
@@ -81,6 +81,16 @@ const ViewManageModal = ({
|
|||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
|
render: (text) => (
|
||||||
|
<div style={{ textAlign: 'left', paddingLeft: 30 }}>{text}</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
dataIndex: 'type',
|
||||||
|
key: 'type',
|
||||||
|
align: 'center' as const,
|
||||||
|
render: (v) => (v === 1 ? '系统' : '个人'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '显示',
|
title: '显示',
|
||||||
@@ -100,10 +110,10 @@ const ViewManageModal = ({
|
|||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
width: 140,
|
width: 100,
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
render: (text: string, record: any, index: number) => {
|
render: (text: string, record: any, index: number) => {
|
||||||
return (
|
return record.type !== 1 ? (
|
||||||
<Space size="middle">
|
<Space size="middle">
|
||||||
<a onClick={() => editView(record, index)}>
|
<a onClick={() => editView(record, index)}>
|
||||||
<EditOutlined />
|
<EditOutlined />
|
||||||
@@ -112,6 +122,8 @@ const ViewManageModal = ({
|
|||||||
<DeleteOutlined />
|
<DeleteOutlined />
|
||||||
</a>
|
</a>
|
||||||
</Space>
|
</Space>
|
||||||
|
) : (
|
||||||
|
'-'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -155,7 +167,6 @@ const ViewManageModal = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onShowChange = (checked: boolean, record: any, index: number) => {
|
const onShowChange = (checked: boolean, record: any, index: number) => {
|
||||||
console.log(checked);
|
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}crons/views/${checked ? 'enable' : 'disable'}`, {
|
.put(`${config.apiPrefix}crons/views/${checked ? 'enable' : 'disable'}`, {
|
||||||
data: [record.id],
|
data: [record.id],
|
||||||
|
|||||||
@@ -27,10 +27,11 @@ import DependenceModal from './modal';
|
|||||||
import { DndProvider, useDrag, useDrop } from 'react-dnd';
|
import { DndProvider, useDrag, useDrop } from 'react-dnd';
|
||||||
import { HTML5Backend } from 'react-dnd-html5-backend';
|
import { HTML5Backend } from 'react-dnd-html5-backend';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
import { getTableScroll } from '@/utils/index';
|
|
||||||
import DependenceLogModal from './logModal';
|
import DependenceLogModal from './logModal';
|
||||||
import { useOutletContext } from '@umijs/max';
|
import { useOutletContext } from '@umijs/max';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
|
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
||||||
|
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
@@ -164,10 +165,11 @@ const Dependence = () => {
|
|||||||
const [editedDependence, setEditedDependence] = useState();
|
const [editedDependence, setEditedDependence] = useState();
|
||||||
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
||||||
const [searchText, setSearchText] = useState('');
|
const [searchText, setSearchText] = useState('');
|
||||||
const [tableScrollHeight, setTableScrollHeight] = useState<number>();
|
|
||||||
const [logDependence, setLogDependence] = useState<any>();
|
const [logDependence, setLogDependence] = useState<any>();
|
||||||
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
||||||
const [type, setType] = useState('nodejs');
|
const [type, setType] = useState('nodejs');
|
||||||
|
const tableRef = useRef<any>();
|
||||||
|
const tableScrollHeight = useTableScrollHeight(tableRef, 59)
|
||||||
|
|
||||||
const getDependencies = () => {
|
const getDependencies = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -282,16 +284,10 @@ const Dependence = () => {
|
|||||||
|
|
||||||
const onSelectChange = (selectedIds: any[]) => {
|
const onSelectChange = (selectedIds: any[]) => {
|
||||||
setSelectedRowIds(selectedIds);
|
setSelectedRowIds(selectedIds);
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
if (selectedRowIds.length === 0 || selectedIds.length === 0) {
|
|
||||||
setTableScrollHeight(getTableScroll({ extraHeight: 87 }));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const rowSelection = {
|
const rowSelection = {
|
||||||
selectedRowIds,
|
selectedRowKeys: selectedRowIds,
|
||||||
onChange: onSelectChange,
|
onChange: onSelectChange,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -367,12 +363,6 @@ const Dependence = () => {
|
|||||||
getDependencies();
|
getDependencies();
|
||||||
}, [searchText, type]);
|
}, [searchText, type]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setTimeout(() => {
|
|
||||||
setTableScrollHeight(getTableScroll({ extraHeight: 87 }));
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (logDependence) {
|
if (logDependence) {
|
||||||
localStorage.setItem('logDependence', logDependence.id);
|
localStorage.setItem('logDependence', logDependence.id);
|
||||||
@@ -421,53 +411,8 @@ const Dependence = () => {
|
|||||||
}
|
}
|
||||||
}, [socketMessage]);
|
}, [socketMessage]);
|
||||||
|
|
||||||
const panelContent = () => (
|
|
||||||
<>
|
|
||||||
{selectedRowIds.length > 0 && (
|
|
||||||
<div style={{ marginBottom: 16 }}>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
style={{ marginBottom: 5, marginLeft: 8 }}
|
|
||||||
onClick={() => handlereInstallDependencies()}
|
|
||||||
>
|
|
||||||
批量安装
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
style={{ marginBottom: 5, marginLeft: 8 }}
|
|
||||||
onClick={() => delDependencies(false)}
|
|
||||||
>
|
|
||||||
批量删除
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
style={{ marginBottom: 5, marginLeft: 8 }}
|
|
||||||
onClick={() => delDependencies(true)}
|
|
||||||
>
|
|
||||||
批量强制删除
|
|
||||||
</Button>
|
|
||||||
<span style={{ marginLeft: 8 }}>
|
|
||||||
已选择
|
|
||||||
<a>{selectedRowIds?.length}</a>项
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<DndProvider backend={HTML5Backend}>
|
|
||||||
<Table
|
|
||||||
columns={columns}
|
|
||||||
rowSelection={rowSelection}
|
|
||||||
pagination={false}
|
|
||||||
dataSource={value}
|
|
||||||
rowKey="id"
|
|
||||||
size="middle"
|
|
||||||
scroll={{ x: 768, y: tableScrollHeight }}
|
|
||||||
loading={loading}
|
|
||||||
/>
|
|
||||||
</DndProvider>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
const onTabChange = (activeKey: string) => {
|
const onTabChange = (activeKey: string) => {
|
||||||
|
setSelectedRowIds([]);
|
||||||
setType(activeKey);
|
setType(activeKey);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -500,20 +445,60 @@ const Dependence = () => {
|
|||||||
{
|
{
|
||||||
key: 'nodejs',
|
key: 'nodejs',
|
||||||
label: 'NodeJs',
|
label: 'NodeJs',
|
||||||
children: panelContent(),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'python3',
|
key: 'python3',
|
||||||
label: 'Python3',
|
label: 'Python3',
|
||||||
children: panelContent(),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'linux',
|
key: 'linux',
|
||||||
label: 'Linux',
|
label: 'Linux',
|
||||||
children: panelContent(),
|
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
<div ref={tableRef}>
|
||||||
|
{selectedRowIds.length > 0 && (
|
||||||
|
<div style={{ marginBottom: 16 }}>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
style={{ marginBottom: 5, marginLeft: 8 }}
|
||||||
|
onClick={() => handlereInstallDependencies()}
|
||||||
|
>
|
||||||
|
批量安装
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
style={{ marginBottom: 5, marginLeft: 8 }}
|
||||||
|
onClick={() => delDependencies(false)}
|
||||||
|
>
|
||||||
|
批量删除
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
style={{ marginBottom: 5, marginLeft: 8 }}
|
||||||
|
onClick={() => delDependencies(true)}
|
||||||
|
>
|
||||||
|
批量强制删除
|
||||||
|
</Button>
|
||||||
|
<span style={{ marginLeft: 8 }}>
|
||||||
|
已选择
|
||||||
|
<a>{selectedRowIds?.length}</a>项
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<DndProvider backend={HTML5Backend}>
|
||||||
|
<Table
|
||||||
|
columns={columns}
|
||||||
|
rowSelection={rowSelection}
|
||||||
|
pagination={false}
|
||||||
|
dataSource={value}
|
||||||
|
rowKey="id"
|
||||||
|
size="middle"
|
||||||
|
scroll={{ x: 768, y: tableScrollHeight }}
|
||||||
|
loading={loading}
|
||||||
|
/>
|
||||||
|
</DndProvider>
|
||||||
|
</div>
|
||||||
<DependenceModal
|
<DependenceModal
|
||||||
visible={isModalVisible}
|
visible={isModalVisible}
|
||||||
handleCancel={handleCancel}
|
handleCancel={handleCancel}
|
||||||
|
|||||||
Vendored
+6
@@ -5,3 +5,9 @@ tr.drop-over-downward td {
|
|||||||
tr.drop-over-upward td {
|
tr.drop-over-upward td {
|
||||||
border-top: 2px dashed #1890ff;
|
border-top: 2px dashed #1890ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.text-ellipsis {
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+132
-91
@@ -1,4 +1,10 @@
|
|||||||
import React, { useCallback, useRef, useState, useEffect } from 'react';
|
import React, {
|
||||||
|
useCallback,
|
||||||
|
useRef,
|
||||||
|
useState,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
} from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
message,
|
message,
|
||||||
@@ -9,6 +15,8 @@ import {
|
|||||||
Typography,
|
Typography,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Input,
|
Input,
|
||||||
|
UploadProps,
|
||||||
|
Upload,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import {
|
import {
|
||||||
EditOutlined,
|
EditOutlined,
|
||||||
@@ -16,6 +24,7 @@ import {
|
|||||||
SyncOutlined,
|
SyncOutlined,
|
||||||
CheckCircleOutlined,
|
CheckCircleOutlined,
|
||||||
StopOutlined,
|
StopOutlined,
|
||||||
|
UploadOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
@@ -25,11 +34,14 @@ import EditNameModal from './editNameModal';
|
|||||||
import { DndProvider, useDrag, useDrop } from 'react-dnd';
|
import { DndProvider, useDrag, useDrop } from 'react-dnd';
|
||||||
import { HTML5Backend } from 'react-dnd-html5-backend';
|
import { HTML5Backend } from 'react-dnd-html5-backend';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
import { exportJson, getTableScroll } from '@/utils/index';
|
import { exportJson } from '@/utils/index';
|
||||||
import { useOutletContext } from '@umijs/max';
|
import { useOutletContext } from '@umijs/max';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
|
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
||||||
|
import Copy from '../../components/copy';
|
||||||
|
import { VList } from 'virtuallist-antd';
|
||||||
|
|
||||||
const { Text, Paragraph } = Typography;
|
const { Text } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
|
|
||||||
enum Status {
|
enum Status {
|
||||||
@@ -54,50 +66,6 @@ enum OperationPath {
|
|||||||
|
|
||||||
const type = 'DragableBodyRow';
|
const type = 'DragableBodyRow';
|
||||||
|
|
||||||
const DragableBodyRow = ({
|
|
||||||
index,
|
|
||||||
moveRow,
|
|
||||||
className,
|
|
||||||
style,
|
|
||||||
...restProps
|
|
||||||
}: any) => {
|
|
||||||
const ref = useRef();
|
|
||||||
const [{ isOver, dropClassName }, drop] = useDrop({
|
|
||||||
accept: type,
|
|
||||||
collect: (monitor) => {
|
|
||||||
const { index: dragIndex } = (monitor.getItem() as any) || {};
|
|
||||||
if (dragIndex === index) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
isOver: monitor.isOver(),
|
|
||||||
dropClassName:
|
|
||||||
dragIndex < index ? ' drop-over-downward' : ' drop-over-upward',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
drop: (item: any) => {
|
|
||||||
moveRow(item.index, index);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const [, drag] = useDrag({
|
|
||||||
type,
|
|
||||||
item: { index },
|
|
||||||
collect: (monitor) => ({
|
|
||||||
isDragging: monitor.isDragging(),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
drop(drag(ref));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<tr
|
|
||||||
ref={ref}
|
|
||||||
className={`${className}${isOver ? dropClassName : ''}`}
|
|
||||||
style={{ cursor: 'move', ...style }}
|
|
||||||
{...restProps}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const Env = () => {
|
const Env = () => {
|
||||||
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
const { headerStyle, isPhone, theme } = useOutletContext<SharedContext>();
|
||||||
const columns: any = [
|
const columns: any = [
|
||||||
@@ -124,16 +92,12 @@ const Env = () => {
|
|||||||
width: '35%',
|
width: '35%',
|
||||||
render: (text: string, record: any) => {
|
render: (text: string, record: any) => {
|
||||||
return (
|
return (
|
||||||
<Paragraph
|
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||||
style={{
|
<Tooltip title={text} placement="topLeft">
|
||||||
wordBreak: 'break-all',
|
<div className="text-ellipsis">{text}</div>
|
||||||
marginBottom: 0,
|
</Tooltip>
|
||||||
textAlign: 'left',
|
<Copy text={text} />
|
||||||
}}
|
</div>
|
||||||
ellipsis={{ tooltip: text, rows: 2 }}
|
|
||||||
>
|
|
||||||
{text}
|
|
||||||
</Paragraph>
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -142,6 +106,13 @@ const Env = () => {
|
|||||||
dataIndex: 'remarks',
|
dataIndex: 'remarks',
|
||||||
key: 'remarks',
|
key: 'remarks',
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
|
render: (text: string, record: any) => {
|
||||||
|
return (
|
||||||
|
<Tooltip title={text} placement="topLeft">
|
||||||
|
<div className="text-ellipsis">{text}</div>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '更新时间',
|
title: '更新时间',
|
||||||
@@ -249,7 +220,9 @@ const Env = () => {
|
|||||||
const [editedEnv, setEditedEnv] = useState();
|
const [editedEnv, setEditedEnv] = useState();
|
||||||
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
||||||
const [searchText, setSearchText] = useState('');
|
const [searchText, setSearchText] = useState('');
|
||||||
const [tableScrollHeight, setTableScrollHeight] = useState<number>();
|
const [importLoading, setImportLoading] = useState(false);
|
||||||
|
const tableRef = useRef<any>();
|
||||||
|
const tableScrollHeight = useTableScrollHeight(tableRef, 59);
|
||||||
|
|
||||||
const getEnvs = () => {
|
const getEnvs = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -350,7 +323,7 @@ const Env = () => {
|
|||||||
|
|
||||||
const handleCancel = (env?: any[]) => {
|
const handleCancel = (env?: any[]) => {
|
||||||
setIsModalVisible(false);
|
setIsModalVisible(false);
|
||||||
env && handleEnv(env);
|
getEnvs();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEditNameCancel = (env?: any[]) => {
|
const handleEditNameCancel = (env?: any[]) => {
|
||||||
@@ -358,28 +331,71 @@ const Env = () => {
|
|||||||
getEnvs();
|
getEnvs();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleEnv = (env: any) => {
|
const vComponents = useMemo(() => {
|
||||||
const result = [...value];
|
return VList({
|
||||||
const index = value.findIndex((x) => x.id === env.id);
|
height: tableScrollHeight!,
|
||||||
if (index === -1) {
|
resetTopWhenDataChange: false,
|
||||||
env = Array.isArray(env) ? env : [env];
|
});
|
||||||
result.push(...env);
|
}, [tableScrollHeight]);
|
||||||
} else {
|
|
||||||
result.splice(index, 1, {
|
const DragableBodyRow = (props: any) => {
|
||||||
...env,
|
const { index, moveRow, className, style, ...restProps } = props;
|
||||||
});
|
const ref = useRef();
|
||||||
}
|
const [{ isOver, dropClassName }, drop] = useDrop({
|
||||||
setValue(result);
|
accept: type,
|
||||||
|
collect: (monitor) => {
|
||||||
|
const { index: dragIndex } = (monitor.getItem() as any) || {};
|
||||||
|
if (dragIndex === index) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
isOver: monitor.isOver(),
|
||||||
|
dropClassName:
|
||||||
|
dragIndex < index ? ' drop-over-downward' : ' drop-over-upward',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
drop: (item: any) => {
|
||||||
|
moveRow(item.index, index);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const [, drag] = useDrag({
|
||||||
|
type,
|
||||||
|
item: { index },
|
||||||
|
collect: (monitor) => ({
|
||||||
|
isDragging: monitor.isDragging(),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
drop(drag(ref));
|
||||||
|
}, [drag, drop]);
|
||||||
|
|
||||||
|
const components = useMemo(() => vComponents.body.row, []);
|
||||||
|
|
||||||
|
const tempProps = useMemo(() => {
|
||||||
|
return {
|
||||||
|
ref: ref,
|
||||||
|
className: `${className}${isOver ? dropClassName : ''}`,
|
||||||
|
style: { cursor: 'move', ...style },
|
||||||
|
...restProps,
|
||||||
|
};
|
||||||
|
}, [className, dropClassName, restProps, style, isOver]);
|
||||||
|
|
||||||
|
return <> {components(tempProps, ref)} </>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const components = {
|
const components = useMemo(() => {
|
||||||
body: {
|
return {
|
||||||
row: DragableBodyRow,
|
...vComponents,
|
||||||
},
|
body: {
|
||||||
};
|
...vComponents.body,
|
||||||
|
row: DragableBodyRow,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [vComponents]);
|
||||||
|
|
||||||
const moveRow = useCallback(
|
const moveRow = useCallback(
|
||||||
(dragIndex, hoverIndex) => {
|
(dragIndex: number, hoverIndex: number) => {
|
||||||
if (dragIndex === hoverIndex) {
|
if (dragIndex === hoverIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -402,16 +418,10 @@ const Env = () => {
|
|||||||
|
|
||||||
const onSelectChange = (selectedIds: any[]) => {
|
const onSelectChange = (selectedIds: any[]) => {
|
||||||
setSelectedRowIds(selectedIds);
|
setSelectedRowIds(selectedIds);
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
if (selectedRowIds.length === 0 || selectedIds.length === 0) {
|
|
||||||
setTableScrollHeight(getTableScroll({ extraHeight: 87 }));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const rowSelection = {
|
const rowSelection = {
|
||||||
selectedRowIds,
|
selectedRowKeys: selectedRowIds,
|
||||||
onChange: onSelectChange,
|
onChange: onSelectChange,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -472,16 +482,37 @@ const Env = () => {
|
|||||||
setSearchText(value.trim());
|
setSearchText(value.trim());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const uploadProps: UploadProps = {
|
||||||
|
accept: 'application/json',
|
||||||
|
beforeUpload: async (file) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('env', file);
|
||||||
|
setImportLoading(true);
|
||||||
|
try {
|
||||||
|
const { code, data } = await request.post(
|
||||||
|
`${config.apiPrefix}envs/upload`,
|
||||||
|
{
|
||||||
|
data: formData,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (code === 200) {
|
||||||
|
message.success(`成功上传${data.length}个环境变量`);
|
||||||
|
getEnvs();
|
||||||
|
}
|
||||||
|
setImportLoading(false);
|
||||||
|
} catch (error: any) {
|
||||||
|
setImportLoading(false);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
fileList: [],
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getEnvs();
|
getEnvs();
|
||||||
}, [searchText]);
|
}, [searchText]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setTimeout(() => {
|
|
||||||
setTableScrollHeight(getTableScroll({ extraHeight: 87 }));
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="ql-container-wrapper env-wrapper"
|
className="ql-container-wrapper env-wrapper"
|
||||||
@@ -494,6 +525,15 @@ const Env = () => {
|
|||||||
loading={loading}
|
loading={loading}
|
||||||
onSearch={onSearch}
|
onSearch={onSearch}
|
||||||
/>,
|
/>,
|
||||||
|
<Upload {...uploadProps}>
|
||||||
|
<Button
|
||||||
|
type="primary"
|
||||||
|
icon={<UploadOutlined />}
|
||||||
|
loading={importLoading}
|
||||||
|
>
|
||||||
|
导入
|
||||||
|
</Button>
|
||||||
|
</Upload>,
|
||||||
<Button key="2" type="primary" onClick={() => addEnv()}>
|
<Button key="2" type="primary" onClick={() => addEnv()}>
|
||||||
新建变量
|
新建变量
|
||||||
</Button>,
|
</Button>,
|
||||||
@@ -547,6 +587,7 @@ const Env = () => {
|
|||||||
)}
|
)}
|
||||||
<DndProvider backend={HTML5Backend}>
|
<DndProvider backend={HTML5Backend}>
|
||||||
<Table
|
<Table
|
||||||
|
ref={tableRef}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
rowSelection={rowSelection}
|
rowSelection={rowSelection}
|
||||||
pagination={false}
|
pagination={false}
|
||||||
@@ -556,7 +597,7 @@ const Env = () => {
|
|||||||
scroll={{ x: 1000, y: tableScrollHeight }}
|
scroll={{ x: 1000, y: tableScrollHeight }}
|
||||||
components={components}
|
components={components}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
onRow={(record: any, index: number) => {
|
onRow={(record: any, index: number | undefined) => {
|
||||||
return {
|
return {
|
||||||
index,
|
index,
|
||||||
moveRow,
|
moveRow,
|
||||||
|
|||||||
@@ -9,20 +9,37 @@ import './index.less';
|
|||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
|
|
||||||
const Error = () => {
|
const Error = () => {
|
||||||
const { user, theme } = useOutletContext<SharedContext>();
|
const { user, theme, reloadUser } = useOutletContext<SharedContext>();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [data, setData] = useState('暂无日志');
|
const [data, setData] = useState('暂无日志');
|
||||||
|
|
||||||
const getLog = () => {
|
const getTimes = () => {
|
||||||
setLoading(true);
|
return parseInt(localStorage.getItem('error_retry_times') || '0', 10);
|
||||||
|
};
|
||||||
|
|
||||||
|
let times = getTimes();
|
||||||
|
|
||||||
|
const getLog = (needLoading: boolean = true) => {
|
||||||
|
needLoading && setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}public/panel/log`)
|
.get(`${config.apiPrefix}public/panel/log`)
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
setData(data);
|
setData(data);
|
||||||
|
if (!data) {
|
||||||
|
times = getTimes();
|
||||||
|
if (times > 5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localStorage.setItem('error_retry_times', `${times + 1}`);
|
||||||
|
setTimeout(() => {
|
||||||
|
reloadUser();
|
||||||
|
getLog(false);
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => needLoading && setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -39,7 +56,7 @@ const Error = () => {
|
|||||||
<div className="error-wrapper">
|
<div className="error-wrapper">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<PageLoading />
|
<PageLoading />
|
||||||
) : (
|
) : data ? (
|
||||||
<Terminal
|
<Terminal
|
||||||
name="服务错误"
|
name="服务错误"
|
||||||
colorMode={theme === 'vs-dark' ? ColorMode.Dark : ColorMode.Light}
|
colorMode={theme === 'vs-dark' ? ColorMode.Dark : ColorMode.Light}
|
||||||
@@ -55,6 +72,10 @@ const Error = () => {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
) : times > 5 ? (
|
||||||
|
<>服务启动超时,请手动进入容器执行 ql -l check 后刷新再试</>
|
||||||
|
) : (
|
||||||
|
<PageLoading tip="启动中,请稍后..." />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ const Initialization = () => {
|
|||||||
<img
|
<img
|
||||||
alt="logo"
|
alt="logo"
|
||||||
className={styles.logo}
|
className={styles.logo}
|
||||||
src="http://qn.whyour.cn/logo.png"
|
src="https://qn.whyour.cn/logo.png"
|
||||||
/>
|
/>
|
||||||
<span className={styles.title}>初始化配置</span>
|
<span className={styles.title}>初始化配置</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ import { useOutletContext } from '@umijs/max';
|
|||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
import { DeleteOutlined } from '@ant-design/icons';
|
import { DeleteOutlined } from '@ant-design/icons';
|
||||||
import { depthFirstSearch } from '@/utils';
|
import { depthFirstSearch } from '@/utils';
|
||||||
import { debounce, uniq } from 'lodash';
|
import debounce from 'lodash/debounce';
|
||||||
|
import uniq from 'lodash/uniq';
|
||||||
import useFilterTreeData from '@/hooks/useFilterTreeData';
|
import useFilterTreeData from '@/hooks/useFilterTreeData';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
@@ -185,6 +186,7 @@ const Log = () => {
|
|||||||
isPhone
|
isPhone
|
||||||
? [
|
? [
|
||||||
<TreeSelect
|
<TreeSelect
|
||||||
|
treeExpandAction="click"
|
||||||
className="log-select"
|
className="log-select"
|
||||||
value={select}
|
value={select}
|
||||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ const Login = () => {
|
|||||||
<img
|
<img
|
||||||
alt="logo"
|
alt="logo"
|
||||||
className={styles.logo}
|
className={styles.logo}
|
||||||
src="http://qn.whyour.cn/logo.png"
|
src="https://qn.whyour.cn/logo.png"
|
||||||
/>
|
/>
|
||||||
<span className={styles.title}>
|
<span className={styles.title}>
|
||||||
{twoFactor ? '两步验证' : config.siteName}
|
{twoFactor ? '两步验证' : config.siteName}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import Editor from '@monaco-editor/react';
|
|||||||
import SaveModal from './saveModal';
|
import SaveModal from './saveModal';
|
||||||
import SettingModal from './setting';
|
import SettingModal from './setting';
|
||||||
import { useTheme } from '@/utils/hooks';
|
import { useTheme } from '@/utils/hooks';
|
||||||
|
import { logEnded } from '@/utils';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
const LangMap: any = {
|
const LangMap: any = {
|
||||||
@@ -48,6 +49,7 @@ const EditModal = ({
|
|||||||
const { theme } = useTheme();
|
const { theme } = useTheme();
|
||||||
const editorRef = useRef<any>(null);
|
const editorRef = useRef<any>(null);
|
||||||
const [isRunning, setIsRunning] = useState(false);
|
const [isRunning, setIsRunning] = useState(false);
|
||||||
|
const [currentPid, setCurrentPid] = useState(null);
|
||||||
|
|
||||||
const cancel = () => {
|
const cancel = () => {
|
||||||
handleCancel();
|
handleCancel();
|
||||||
@@ -57,6 +59,11 @@ const EditModal = ({
|
|||||||
if (node.key === selectedKey || !value) {
|
if (node.key === selectedKey || !value) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.type === 'directory') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const newMode = LangMap[value.slice(-3)] || '';
|
const newMode = LangMap[value.slice(-3)] || '';
|
||||||
setCNode(node);
|
setCNode(node);
|
||||||
setLanguage(newMode);
|
setLanguage(newMode);
|
||||||
@@ -88,21 +95,21 @@ const EditModal = ({
|
|||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
setIsRunning(true);
|
setIsRunning(true);
|
||||||
|
setCurrentPid(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
if (!cNode || !cNode.title) {
|
if (!cNode || !cNode.title || !currentPid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const content = editorRef.current.getValue().replace(/\r\n/g, '\n');
|
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}scripts/stop`, {
|
.put(`${config.apiPrefix}scripts/stop`, {
|
||||||
data: {
|
data: {
|
||||||
filename: cNode.title,
|
filename: cNode.title,
|
||||||
path: cNode.parent || '',
|
path: cNode.parent || '',
|
||||||
content,
|
pid: currentPid,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
@@ -123,7 +130,7 @@ const EditModal = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_message.includes('执行结束')) {
|
if (logEnded(_message)) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setIsRunning(false);
|
setIsRunning(false);
|
||||||
}, 300);
|
}, 300);
|
||||||
@@ -136,10 +143,13 @@ const EditModal = ({
|
|||||||
}, [socketMessage]);
|
}, [socketMessage]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
setLog('');
|
||||||
if (currentNode) {
|
if (currentNode) {
|
||||||
setCNode(currentNode);
|
setCNode(currentNode);
|
||||||
setValue(content as string);
|
setValue(content as string);
|
||||||
setSelectedKey(currentNode.key);
|
setSelectedKey(currentNode.key);
|
||||||
|
const newMode = LangMap[currentNode.title.slice(-3)] || '';
|
||||||
|
setLanguage(newMode);
|
||||||
}
|
}
|
||||||
}, [content, currentNode]);
|
}, [content, currentNode]);
|
||||||
|
|
||||||
@@ -150,6 +160,7 @@ const EditModal = ({
|
|||||||
title={
|
title={
|
||||||
<>
|
<>
|
||||||
<TreeSelect
|
<TreeSelect
|
||||||
|
treeExpandAction="click"
|
||||||
style={{ marginRight: 8, width: 150 }}
|
style={{ marginRight: 8, width: 150 }}
|
||||||
value={selectedKey}
|
value={selectedKey}
|
||||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||||
@@ -243,7 +254,14 @@ const EditModal = ({
|
|||||||
editorRef.current = editor;
|
editorRef.current = editor;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<pre style={{ height: '100%', whiteSpace: 'break-spaces' }}>{log}</pre>
|
<pre
|
||||||
|
style={{
|
||||||
|
height: '100%',
|
||||||
|
padding: '0 15px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{log}
|
||||||
|
</pre>
|
||||||
</SplitPane>
|
</SplitPane>
|
||||||
<SaveModal
|
<SaveModal
|
||||||
visible={saveModalVisible}
|
visible={saveModalVisible}
|
||||||
@@ -254,7 +272,7 @@ const EditModal = ({
|
|||||||
content:
|
content:
|
||||||
editorRef.current &&
|
editorRef.current &&
|
||||||
editorRef.current.getValue().replace(/\r\n/g, '\n'),
|
editorRef.current.getValue().replace(/\r\n/g, '\n'),
|
||||||
filename: cNode?.title,
|
...cNode,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<SettingModal
|
<SettingModal
|
||||||
|
|||||||
+86
-44
@@ -11,6 +11,7 @@ import {
|
|||||||
Dropdown,
|
Dropdown,
|
||||||
Menu,
|
Menu,
|
||||||
Empty,
|
Empty,
|
||||||
|
MenuProps,
|
||||||
} from 'antd';
|
} from 'antd';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
@@ -35,10 +36,12 @@ import EditScriptNameModal from './editNameModal';
|
|||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
import { history, useOutletContext, useLocation } from '@umijs/max';
|
import { history, useOutletContext, useLocation } from '@umijs/max';
|
||||||
import { parse } from 'query-string';
|
import { parse } from 'query-string';
|
||||||
import { depthFirstSearch } from '@/utils';
|
import { depthFirstSearch, findNode } from '@/utils';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
import useFilterTreeData from '@/hooks/useFilterTreeData';
|
import useFilterTreeData from '@/hooks/useFilterTreeData';
|
||||||
import { uniq } from 'lodash';
|
import uniq from 'lodash/uniq';
|
||||||
|
import IconFont from '@/components/iconfont';
|
||||||
|
import RenameModal from './renameModal';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
@@ -64,25 +67,32 @@ const Script = () => {
|
|||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const editorRef = useRef<any>(null);
|
const editorRef = useRef<any>(null);
|
||||||
const [isAddFileModalVisible, setIsAddFileModalVisible] = useState(false);
|
const [isAddFileModalVisible, setIsAddFileModalVisible] = useState(false);
|
||||||
|
const [isRenameFileModalVisible, setIsRenameFileModalVisible] =
|
||||||
|
useState(false);
|
||||||
const [currentNode, setCurrentNode] = useState<any>();
|
const [currentNode, setCurrentNode] = useState<any>();
|
||||||
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
const [expandedKeys, setExpandedKeys] = useState<string[]>([]);
|
||||||
|
|
||||||
const getScripts = () => {
|
const getScripts = (needLoading: boolean = true) => {
|
||||||
setLoading(true);
|
needLoading && setLoading(true);
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}scripts`)
|
.get(`${config.apiPrefix}scripts`)
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
setData(data);
|
setData(data);
|
||||||
initGetScript();
|
initState();
|
||||||
|
initGetScript(data);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => needLoading && setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDetail = (node: any) => {
|
const getDetail = (node: any) => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`)
|
.get(
|
||||||
|
`${config.apiPrefix}scripts/${encodeURIComponent(node.title)}?path=${
|
||||||
|
node.parent || ''
|
||||||
|
}`,
|
||||||
|
)
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
setValue(data);
|
setValue(data);
|
||||||
@@ -90,7 +100,7 @@ const Script = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const initGetScript = () => {
|
const initGetScript = (_data: any) => {
|
||||||
const { p, s } = parse(history.location.search);
|
const { p, s } = parse(history.location.search);
|
||||||
if (s) {
|
if (s) {
|
||||||
const vkey = `${p}/${s}`;
|
const vkey = `${p}/${s}`;
|
||||||
@@ -101,8 +111,11 @@ const Script = () => {
|
|||||||
parent: p,
|
parent: p,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
setExpandedKeys([p]);
|
const item = findNode(_data, (c) => c.key === obj.node.key);
|
||||||
onTreeSelect([vkey], obj);
|
if (item) {
|
||||||
|
setExpandedKeys([p as string]);
|
||||||
|
onTreeSelect([vkey], obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -283,6 +296,15 @@ const Script = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const renameFile = () => {
|
||||||
|
setIsRenameFileModalVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRenameFileCancel = () => {
|
||||||
|
setIsRenameFileModalVisible(false);
|
||||||
|
getScripts(false);
|
||||||
|
};
|
||||||
|
|
||||||
const addFile = () => {
|
const addFile = () => {
|
||||||
setIsAddFileModalVisible(true);
|
setIsAddFileModalVisible(true);
|
||||||
};
|
};
|
||||||
@@ -368,7 +390,7 @@ const Script = () => {
|
|||||||
|
|
||||||
const menuAction = (key: string | number) => {
|
const menuAction = (key: string | number) => {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'save':
|
case 'add':
|
||||||
addFile();
|
addFile();
|
||||||
break;
|
break;
|
||||||
case 'edit':
|
case 'edit':
|
||||||
@@ -377,45 +399,52 @@ const Script = () => {
|
|||||||
case 'delete':
|
case 'delete':
|
||||||
deleteFile();
|
deleteFile();
|
||||||
break;
|
break;
|
||||||
|
case 'rename':
|
||||||
|
renameFile();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const menu = isEditing ? (
|
const menu: MenuProps = isEditing
|
||||||
<Menu
|
? {
|
||||||
items={[
|
items: [
|
||||||
{ label: '保存', key: 'save', icon: <PlusOutlined /> },
|
{ label: '保存', key: 'save', icon: <PlusOutlined /> },
|
||||||
{ label: '退出编辑', key: 'exit', icon: <EditOutlined /> },
|
{ label: '退出编辑', key: 'exit', icon: <EditOutlined /> },
|
||||||
]}
|
],
|
||||||
onClick={({ key, domEvent }) => {
|
onClick: ({ key, domEvent }) => {
|
||||||
domEvent.stopPropagation();
|
domEvent.stopPropagation();
|
||||||
action(key);
|
action(key);
|
||||||
}}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Menu
|
|
||||||
items={[
|
|
||||||
{ label: '新建', key: 'add', icon: <PlusOutlined /> },
|
|
||||||
{
|
|
||||||
label: '编辑',
|
|
||||||
key: 'edit',
|
|
||||||
icon: <EditOutlined />,
|
|
||||||
disabled: !select,
|
|
||||||
},
|
},
|
||||||
{
|
}
|
||||||
label: '删除',
|
: {
|
||||||
key: 'delete',
|
items: [
|
||||||
icon: <DeleteOutlined />,
|
{ label: '新建', key: 'add', icon: <PlusOutlined /> },
|
||||||
disabled: !select,
|
{
|
||||||
|
label: '编辑',
|
||||||
|
key: 'edit',
|
||||||
|
icon: <EditOutlined />,
|
||||||
|
disabled: !select,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '重命名',
|
||||||
|
key: 'rename',
|
||||||
|
icon: <IconFont type="ql-icon-rename" />,
|
||||||
|
disabled: !select,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '删除',
|
||||||
|
key: 'delete',
|
||||||
|
icon: <DeleteOutlined />,
|
||||||
|
disabled: !select,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
onClick: ({ key, domEvent }) => {
|
||||||
|
domEvent.stopPropagation();
|
||||||
|
menuAction(key);
|
||||||
},
|
},
|
||||||
]}
|
};
|
||||||
onClick={({ key, domEvent }) => {
|
|
||||||
domEvent.stopPropagation();
|
|
||||||
menuAction(key);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer
|
<PageContainer
|
||||||
@@ -438,7 +467,7 @@ const Script = () => {
|
|||||||
allowClear
|
allowClear
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
/>,
|
/>,
|
||||||
<Dropdown overlay={menu} trigger={['click']}>
|
<Dropdown menu={menu} trigger={['click']}>
|
||||||
<Button type="primary" icon={<EllipsisOutlined />} />
|
<Button type="primary" icon={<EllipsisOutlined />} />
|
||||||
</Dropdown>,
|
</Dropdown>,
|
||||||
]
|
]
|
||||||
@@ -467,6 +496,14 @@ const Script = () => {
|
|||||||
icon={<EditOutlined />}
|
icon={<EditOutlined />}
|
||||||
/>
|
/>
|
||||||
</Tooltip>,
|
</Tooltip>,
|
||||||
|
<Tooltip title="重命名">
|
||||||
|
<Button
|
||||||
|
disabled={!select}
|
||||||
|
type="primary"
|
||||||
|
onClick={renameFile}
|
||||||
|
icon={<IconFont type="ql-icon-rename" />}
|
||||||
|
/>
|
||||||
|
</Tooltip>,
|
||||||
<Tooltip title="删除">
|
<Tooltip title="删除">
|
||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
@@ -581,6 +618,11 @@ const Script = () => {
|
|||||||
treeData={data}
|
treeData={data}
|
||||||
handleCancel={addFileModalClose}
|
handleCancel={addFileModalClose}
|
||||||
/>
|
/>
|
||||||
|
<RenameModal
|
||||||
|
visible={isRenameFileModalVisible}
|
||||||
|
handleCancel={handleRenameFileCancel}
|
||||||
|
currentNode={currentNode}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { Modal, message, Input, Form } from 'antd';
|
||||||
|
import { request } from '@/utils/http';
|
||||||
|
import config from '@/utils/config';
|
||||||
|
|
||||||
|
const RenameModal = ({
|
||||||
|
currentNode,
|
||||||
|
handleCancel,
|
||||||
|
visible,
|
||||||
|
}: {
|
||||||
|
currentNode?: any;
|
||||||
|
visible: boolean;
|
||||||
|
handleCancel: () => void;
|
||||||
|
}) => {
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const handleOk = async (values: any) => {
|
||||||
|
setLoading(true);
|
||||||
|
try {
|
||||||
|
const { code, data } = await request.put(
|
||||||
|
`${config.apiPrefix}scripts/rename`,
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
filename: currentNode.title,
|
||||||
|
path: currentNode.parent || '',
|
||||||
|
newFilename: values.name,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (code === 200) {
|
||||||
|
message.success('更新名称成功');
|
||||||
|
handleCancel();
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
} catch (error) {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
form.resetFields();
|
||||||
|
}, [currentNode, visible]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
title="重命名"
|
||||||
|
open={visible}
|
||||||
|
forceRender
|
||||||
|
centered
|
||||||
|
maskClosable={false}
|
||||||
|
onOk={() => {
|
||||||
|
form
|
||||||
|
.validateFields()
|
||||||
|
.then((values) => {
|
||||||
|
handleOk(values);
|
||||||
|
})
|
||||||
|
.catch((info) => {
|
||||||
|
console.log('Validate Failed:', info);
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
onCancel={() => handleCancel()}
|
||||||
|
confirmLoading={loading}
|
||||||
|
>
|
||||||
|
<Form form={form} layout="vertical" name="edit_name_modal">
|
||||||
|
<Form.Item
|
||||||
|
name="name"
|
||||||
|
rules={[{ required: true, message: '请输入新名称' }]}
|
||||||
|
>
|
||||||
|
<Input placeholder="请输入新名称" />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RenameModal;
|
||||||
@@ -17,7 +17,7 @@ const SaveModal = ({
|
|||||||
|
|
||||||
const handleOk = async (values: any) => {
|
const handleOk = async (values: any) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const payload = { ...file, ...values, originFilename: file.filename };
|
const payload = { ...file, ...values, originFilename: file.title };
|
||||||
request
|
request
|
||||||
.post(`${config.apiPrefix}scripts`, {
|
.post(`${config.apiPrefix}scripts`, {
|
||||||
data: payload,
|
data: payload,
|
||||||
@@ -60,7 +60,7 @@ const SaveModal = ({
|
|||||||
form={form}
|
form={form}
|
||||||
layout="vertical"
|
layout="vertical"
|
||||||
name="script_modal"
|
name="script_modal"
|
||||||
initialValues={file}
|
initialValues={{ filename: file?.title, path: file?.parent || '' }}
|
||||||
>
|
>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
name="filename"
|
name="filename"
|
||||||
|
|||||||
@@ -1,16 +1,23 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Typography, Input, Form, Button, message } from 'antd';
|
import { Typography, Input, Form, Button, message, Descriptions } from 'antd';
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
|
import { SharedContext } from '@/layouts';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
const { Link } = Typography;
|
const { Link } = Typography;
|
||||||
|
|
||||||
const About = () => {
|
enum TVersion {
|
||||||
|
'develop' = '开发版',
|
||||||
|
'master' = '正式版',
|
||||||
|
}
|
||||||
|
|
||||||
|
const About = ({ systemInfo }: { systemInfo: SharedContext['systemInfo'] }) => {
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<img
|
<img
|
||||||
alt="logo"
|
alt="logo"
|
||||||
style={{ width: 140, marginRight: 20 }}
|
style={{ width: 140, marginRight: 20 }}
|
||||||
src="http://qn.whyour.cn/logo.png"
|
src="https://qn.whyour.cn/logo.png"
|
||||||
/>
|
/>
|
||||||
<div className={styles.right}>
|
<div className={styles.right}>
|
||||||
<span className={styles.title}>青龙</span>
|
<span className={styles.title}>青龙</span>
|
||||||
@@ -19,6 +26,27 @@ const About = () => {
|
|||||||
task management panel that supports typescript, javaScript, python3,
|
task management panel that supports typescript, javaScript, python3,
|
||||||
and shell.)
|
and shell.)
|
||||||
</span>
|
</span>
|
||||||
|
<Descriptions>
|
||||||
|
<Descriptions.Item label="版本" span={3}>
|
||||||
|
{TVersion[systemInfo.branch]} v{systemInfo.version}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="更新时间" span={3}>
|
||||||
|
{dayjs(systemInfo.lastCommitTime * 1000).format(
|
||||||
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
|
)}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="更新ID" span={3}>
|
||||||
|
{systemInfo.lastCommitId}
|
||||||
|
</Descriptions.Item>
|
||||||
|
<Descriptions.Item label="更新日志" span={3}>
|
||||||
|
<Link
|
||||||
|
href={`https://qn.whyour.cn/version.yaml?t=${Date.now()}`}
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
查看
|
||||||
|
</Link>
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
<div>
|
<div>
|
||||||
<Link
|
<Link
|
||||||
href="https://github.com/whyour/qinglong"
|
href="https://github.com/whyour/qinglong"
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ import React, { useEffect, useState, useRef } from 'react';
|
|||||||
import { Statistic, Modal, Tag, Button, Spin, message } from 'antd';
|
import { Statistic, Modal, Tag, Button, Spin, message } from 'antd';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { version } from '../../version';
|
|
||||||
|
|
||||||
const { Countdown } = Statistic;
|
const { Countdown } = Statistic;
|
||||||
|
|
||||||
const CheckUpdate = ({ socketMessage }: any) => {
|
const CheckUpdate = ({ socketMessage, systemInfo }: any) => {
|
||||||
const [updateLoading, setUpdateLoading] = useState(false);
|
const [updateLoading, setUpdateLoading] = useState(false);
|
||||||
const [value, setValue] = useState('');
|
const [value, setValue] = useState('');
|
||||||
const modalRef = useRef<any>();
|
const modalRef = useRef<any>();
|
||||||
@@ -23,7 +22,7 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
if (data.hasNewVersion) {
|
if (data.hasNewVersion) {
|
||||||
showConfirmUpdateModal(data);
|
showConfirmUpdateModal(data);
|
||||||
} else {
|
} else {
|
||||||
showForceUpdateModal();
|
showForceUpdateModal(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -36,7 +35,7 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const showForceUpdateModal = () => {
|
const showForceUpdateModal = (data: any) => {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
width: 500,
|
width: 500,
|
||||||
title: '更新',
|
title: '更新',
|
||||||
@@ -44,7 +43,7 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
<>
|
<>
|
||||||
<div>已经是最新版了!</div>
|
<div>已经是最新版了!</div>
|
||||||
<div style={{ fontSize: 12, fontWeight: 400, marginTop: 5 }}>
|
<div style={{ fontSize: 12, fontWeight: 400, marginTop: 5 }}>
|
||||||
青龙 {version} 是目前检测到的最新可用版本了。
|
青龙 {data.lastVersion} 是目前检测到的最新可用版本了。
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
@@ -70,16 +69,13 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
<>
|
<>
|
||||||
<div>更新可用</div>
|
<div>更新可用</div>
|
||||||
<div style={{ fontSize: 12, fontWeight: 400, marginTop: 5 }}>
|
<div style={{ fontSize: 12, fontWeight: 400, marginTop: 5 }}>
|
||||||
新版本{lastVersion}可用。你使用的版本为{version}。
|
新版本 {lastVersion} 可用,你使用的版本为 {systemInfo.version}。
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
content: (
|
content: (
|
||||||
<pre
|
<pre
|
||||||
style={{
|
style={{
|
||||||
wordBreak: 'break-all',
|
|
||||||
whiteSpace: 'pre-wrap',
|
|
||||||
paddingTop: 15,
|
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: 400,
|
fontWeight: 400,
|
||||||
}}
|
}}
|
||||||
@@ -108,21 +104,17 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
maskClosable: false,
|
maskClosable: false,
|
||||||
closable: false,
|
closable: false,
|
||||||
okButtonProps: { disabled: true },
|
okButtonProps: { disabled: true },
|
||||||
title: '更新日志',
|
title: '更新中...',
|
||||||
centered: true,
|
centered: true,
|
||||||
content: (
|
content: (
|
||||||
<div style={{ height: '60vh', overflowY: 'auto' }}>
|
<pre
|
||||||
<pre
|
style={{
|
||||||
style={{
|
fontSize: 12,
|
||||||
wordBreak: 'break-all',
|
fontWeight: 400,
|
||||||
whiteSpace: 'pre-wrap',
|
}}
|
||||||
fontSize: 12,
|
>
|
||||||
fontWeight: 400,
|
{value}
|
||||||
}}
|
</pre>
|
||||||
>
|
|
||||||
{value}
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -145,11 +137,9 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
closable: updateFailed,
|
closable: updateFailed,
|
||||||
okButtonProps: { disabled: !updateFailed },
|
okButtonProps: { disabled: !updateFailed },
|
||||||
content: (
|
content: (
|
||||||
<div style={{ height: '60vh', overflowY: 'auto' }}>
|
<>
|
||||||
<pre
|
<pre
|
||||||
style={{
|
style={{
|
||||||
wordBreak: 'break-all',
|
|
||||||
whiteSpace: 'pre-wrap',
|
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: 400,
|
fontWeight: 400,
|
||||||
}}
|
}}
|
||||||
@@ -157,7 +147,7 @@ const CheckUpdate = ({ socketMessage }: any) => {
|
|||||||
{newMessage}
|
{newMessage}
|
||||||
</pre>
|
</pre>
|
||||||
<div id="log-identifier" style={{ paddingBottom: 5 }}></div>
|
<div id="log-identifier" style={{ paddingBottom: 5 }}></div>
|
||||||
</div>
|
</>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -18,5 +18,20 @@
|
|||||||
.desc {
|
.desc {
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:global {
|
||||||
|
.ant-descriptions-row > th,
|
||||||
|
.ant-descriptions-row > td {
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ql-setting-container {
|
||||||
|
.ant-tabs-content-holder {
|
||||||
|
max-height: calc(100vh - 114px);
|
||||||
|
max-height: calc(100vh - var(--vh-offset, 114px));
|
||||||
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-109
@@ -17,7 +17,6 @@ import {
|
|||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import * as DarkReader from '@umijs/ssr-darkreader';
|
|
||||||
import AppModal from './appModal';
|
import AppModal from './appModal';
|
||||||
import {
|
import {
|
||||||
EditOutlined,
|
EditOutlined,
|
||||||
@@ -27,21 +26,24 @@ import {
|
|||||||
import SecuritySettings from './security';
|
import SecuritySettings from './security';
|
||||||
import LoginLog from './loginLog';
|
import LoginLog from './loginLog';
|
||||||
import NotificationSetting from './notification';
|
import NotificationSetting from './notification';
|
||||||
import CheckUpdate from './checkUpdate';
|
import Other from './other';
|
||||||
import About from './about';
|
import About from './about';
|
||||||
import { useOutletContext } from '@umijs/max';
|
import { useOutletContext } from '@umijs/max';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
const optionsWithDisabled = [
|
|
||||||
{ label: '亮色', value: 'light' },
|
|
||||||
{ label: '暗色', value: 'dark' },
|
|
||||||
{ label: '跟随系统', value: 'auto' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const Setting = () => {
|
const Setting = () => {
|
||||||
const { headerStyle, isPhone, user, reloadUser, reloadTheme, socketMessage } =
|
const {
|
||||||
useOutletContext<SharedContext>();
|
headerStyle,
|
||||||
|
isPhone,
|
||||||
|
user,
|
||||||
|
reloadUser,
|
||||||
|
reloadTheme,
|
||||||
|
socketMessage,
|
||||||
|
systemInfo,
|
||||||
|
} = useOutletContext<SharedContext>();
|
||||||
const columns = [
|
const columns = [
|
||||||
{
|
{
|
||||||
title: '名称',
|
title: '名称',
|
||||||
@@ -72,10 +74,15 @@ const Setting = () => {
|
|||||||
dataIndex: 'scopes',
|
dataIndex: 'scopes',
|
||||||
key: 'scopes',
|
key: 'scopes',
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
|
width: '40%',
|
||||||
render: (text: string, record: any) => {
|
render: (text: string, record: any) => {
|
||||||
return record.scopes.map((scope: any) => {
|
return (
|
||||||
return <Tag key={scope}>{(config.scopesMap as any)[scope]}</Tag>;
|
<div style={{ textAlign: 'left' }}>
|
||||||
});
|
{record.scopes.map((scope: any) => {
|
||||||
|
return <Tag key={scope}>{(config.scopesMap as any)[scope]}</Tag>;
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -108,37 +115,12 @@ const Setting = () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const defaultTheme = localStorage.getItem('qinglong_dark_theme') || 'auto';
|
|
||||||
const [dataSource, setDataSource] = useState<any[]>([]);
|
const [dataSource, setDataSource] = useState<any[]>([]);
|
||||||
const [isModalVisible, setIsModalVisible] = useState(false);
|
const [isModalVisible, setIsModalVisible] = useState(false);
|
||||||
const [editedApp, setEditedApp] = useState<any>();
|
const [editedApp, setEditedApp] = useState<any>();
|
||||||
const [tabActiveKey, setTabActiveKey] = useState('security');
|
const [tabActiveKey, setTabActiveKey] = useState('security');
|
||||||
const [loginLogData, setLoginLogData] = useState<any[]>([]);
|
const [loginLogData, setLoginLogData] = useState<any[]>([]);
|
||||||
const [notificationInfo, setNotificationInfo] = useState<any>();
|
const [notificationInfo, setNotificationInfo] = useState<any>();
|
||||||
const [logRemoveFrequency, setLogRemoveFrequency] = useState<number>();
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
const {
|
|
||||||
enable: enableDarkMode,
|
|
||||||
disable: disableDarkMode,
|
|
||||||
exportGeneratedCSS: collectCSS,
|
|
||||||
setFetchMethod,
|
|
||||||
auto: followSystemColorScheme,
|
|
||||||
} = DarkReader || {};
|
|
||||||
|
|
||||||
const themeChange = (e: any) => {
|
|
||||||
const _theme = e.target.value;
|
|
||||||
localStorage.setItem('qinglong_dark_theme', e.target.value);
|
|
||||||
setFetchMethod(fetch);
|
|
||||||
|
|
||||||
if (_theme === 'dark') {
|
|
||||||
enableDarkMode({});
|
|
||||||
} else if (_theme === 'light') {
|
|
||||||
disableDarkMode();
|
|
||||||
} else {
|
|
||||||
followSystemColorScheme({});
|
|
||||||
}
|
|
||||||
reloadTheme();
|
|
||||||
};
|
|
||||||
|
|
||||||
const getApps = () => {
|
const getApps = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -263,8 +245,6 @@ const Setting = () => {
|
|||||||
getLoginLog();
|
getLoginLog();
|
||||||
} else if (activeKey === 'notification') {
|
} else if (activeKey === 'notification') {
|
||||||
getNotification();
|
getNotification();
|
||||||
} else if (activeKey === 'other') {
|
|
||||||
getLogRemoveFrequency();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -281,40 +261,9 @@ const Setting = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getLogRemoveFrequency = () => {
|
|
||||||
request
|
|
||||||
.get(`${config.apiPrefix}system/log/remove`)
|
|
||||||
.then(({ code, data }) => {
|
|
||||||
if (code === 200 && data.info) {
|
|
||||||
const { frequency } = data.info;
|
|
||||||
setLogRemoveFrequency(frequency);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error: any) => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateRemoveLogFrequency = () => {
|
|
||||||
setTimeout(() => {
|
|
||||||
request
|
|
||||||
.put(`${config.apiPrefix}system/log/remove`, {
|
|
||||||
data: { frequency: logRemoveFrequency },
|
|
||||||
})
|
|
||||||
.then(({ code, data }) => {
|
|
||||||
if (code === 200) {
|
|
||||||
message.success('更新成功');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error: any) => {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="ql-container-wrapper ql-container-wrapper-has-tab"
|
className="ql-container-wrapper ql-container-wrapper-has-tab ql-setting-container"
|
||||||
title="系统设置"
|
title="系统设置"
|
||||||
header={{
|
header={{
|
||||||
style: headerStyle,
|
style: headerStyle,
|
||||||
@@ -369,49 +318,17 @@ const Setting = () => {
|
|||||||
key: 'other',
|
key: 'other',
|
||||||
label: '其他设置',
|
label: '其他设置',
|
||||||
children: (
|
children: (
|
||||||
<Form layout="vertical" form={form}>
|
<Other
|
||||||
<Form.Item
|
reloadTheme={reloadTheme}
|
||||||
label="主题设置"
|
socketMessage={socketMessage}
|
||||||
name="theme"
|
systemInfo={systemInfo}
|
||||||
initialValue={defaultTheme}
|
/>
|
||||||
>
|
|
||||||
<Radio.Group
|
|
||||||
options={optionsWithDisabled}
|
|
||||||
onChange={themeChange}
|
|
||||||
value={defaultTheme}
|
|
||||||
optionType="button"
|
|
||||||
buttonStyle="solid"
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item
|
|
||||||
label="日志删除频率"
|
|
||||||
name="frequency"
|
|
||||||
tooltip="每x天自动删除x天以前的日志"
|
|
||||||
>
|
|
||||||
<Input.Group compact>
|
|
||||||
<InputNumber
|
|
||||||
addonBefore="每"
|
|
||||||
addonAfter="天"
|
|
||||||
style={{ width: 150 }}
|
|
||||||
min={0}
|
|
||||||
value={logRemoveFrequency}
|
|
||||||
onChange={(value) => setLogRemoveFrequency(value)}
|
|
||||||
/>
|
|
||||||
<Button type="primary" onClick={updateRemoveLogFrequency}>
|
|
||||||
确认
|
|
||||||
</Button>
|
|
||||||
</Input.Group>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item label="检查更新" name="update">
|
|
||||||
<CheckUpdate socketMessage={socketMessage} />
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'about',
|
key: 'about',
|
||||||
label: '关于',
|
label: '关于',
|
||||||
children: <About />,
|
children: <About systemInfo={systemInfo} />,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
></Tabs>
|
></Tabs>
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import { Button, InputNumber, Form, Radio, message, Input } from 'antd';
|
||||||
|
import * as DarkReader from '@umijs/ssr-darkreader';
|
||||||
|
import config from '@/utils/config';
|
||||||
|
import { request } from '@/utils/http';
|
||||||
|
import CheckUpdate from './checkUpdate';
|
||||||
|
import { SharedContext } from '@/layouts';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
|
const optionsWithDisabled = [
|
||||||
|
{ label: '亮色', value: 'light' },
|
||||||
|
{ label: '暗色', value: 'dark' },
|
||||||
|
{ label: '跟随系统', value: 'auto' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const Other = ({
|
||||||
|
systemInfo,
|
||||||
|
socketMessage,
|
||||||
|
reloadTheme,
|
||||||
|
}: Pick<SharedContext, 'socketMessage' | 'reloadTheme' | 'systemInfo'>) => {
|
||||||
|
const defaultTheme = localStorage.getItem('qinglong_dark_theme') || 'auto';
|
||||||
|
const [logRemoveFrequency, setLogRemoveFrequency] = useState<number | null>();
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
|
const {
|
||||||
|
enable: enableDarkMode,
|
||||||
|
disable: disableDarkMode,
|
||||||
|
exportGeneratedCSS: collectCSS,
|
||||||
|
setFetchMethod,
|
||||||
|
auto: followSystemColorScheme,
|
||||||
|
} = DarkReader || {};
|
||||||
|
|
||||||
|
const themeChange = (e: any) => {
|
||||||
|
const _theme = e.target.value;
|
||||||
|
localStorage.setItem('qinglong_dark_theme', e.target.value);
|
||||||
|
setFetchMethod(fetch);
|
||||||
|
|
||||||
|
if (_theme === 'dark') {
|
||||||
|
enableDarkMode({});
|
||||||
|
} else if (_theme === 'light') {
|
||||||
|
disableDarkMode();
|
||||||
|
} else {
|
||||||
|
followSystemColorScheme({});
|
||||||
|
}
|
||||||
|
reloadTheme();
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLogRemoveFrequency = () => {
|
||||||
|
request
|
||||||
|
.get(`${config.apiPrefix}system/log/remove`)
|
||||||
|
.then(({ code, data }) => {
|
||||||
|
if (code === 200 && data.info) {
|
||||||
|
const { frequency } = data.info;
|
||||||
|
setLogRemoveFrequency(frequency);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateRemoveLogFrequency = () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
request
|
||||||
|
.put(`${config.apiPrefix}system/log/remove`, {
|
||||||
|
data: { frequency: logRemoveFrequency },
|
||||||
|
})
|
||||||
|
.then(({ code, data }) => {
|
||||||
|
if (code === 200) {
|
||||||
|
message.success('更新成功');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getLogRemoveFrequency();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form layout="vertical" form={form}>
|
||||||
|
<Form.Item label="主题设置" name="theme" initialValue={defaultTheme}>
|
||||||
|
<Radio.Group
|
||||||
|
options={optionsWithDisabled}
|
||||||
|
onChange={themeChange}
|
||||||
|
value={defaultTheme}
|
||||||
|
optionType="button"
|
||||||
|
buttonStyle="solid"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
label="日志删除频率"
|
||||||
|
name="frequency"
|
||||||
|
tooltip="每x天自动删除x天以前的日志"
|
||||||
|
>
|
||||||
|
<Input.Group compact>
|
||||||
|
<InputNumber
|
||||||
|
addonBefore="每"
|
||||||
|
addonAfter="天"
|
||||||
|
style={{ width: 150 }}
|
||||||
|
min={0}
|
||||||
|
value={logRemoveFrequency}
|
||||||
|
onChange={(value) => setLogRemoveFrequency(value)}
|
||||||
|
/>
|
||||||
|
<Button type="primary" onClick={updateRemoveLogFrequency}>
|
||||||
|
确认
|
||||||
|
</Button>
|
||||||
|
</Input.Group>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item label="检查更新" name="update">
|
||||||
|
<CheckUpdate systemInfo={systemInfo} socketMessage={socketMessage} />
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Other;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
.inline-form-item {
|
||||||
|
margin-bottom: 0;
|
||||||
|
|
||||||
|
.ant-form-item {
|
||||||
|
display: inline-block;
|
||||||
|
width: 50%;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect, useRef } from 'react';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
message,
|
message,
|
||||||
@@ -29,11 +29,11 @@ import config from '@/utils/config';
|
|||||||
import { PageContainer } from '@ant-design/pro-layout';
|
import { PageContainer } from '@ant-design/pro-layout';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import SubscriptionModal from './modal';
|
import SubscriptionModal from './modal';
|
||||||
import { getTableScroll } from '@/utils/index';
|
|
||||||
import { history, useOutletContext } from '@umijs/max';
|
import { history, useOutletContext } from '@umijs/max';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
import SubscriptionLogModal from './logModal';
|
import SubscriptionLogModal from './logModal';
|
||||||
import { SharedContext } from '@/layouts';
|
import { SharedContext } from '@/layouts';
|
||||||
|
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
|
||||||
|
|
||||||
const { Text, Paragraph } = Typography;
|
const { Text, Paragraph } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
@@ -243,10 +243,10 @@ const Subscription = () => {
|
|||||||
const [searchText, setSearchText] = useState('');
|
const [searchText, setSearchText] = useState('');
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [pageSize, setPageSize] = useState(20);
|
const [pageSize, setPageSize] = useState(20);
|
||||||
const [tableScrollHeight, setTableScrollHeight] = useState<number>();
|
|
||||||
const [searchValue, setSearchValue] = useState('');
|
|
||||||
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
||||||
const [logSubscription, setLogSubscription] = useState<any>();
|
const [logSubscription, setLogSubscription] = useState<any>();
|
||||||
|
const tableRef = useRef<any>();
|
||||||
|
const tableScrollHeight = useTableScrollHeight(tableRef);
|
||||||
|
|
||||||
const runSubscription = (record: any, index: number) => {
|
const runSubscription = (record: any, index: number) => {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
@@ -427,28 +427,26 @@ const Subscription = () => {
|
|||||||
arrow={{ pointAtCenter: true }}
|
arrow={{ pointAtCenter: true }}
|
||||||
placement="bottomRight"
|
placement="bottomRight"
|
||||||
trigger={['click']}
|
trigger={['click']}
|
||||||
overlay={
|
menu={{
|
||||||
<Menu
|
items: [
|
||||||
items={[
|
{ label: '编辑', key: 'edit', icon: <EditOutlined /> },
|
||||||
{ label: '编辑', key: 'edit', icon: <EditOutlined /> },
|
{
|
||||||
{
|
label: record.is_disabled === 1 ? '启用' : '禁用',
|
||||||
label: record.is_disabled === 1 ? '启用' : '禁用',
|
key: 'enableOrDisable',
|
||||||
key: 'enableOrDisable',
|
icon:
|
||||||
icon:
|
record.is_disabled === 1 ? (
|
||||||
record.is_disabled === 1 ? (
|
<CheckCircleOutlined />
|
||||||
<CheckCircleOutlined />
|
) : (
|
||||||
) : (
|
<StopOutlined />
|
||||||
<StopOutlined />
|
),
|
||||||
),
|
},
|
||||||
},
|
{ label: '删除', key: 'delete', icon: <DeleteOutlined /> },
|
||||||
{ label: '删除', key: 'delete', icon: <DeleteOutlined /> },
|
],
|
||||||
]}
|
onClick: ({ key, domEvent }) => {
|
||||||
onClick={({ key, domEvent }) => {
|
domEvent.stopPropagation();
|
||||||
domEvent.stopPropagation();
|
action(key, record, index);
|
||||||
action(key, record, index);
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<a onClick={(e) => e.stopPropagation()}>
|
<a onClick={(e) => e.stopPropagation()}>
|
||||||
<EllipsisOutlined />
|
<EllipsisOutlined />
|
||||||
@@ -539,9 +537,6 @@ const Subscription = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPageSize(parseInt(localStorage.getItem('pageSize') || '20'));
|
setPageSize(parseInt(localStorage.getItem('pageSize') || '20'));
|
||||||
setTimeout(() => {
|
|
||||||
setTableScrollHeight(getTableScroll());
|
|
||||||
});
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -555,8 +550,6 @@ const Subscription = () => {
|
|||||||
enterButton
|
enterButton
|
||||||
allowClear
|
allowClear
|
||||||
loading={loading}
|
loading={loading}
|
||||||
value={searchValue}
|
|
||||||
onChange={(e) => setSearchValue(e.target.value)}
|
|
||||||
onSearch={onSearch}
|
onSearch={onSearch}
|
||||||
/>,
|
/>,
|
||||||
<Button key="2" type="primary" onClick={() => addSubscription()}>
|
<Button key="2" type="primary" onClick={() => addSubscription()}>
|
||||||
@@ -568,6 +561,7 @@ const Subscription = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Table
|
<Table
|
||||||
|
ref={tableRef}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
pagination={{
|
pagination={{
|
||||||
current: currentPage,
|
current: currentPage,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
CheckCircleOutlined,
|
CheckCircleOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { PageLoading } from '@ant-design/pro-layout';
|
import { PageLoading } from '@ant-design/pro-layout';
|
||||||
|
import { logEnded } from '@/utils';
|
||||||
|
|
||||||
const SubscriptionLogModal = ({
|
const SubscriptionLogModal = ({
|
||||||
subscription,
|
subscription,
|
||||||
@@ -43,8 +44,8 @@ const SubscriptionLogModal = ({
|
|||||||
) {
|
) {
|
||||||
const log = data as string;
|
const log = data as string;
|
||||||
setValue(log || '暂无日志');
|
setValue(log || '暂无日志');
|
||||||
setExecuting(log && !log.includes('执行结束'));
|
setExecuting(log && !logEnded(log));
|
||||||
if (log && !log.includes('执行结束')) {
|
if (log && !logEnded(log)) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
getCronLog();
|
getCronLog();
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { Modal, message, InputNumber, Form, Radio, Select, Input } from 'antd';
|
import {
|
||||||
|
Modal,
|
||||||
|
message,
|
||||||
|
InputNumber,
|
||||||
|
Form,
|
||||||
|
Radio,
|
||||||
|
Select,
|
||||||
|
Input,
|
||||||
|
Switch,
|
||||||
|
} from 'antd';
|
||||||
import { request } from '@/utils/http';
|
import { request } from '@/utils/http';
|
||||||
import config from '@/utils/config';
|
import config from '@/utils/config';
|
||||||
import cron_parser from 'cron-parser';
|
import cron_parser from 'cron-parser';
|
||||||
@@ -26,7 +35,11 @@ const SubscriptionModal = ({
|
|||||||
const handleOk = async (values: any) => {
|
const handleOk = async (values: any) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const method = subscription ? 'put' : 'post';
|
const method = subscription ? 'put' : 'post';
|
||||||
const payload = { ...values };
|
const payload = {
|
||||||
|
...values,
|
||||||
|
autoAddCron: Boolean(values.autoAddCron),
|
||||||
|
autoDelCron: Boolean(values.autoDelCron),
|
||||||
|
};
|
||||||
if (subscription) {
|
if (subscription) {
|
||||||
payload.id = subscription.id;
|
payload.id = subscription.id;
|
||||||
}
|
}
|
||||||
@@ -110,8 +123,8 @@ const SubscriptionModal = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const numberChange = (value: number) => {
|
const numberChange = (value: number | null) => {
|
||||||
setIntervalNumber(value);
|
setIntervalNumber(value || 1);
|
||||||
if (!value) {
|
if (!value) {
|
||||||
onChange?.(null);
|
onChange?.(null);
|
||||||
} else {
|
} else {
|
||||||
@@ -439,6 +452,37 @@ const SubscriptionModal = ({
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
<Form.Item
|
||||||
|
name="proxy"
|
||||||
|
label="代理"
|
||||||
|
tooltip="公开仓库支持HTTP/SOCK5代理,私有仓库支持SOCK5代理"
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
placeholder={
|
||||||
|
type === 'private-repo'
|
||||||
|
? 'SOCK5代理,例如 IP:PORT'
|
||||||
|
: 'HTTP/SOCK5代理,例如 http://127.0.0.1:1080'
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item style={{ marginBottom: 0 }} className="inline-form-item">
|
||||||
|
<Form.Item
|
||||||
|
name="autoAddCron"
|
||||||
|
label="自动添加任务"
|
||||||
|
valuePropName="checked"
|
||||||
|
initialValue={true}
|
||||||
|
>
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
<Form.Item
|
||||||
|
name="autoDelCron"
|
||||||
|
label="自动删除任务"
|
||||||
|
valuePropName="checked"
|
||||||
|
initialValue={true}
|
||||||
|
>
|
||||||
|
<Switch />
|
||||||
|
</Form.Item>
|
||||||
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
|
|||||||
+42
-2
@@ -88,10 +88,12 @@ export default {
|
|||||||
{ value: 'dingtalkBot', label: '钉钉机器人' },
|
{ value: 'dingtalkBot', label: '钉钉机器人' },
|
||||||
{ value: 'weWorkBot', label: '企业微信机器人' },
|
{ value: 'weWorkBot', label: '企业微信机器人' },
|
||||||
{ value: 'weWorkApp', label: '企业微信应用' },
|
{ value: 'weWorkApp', label: '企业微信应用' },
|
||||||
|
{ value: 'aibotk', label: '智能微秘书' },
|
||||||
{ value: 'iGot', label: 'IGot' },
|
{ value: 'iGot', label: 'IGot' },
|
||||||
{ value: 'pushPlus', label: 'PushPlus' },
|
{ value: 'pushPlus', label: 'PushPlus' },
|
||||||
{ value: 'chat', label: '群辉chat' },
|
{ value: 'chat', label: '群辉chat' },
|
||||||
{ value: 'email', label: '邮箱' },
|
{ value: 'email', label: '邮箱' },
|
||||||
|
{ value: 'lark', label: '飞书机器人' },
|
||||||
{ value: 'webhook', label: '自定义通知' },
|
{ value: 'webhook', label: '自定义通知' },
|
||||||
{ value: 'closed', label: '已关闭' },
|
{ value: 'closed', label: '已关闭' },
|
||||||
],
|
],
|
||||||
@@ -135,6 +137,10 @@ export default {
|
|||||||
tip: 'PushDeer的Key,https://github.com/easychen/pushdeer',
|
tip: 'PushDeer的Key,https://github.com/easychen/pushdeer',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'pushDeerUrl',
|
||||||
|
tip: 'PushDeer的自架API endpoint,默认是 https://api2.pushdeer.com/message/push',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
bark: [
|
bark: [
|
||||||
{
|
{
|
||||||
@@ -196,6 +202,28 @@ export default {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
aibotk: [
|
||||||
|
{
|
||||||
|
label: 'aibotkKey',
|
||||||
|
tip: '密钥key,智能微秘书个人中心获取apikey,申请地址:https://wechat.aibotk.com/signup?from=ql',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'aibotkType',
|
||||||
|
tip: '发送的目标,群组或者好友',
|
||||||
|
required: true,
|
||||||
|
placeholder: '请输入要发送的目标',
|
||||||
|
items: [
|
||||||
|
{ value: 'room', label: '群聊' },
|
||||||
|
{ value: 'contact', label: '好友' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'aibotkName',
|
||||||
|
tip: '要发送的用户昵称或群名,如果目标是群,需要填群名,如果目标是好友,需要填好友昵称',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
iGot: [
|
iGot: [
|
||||||
{
|
{
|
||||||
label: 'iGotPushKey',
|
label: 'iGotPushKey',
|
||||||
@@ -214,6 +242,13 @@ export default {
|
|||||||
tip: '一对多推送的“群组编码”(一对多推送下面->您的群组(如无则新建)->群组编码,如果您是创建群组人。也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送)',
|
tip: '一对多推送的“群组编码”(一对多推送下面->您的群组(如无则新建)->群组编码,如果您是创建群组人。也需点击“查看二维码”扫描绑定,否则不能接受群组消息推送)',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
lark: [
|
||||||
|
{
|
||||||
|
label: 'larkKey',
|
||||||
|
tip: '飞书群组机器人:https://www.feishu.cn/hc/zh-CN/articles/360024984973',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
email: [
|
email: [
|
||||||
{
|
{
|
||||||
label: 'emailService',
|
label: 'emailService',
|
||||||
@@ -234,7 +269,11 @@ export default {
|
|||||||
label: 'webhookContentType',
|
label: 'webhookContentType',
|
||||||
tip: '请求头Content-Type',
|
tip: '请求头Content-Type',
|
||||||
required: true,
|
required: true,
|
||||||
items: [{ value: 'application/json' }, { value: 'multipart/form-data' }, { value: 'application/x-www-form-urlencoded' }],
|
items: [
|
||||||
|
{ value: 'application/json' },
|
||||||
|
{ value: 'multipart/form-data' },
|
||||||
|
{ value: 'application/x-www-form-urlencoded' },
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'webhookUrl',
|
label: 'webhookUrl',
|
||||||
@@ -257,7 +296,7 @@ export default {
|
|||||||
documentTitleMap: {
|
documentTitleMap: {
|
||||||
'/login': '登录',
|
'/login': '登录',
|
||||||
'/initialization': '初始化',
|
'/initialization': '初始化',
|
||||||
'/cron': '定时任务',
|
'/crontab': '定时任务',
|
||||||
'/env': '环境变量',
|
'/env': '环境变量',
|
||||||
'/subscription': '订阅管理',
|
'/subscription': '订阅管理',
|
||||||
'/config': '配置文件',
|
'/config': '配置文件',
|
||||||
@@ -266,6 +305,7 @@ export default {
|
|||||||
'/log': '日志管理',
|
'/log': '日志管理',
|
||||||
'/setting': '系统设置',
|
'/setting': '系统设置',
|
||||||
'/error': '错误日志',
|
'/error': '错误日志',
|
||||||
|
'/dependence': '依赖管理',
|
||||||
},
|
},
|
||||||
dependenceTypes: ['nodejs', 'python3', 'linux'],
|
dependenceTypes: ['nodejs', 'python3', 'linux'],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export const LOG_END_SYMBOL = ' ';
|
||||||
@@ -56,7 +56,6 @@ _request.interceptors.request.use((url, options) => {
|
|||||||
_request.interceptors.response.use(async (response) => {
|
_request.interceptors.response.use(async (response) => {
|
||||||
const responseStatus = response.status;
|
const responseStatus = response.status;
|
||||||
if ([502, 504].includes(responseStatus)) {
|
if ([502, 504].includes(responseStatus)) {
|
||||||
message.error('服务异常,请稍后刷新!');
|
|
||||||
history.push('/error');
|
history.push('/error');
|
||||||
} else if (responseStatus === 401) {
|
} else if (responseStatus === 401) {
|
||||||
if (history.location.pathname !== '/login') {
|
if (history.location.pathname !== '/login') {
|
||||||
|
|||||||
+76
-11
@@ -1,3 +1,6 @@
|
|||||||
|
import { LOG_END_SYMBOL } from './const';
|
||||||
|
import cron_parser from 'cron-parser';
|
||||||
|
|
||||||
export default function browserType() {
|
export default function browserType() {
|
||||||
// 权重:系统 + 系统版本 > 平台 > 内核 + 载体 + 内核版本 + 载体版本 > 外壳 + 外壳版本
|
// 权重:系统 + 系统版本 > 平台 > 内核 + 载体 + 内核版本 + 载体版本 > 外壳 + 外壳版本
|
||||||
const ua = navigator.userAgent.toLowerCase();
|
const ua = navigator.userAgent.toLowerCase();
|
||||||
@@ -150,9 +153,9 @@ export default function browserType() {
|
|||||||
shell === 'none'
|
shell === 'none'
|
||||||
? {}
|
? {}
|
||||||
: {
|
: {
|
||||||
shell, // wechat qq uc 360 2345 sougou liebao maxthon
|
shell, // wechat qq uc 360 2345 sougou liebao maxthon
|
||||||
shellVs,
|
shellVs,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
@@ -178,19 +181,15 @@ export default function browserType() {
|
|||||||
*/
|
*/
|
||||||
export function getTableScroll({
|
export function getTableScroll({
|
||||||
extraHeight,
|
extraHeight,
|
||||||
id,
|
target,
|
||||||
}: { extraHeight?: number; id?: string } = {}) {
|
}: { extraHeight?: number; target?: HTMLElement } = {}) {
|
||||||
if (typeof extraHeight == 'undefined') {
|
if (typeof extraHeight == 'undefined') {
|
||||||
// 47 + 40 + 12
|
// 47 + 40 + 12
|
||||||
extraHeight = 99;
|
extraHeight = 99;
|
||||||
}
|
}
|
||||||
let tHeader = null;
|
let tHeader = null;
|
||||||
if (id) {
|
if (target) {
|
||||||
tHeader = document.getElementById(id)
|
tHeader = target;
|
||||||
? document
|
|
||||||
.getElementById(id)!
|
|
||||||
.getElementsByClassName('ant-table-thead')[0]
|
|
||||||
: null;
|
|
||||||
} else {
|
} else {
|
||||||
tHeader = document.querySelector('.ant-table-wrapper');
|
tHeader = document.querySelector('.ant-table-wrapper');
|
||||||
}
|
}
|
||||||
@@ -273,3 +272,69 @@ export function depthFirstSearch<
|
|||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function findNode<T extends Record<string, any> & { children?: T[] }>(
|
||||||
|
children: T[],
|
||||||
|
condition: (column: T) => boolean,
|
||||||
|
) {
|
||||||
|
const c = [...children];
|
||||||
|
|
||||||
|
let item;
|
||||||
|
function find(cls: T[] | undefined): T | undefined {
|
||||||
|
if (!cls) return;
|
||||||
|
for (let i = 0; i < cls?.length; i++) {
|
||||||
|
if (condition(cls[i])) {
|
||||||
|
item = cls[i];
|
||||||
|
} else if (cls[i].children) {
|
||||||
|
find(cls[i].children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
find(c);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function logEnded(log: string): boolean {
|
||||||
|
const endTips = [LOG_END_SYMBOL, '执行结束'];
|
||||||
|
return endTips.some((x) => log.includes(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCommandScript(
|
||||||
|
command: string,
|
||||||
|
): [string, string] | string | undefined {
|
||||||
|
const cmd = command.split(' ') as string[];
|
||||||
|
if (cmd[1] === 'repo' || cmd[1] === 'raw') {
|
||||||
|
return cmd[2];
|
||||||
|
}
|
||||||
|
let scriptsPart = cmd.find((x) =>
|
||||||
|
['.js', '.ts', '.sh', '.py'].some((y) => x.endsWith(y)),
|
||||||
|
);
|
||||||
|
if (!scriptsPart) return;
|
||||||
|
if (scriptsPart.startsWith('/ql/data/scripts')) {
|
||||||
|
scriptsPart = scriptsPart.replace('/ql/data/scripts/', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
let p: string, s: string;
|
||||||
|
let index = scriptsPart.lastIndexOf('/');
|
||||||
|
if (index >= 0) {
|
||||||
|
s = scriptsPart.slice(index + 1);
|
||||||
|
p = scriptsPart.slice(0, index);
|
||||||
|
} else {
|
||||||
|
s = scriptsPart;
|
||||||
|
p = '';
|
||||||
|
}
|
||||||
|
return [s, p];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseCrontab(schedule: string): Date {
|
||||||
|
try {
|
||||||
|
const time = cron_parser.parseExpression(schedule);
|
||||||
|
if (time) {
|
||||||
|
return time.next().toDate();
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
|
|
||||||
|
return new Date('1970');
|
||||||
|
}
|
||||||
|
|||||||
+3
-5
@@ -1,9 +1,9 @@
|
|||||||
import * as Sentry from '@sentry/react';
|
import * as Sentry from '@sentry/react';
|
||||||
import { Integrations } from '@sentry/tracing';
|
import { Integrations } from '@sentry/tracing';
|
||||||
import { loader } from '@monaco-editor/react';
|
import { loader } from '@monaco-editor/react';
|
||||||
import { version } from '../version';
|
import * as monaco from 'monaco-editor';
|
||||||
|
|
||||||
export function init() {
|
export function init(version: string) {
|
||||||
// sentry监控 init
|
// sentry监控 init
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
dsn: 'https://3406424fb1dc4813a62d39e844a9d0ac@o1098464.ingest.sentry.io/6122818',
|
dsn: 'https://3406424fb1dc4813a62d39e844a9d0ac@o1098464.ingest.sentry.io/6122818',
|
||||||
@@ -27,9 +27,7 @@ export function init() {
|
|||||||
|
|
||||||
// monaco 编辑器配置cdn和locale
|
// monaco 编辑器配置cdn和locale
|
||||||
loader.config({
|
loader.config({
|
||||||
paths: {
|
monaco,
|
||||||
vs: 'https://cdn.staticfile.org/monaco-editor/0.33.0/min/vs',
|
|
||||||
},
|
|
||||||
'vs/nls': {
|
'vs/nls': {
|
||||||
availableLanguages: {
|
availableLanguages: {
|
||||||
'*': 'zh-cn',
|
'*': 'zh-cn',
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
export const version = '2.14.6';
|
|
||||||
export const changeLogLink = 'https://t.me/jiao_long/333';
|
|
||||||
export const changeLog = `2.14.6 版本说明
|
|
||||||
1. 任务执行日志增加资源占用说明
|
|
||||||
2. 配置文件config.sh增加资源配置参数CpuWarn/MemoryWarn/DiskWarn
|
|
||||||
3. 修复脚本管理和日志管理搜索
|
|
||||||
4. 其他bug修复
|
|
||||||
`;
|
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
"./src/types",
|
"./src/types",
|
||||||
"./node_modules/celebrate/lib/index.d.ts"
|
"./node_modules/celebrate/lib/index.d.ts"
|
||||||
],
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./back/*"],
|
||||||
|
},
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
|
|||||||
Vendored
+2
@@ -8,3 +8,5 @@ declare module '*.svg' {
|
|||||||
const url: string;
|
const url: string;
|
||||||
export default url;
|
export default url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module 'pstree.remy';
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
version: 2.15.7
|
||||||
|
changeLogLink: https://t.me/jiao_long/363
|
||||||
|
changeLog: |
|
||||||
|
1. 订阅支持自动添加和删除任务设置
|
||||||
|
2. 增加 ppc64le/s390x/386 镜像
|
||||||
|
3. 修改 curl 等命令参数处理逻辑
|
||||||
|
4. 修复移动端新建脚本
|
||||||
|
5. 修改任务日志自动滚动逻辑
|
||||||
|
6. 修复查看任务日志,列表位置重置
|
||||||
|
7. 其他优化
|
||||||
Reference in New Issue
Block a user