调整数据目录

This commit is contained in:
whyour 2022-02-19 13:08:14 +08:00
parent 0caf53b147
commit 0112b92e77
21 changed files with 75 additions and 150 deletions

View File

@ -36,9 +36,9 @@ jobs:
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 }}
run: | run: |
mkdir -p static mkdir -p tmp
cd ./static cd ./tmp
cp -rf ../dist ./ && cp -rf ../build ./ cp -rf ../static ./
git init -b ${GITHUB_BRANCH} && git add . git init -b ${GITHUB_BRANCH} && git add .
git config --local user.name 'github-actions[bot]' git config --local user.name 'github-actions[bot]'
git config --local user.email 'github-actions[bot]@users.noreply.github.com' git config --local user.email 'github-actions[bot]@users.noreply.github.com'

4
.gitignore vendored
View File

@ -8,8 +8,8 @@
/package-lock.json /package-lock.json
# production # production
/dist /static
/build /data
# misc # misc
.DS_Store .DS_Store

View File

@ -4,6 +4,7 @@ const CompressionPlugin = require('compression-webpack-plugin');
export default defineConfig({ export default defineConfig({
hash: true, hash: true,
layout: false, layout: false,
outputPath: 'static/dist',
nodeModulesTransform: { nodeModulesTransform: {
type: 'none', type: 'none',
}, },

View File

@ -56,12 +56,7 @@ sudo curl -sSL get.docker.com | sh
```bash ```bash
docker run -dit \ docker run -dit \
-v $PWD/ql/config:/ql/config \ -v $PWD/ql:/ql/data \
-v $PWD/ql/log:/ql/log \
-v $PWD/ql/db:/ql/db \
-v $PWD/ql/repo:/ql/repo \
-v $PWD/ql/raw:/ql/raw \
-v $PWD/ql/scripts:/ql/scripts \
-p 5700:5700 \ -p 5700:5700 \
--name qinglong \ --name qinglong \
--hostname qinglong \ --hostname qinglong \

View File

@ -5,8 +5,8 @@ import * as fs from 'fs';
import config from '../config'; import config from '../config';
import SystemService from '../services/system'; import SystemService from '../services/system';
import { celebrate, Joi } from 'celebrate'; import { celebrate, Joi } from 'celebrate';
import { getFileContentByName } from '../config/util';
import UserService from '../services/user'; import UserService from '../services/user';
import { EnvModel } from '../data/env';
const route = Router(); const route = Router();
export default (app: Router) => { export default (app: Router) => {
@ -17,7 +17,7 @@ export default (app: Router) => {
try { try {
const userService = Container.get(UserService); const userService = Container.get(UserService);
const authInfo = await userService.getUserInfo(); const authInfo = await userService.getUserInfo();
const envDbContent = getFileContentByName(config.envDbFile); const envCount = await EnvModel.count();
const versionRegx = /.*export const version = \'(.*)\'\;/; const versionRegx = /.*export const version = \'(.*)\'\;/;
const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8'); const currentVersionFile = fs.readFileSync(config.versionFile, 'utf8');
@ -28,7 +28,7 @@ export default (app: Router) => {
Object.keys(authInfo).length === 2 && Object.keys(authInfo).length === 2 &&
authInfo.username === 'admin' && authInfo.username === 'admin' &&
authInfo.password === 'admin' && authInfo.password === 'admin' &&
envDbContent.length === 0 envCount === 0
) { ) {
isInitialized = false; isInitialized = false;
} }

View File

@ -9,27 +9,26 @@ const lastVersionFile =
const envFound = dotenv.config(); const envFound = dotenv.config();
const rootPath = process.cwd(); const rootPath = process.cwd();
const envFile = path.join(rootPath, 'config/env.sh'); const dataPath = path.join(rootPath, 'data/');
const confFile = path.join(rootPath, 'config/config.sh');
const sampleFile = path.join(rootPath, 'sample/config.sample.sh');
const crontabFile = path.join(rootPath, 'config/crontab.list');
const confBakDir = path.join(rootPath, 'config/bak/');
const authConfigFile = path.join(rootPath, 'config/auth.json');
const extraFile = path.join(rootPath, 'config/extra.sh');
const configPath = path.join(rootPath, 'config/');
const scriptPath = path.join(rootPath, 'scripts/');
const bakPath = path.join(rootPath, 'bak/');
const samplePath = path.join(rootPath, 'sample/'); const samplePath = path.join(rootPath, 'sample/');
const logPath = path.join(rootPath, 'log/'); const configPath = path.join(dataPath, 'config/');
const scriptPath = path.join(dataPath, 'scripts/');
const bakPath = path.join(dataPath, 'bak/');
const logPath = path.join(dataPath, 'log/');
const dbPath = path.join(dataPath, 'db/');
const envFile = path.join(configPath, 'env.sh');
const confFile = path.join(configPath, 'config.sh');
const crontabFile = path.join(configPath, 'crontab.list');
const authConfigFile = path.join(configPath, 'auth.json');
const extraFile = path.join(configPath, 'extra.sh');
const confBakDir = path.join(dataPath, 'config/bak/');
const sampleFile = path.join(samplePath, 'config.sample.sh');
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 dbPath = path.join(rootPath, 'db/');
const cronDbFile = path.join(rootPath, 'db/crontab.db');
const envDbFile = path.join(rootPath, 'db/env.db');
const appDbFile = path.join(rootPath, 'db/app.db');
const authDbFile = path.join(rootPath, 'db/auth.db');
const dependenceDbFile = path.join(rootPath, 'db/dependence.db');
const versionFile = path.join(rootPath, 'src/version.ts'); const versionFile = path.join(rootPath, 'src/version.ts');
if (envFound.error) { if (envFound.error) {
@ -59,11 +58,6 @@ export default {
confFile, confFile,
envFile, envFile,
dbPath, dbPath,
cronDbFile,
envDbFile,
appDbFile,
authDbFile,
dependenceDbFile,
configPath, configPath,
scriptPath, scriptPath,
samplePath, samplePath,
@ -86,4 +80,5 @@ export default {
], ],
versionFile, versionFile,
lastVersionFile, lastVersionFile,
sqliteFile,
}; };

View File

@ -1,7 +1,4 @@
import DataStore from 'nedb';
import config from '../config';
import Logger from './logger'; import Logger from './logger';
import { fileExist } from '../config/util';
import { EnvModel } from '../data/env'; import { EnvModel } from '../data/env';
import { CrontabModel } from '../data/cron'; import { CrontabModel } from '../data/cron';
import { DependenceModel } from '../data/dependence'; import { DependenceModel } from '../data/dependence';
@ -12,7 +9,11 @@ import { sequelize } from '../data';
export default async () => { export default async () => {
try { try {
await sequelize.sync(); await sequelize.sync();
await new Promise((resolve) => setTimeout(() => resolve(null), 5000)); await CrontabModel.sync();
await DependenceModel.sync();
await AppModel.sync();
await AuthModel.sync();
await EnvModel.sync();
// try { // try {
// const queryInterface = sequelize.getQueryInterface(); // const queryInterface = sequelize.getQueryInterface();
@ -23,72 +24,6 @@ export default async () => {
// } // }
const crondbExist = await fileExist(config.cronDbFile);
const dependenceDbExist = await fileExist(config.dependenceDbFile);
const envDbExist = await fileExist(config.envDbFile);
const appDbExist = await fileExist(config.appDbFile);
const authDbExist = await fileExist(config.authDbFile);
const cronCount = await CrontabModel.count();
const dependenceCount = await DependenceModel.count();
const envCount = await EnvModel.count();
const appCount = await AppModel.count();
const authCount = await AuthModel.count();
if (crondbExist && cronCount === 0) {
const cronDb = new DataStore({
filename: config.cronDbFile,
autoload: true,
});
cronDb.persistence.compactDatafile();
cronDb.find({}).exec(async (err, docs) => {
await CrontabModel.bulkCreate(docs, { ignoreDuplicates: true });
});
}
if (dependenceDbExist && dependenceCount === 0) {
const dependenceDb = new DataStore({
filename: config.dependenceDbFile,
autoload: true,
});
dependenceDb.persistence.compactDatafile();
dependenceDb.find({}).exec(async (err, docs) => {
await DependenceModel.bulkCreate(docs, { ignoreDuplicates: true });
});
}
if (envDbExist && envCount === 0) {
const envDb = new DataStore({
filename: config.envDbFile,
autoload: true,
});
envDb.persistence.compactDatafile();
envDb.find({}).exec(async (err, docs) => {
await EnvModel.bulkCreate(docs, { ignoreDuplicates: true });
});
}
if (appDbExist && appCount === 0) {
const appDb = new DataStore({
filename: config.appDbFile,
autoload: true,
});
appDb.persistence.compactDatafile();
appDb.find({}).exec(async (err, docs) => {
await AppModel.bulkCreate(docs, { ignoreDuplicates: true });
});
}
if (authDbExist && authCount === 0) {
const authDb = new DataStore({
filename: config.authDbFile,
autoload: true,
});
authDb.persistence.compactDatafile();
authDb.find({}).exec(async (err, docs) => {
await AuthModel.bulkCreate(docs, { ignoreDuplicates: true });
});
}
Logger.info('✌️ DB loaded'); Logger.info('✌️ DB loaded');
} catch (error) { } catch (error) {
Logger.info('✌️ DB load failed'); Logger.info('✌️ DB load failed');

View File

@ -5,13 +5,14 @@ import routes from '../api';
import config from '../config'; import config from '../config';
import jwt from 'express-jwt'; import jwt from 'express-jwt';
import fs from 'fs'; import fs from 'fs';
import { getFileContentByName, getPlatform, getToken } from '../config/util'; import { getPlatform, getToken } from '../config/util';
import Container from 'typedi'; import Container from 'typedi';
import OpenService from '../services/open'; import OpenService from '../services/open';
import rewrite from 'express-urlrewrite'; import rewrite from 'express-urlrewrite';
import UserService from '../services/user'; import UserService from '../services/user';
import handler from 'serve-handler'; import handler from 'serve-handler';
import * as Sentry from '@sentry/node'; import * as Sentry from '@sentry/node';
import { EnvModel } from '../data/env';
export default ({ app }: { app: Application }) => { export default ({ app }: { app: Application }) => {
app.enable('trust proxy'); app.enable('trust proxy');
@ -22,7 +23,7 @@ export default ({ app }: { app: Application }) => {
next(); next();
} else { } else {
return handler(req, res, { return handler(req, res, {
public: 'dist', public: 'static/dist',
rewrites: [{ source: '**', destination: '/index.html' }], rewrites: [{ source: '**', destination: '/index.html' }],
}); });
} }
@ -104,14 +105,14 @@ export default ({ app }: { app: Application }) => {
} }
const userService = Container.get(UserService); const userService = Container.get(UserService);
const authInfo = await userService.getUserInfo(); const authInfo = await userService.getUserInfo();
const envDbContent = getFileContentByName(config.envDbFile); const envCount = await EnvModel.count();
let isInitialized = true; let isInitialized = true;
if ( if (
Object.keys(authInfo).length === 2 && Object.keys(authInfo).length === 2 &&
authInfo.username === 'admin' && authInfo.username === 'admin' &&
authInfo.password === 'admin' && authInfo.password === 'admin' &&
envDbContent.length === 0 envCount === 0
) { ) {
isInitialized = false; isInitialized = false;
} }

View File

@ -5,13 +5,15 @@ import Logger from './logger';
import { fileExist } from '../config/util'; import { fileExist } from '../config/util';
const rootPath = process.cwd(); const rootPath = process.cwd();
const confFile = path.join(rootPath, 'config/config.sh'); const dataPath = path.join(rootPath, 'data/');
const sampleConfigFile = path.join(rootPath, 'sample/config.sample.sh'); const configPath = path.join(dataPath, 'config/');
const sampleAuthFile = path.join(rootPath, 'sample/auth.sample.json'); const scriptPath = path.join(dataPath, 'scripts/');
const authConfigFile = path.join(rootPath, 'config/auth.json'); const logPath = path.join(dataPath, 'log/');
const configPath = path.join(rootPath, 'config/'); const samplePath = path.join(rootPath, 'sample/');
const scriptPath = path.join(rootPath, 'scripts/'); const confFile = path.join(configPath, 'config.sh');
const logPath = path.join(rootPath, 'log/'); const authConfigFile = path.join(configPath, 'auth.json');
const sampleConfigFile = path.join(samplePath, 'config.sample.sh');
const sampleAuthFile = path.join(samplePath, 'auth.sample.json');
export default async () => { export default async () => {
const authFileExist = await fileExist(authConfigFile); const authFileExist = await fileExist(authConfigFile);

View File

@ -3,12 +3,7 @@ services:
web: web:
image: whyour/qinglong:latest image: whyour/qinglong:latest
volumes: volumes:
- ./data/config:/ql/config - ./data:/ql/data
- ./data/log:/ql/log
- ./data/db:/ql/db
- ./data/scripts:/ql/scripts
- ./data/repo:/ql/repo
- ./data/raw:/ql/raw
ports: ports:
- "0.0.0.0:5700:5700" - "0.0.0.0:5700:5700"
restart: unless-stopped restart: unless-stopped

View File

@ -22,12 +22,12 @@ echo -e "nginx启动成功...\n"
echo -e "======================4. 启动控制面板========================\n" echo -e "======================4. 启动控制面板========================\n"
pm2 delete panel &>/dev/null pm2 delete panel &>/dev/null
pm2 start $dir_root/build/app.js -n panel --source-map-support --time pm2 start $dir_static/build/app.js -n panel --source-map-support --time
echo -e "控制面板启动成功...\n" echo -e "控制面板启动成功...\n"
echo -e "======================5. 启动定时任务========================\n" echo -e "======================5. 启动定时任务========================\n"
pm2 delete schedule &>/dev/null pm2 delete schedule &>/dev/null
pm2 start $dir_root/build/schedule.js -n schedule --source-map-support --time pm2 start $dir_static/build/schedule.js -n schedule --source-map-support --time
echo -e "定时任务启动成功...\n" echo -e "定时任务启动成功...\n"
if [[ $AutoStartBot == true ]]; then if [[ $AutoStartBot == true ]]; then

View File

@ -9,7 +9,7 @@ map $http_upgrade $connection_upgrade {
server { server {
listen 5700; listen 5700;
root /ql/dist; root /ql/static/dist;
ssl_session_timeout 5m; ssl_session_timeout 5m;
location /api { location /api {

View File

@ -6,8 +6,8 @@
"start:back": "nodemon", "start:back": "nodemon",
"build:front": "umi build", "build:front": "umi build",
"build:back": "tsc -p tsconfig.back.json", "build:back": "tsc -p tsconfig.back.json",
"panel": "npm run build:back && node build/app.js", "panel": "npm run build:back && node static/build/app.js",
"schedule": "npm run build:back && node build/schedule.js", "schedule": "npm run build:back && node static/build/schedule.js",
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'", "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
"prepare": "umi generate tmp", "prepare": "umi generate tmp",
"test": "umi-test", "test": "umi-test",
@ -42,7 +42,6 @@
"iconv-lite": "^0.6.3", "iconv-lite": "^0.6.3",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"nedb": "^1.8.0",
"node-fetch": "^2.6.1", "node-fetch": "^2.6.1",
"node-schedule": "^2.0.0", "node-schedule": "^2.0.0",
"nodemailer": "^6.7.0", "nodemailer": "^6.7.0",
@ -67,7 +66,6 @@
"@types/express-jwt": "^6.0.1", "@types/express-jwt": "^6.0.1",
"@types/jsonwebtoken": "^8.5.0", "@types/jsonwebtoken": "^8.5.0",
"@types/lodash": "^4.14.170", "@types/lodash": "^4.14.170",
"@types/nedb": "^1.8.11",
"@types/node": "^14.11.2", "@types/node": "^14.11.2",
"@types/node-fetch": "^2.5.8", "@types/node-fetch": "^2.5.8",
"@types/node-schedule": "^1.3.2", "@types/node-schedule": "^1.3.2",

View File

@ -38,10 +38,10 @@ reload_pm2() {
pm2 l &>/dev/null pm2 l &>/dev/null
pm2 delete panel --source-map-support --time &>/dev/null pm2 delete panel --source-map-support --time &>/dev/null
pm2 start $dir_root/build/app.js -n panel --source-map-support --time &>/dev/null pm2 start $dir_static/build/app.js -n panel --source-map-support --time &>/dev/null
pm2 delete schedule --source-map-support --time &>/dev/null pm2 delete schedule --source-map-support --time &>/dev/null
pm2 start $dir_root/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
} }
pm2_log() { pm2_log() {

View File

@ -1,4 +1,4 @@
const notify = require('/ql/scripts/sendNotify.js'); const notify = require('/ql/data/scripts/sendNotify.js');
const title = process.argv[2]; const title = process.argv[2];
const content = process.argv[3]; const content = process.argv[3];

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
#author:spark thanks to: https://github.com/sparkssssssss/scripts #author:spark thanks to: https://github.com/sparkssssssss/scripts
. /ql/config/config.sh . /ql/data/config/config.sh
title=$(echo $1|sed 's/-/_/g') title=$(echo $1|sed 's/-/_/g')
msg=$(echo -e $2) msg=$(echo -e $2)

View File

@ -2,15 +2,17 @@
## 目录 ## 目录
dir_root=/ql dir_root=/ql
dir_data=$dir_root/data
dir_shell=$dir_root/shell dir_shell=$dir_root/shell
dir_sample=$dir_root/sample dir_sample=$dir_root/sample
dir_config=$dir_root/config dir_static=$dir_root/static
dir_scripts=$dir_root/scripts dir_config=$dir_data/config
dir_repo=$dir_root/repo dir_scripts=$dir_data/scripts
dir_raw=$dir_root/raw dir_repo=$dir_data/repo
dir_log=$dir_root/log dir_raw=$dir_data/raw
dir_db=$dir_root/db dir_log=$dir_data/log
dir_dep=$dir_root/deps dir_db=$dir_data/db
dir_dep=$dir_data/deps
dir_list_tmp=$dir_log/.tmp dir_list_tmp=$dir_log/.tmp
dir_code=$dir_log/code dir_code=$dir_log/code
dir_update_log=$dir_log/update dir_update_log=$dir_log/update

View File

@ -271,9 +271,9 @@ update_qinglong() {
echo -e "\n更新$ql_static_repo成功...\n" echo -e "\n更新$ql_static_repo成功...\n"
local static_version=$(cat /ql/src/version.ts | perl -pe "s|.*\'(.*)\';\.*|\1|" | head -1) local static_version=$(cat /ql/src/version.ts | perl -pe "s|.*\'(.*)\';\.*|\1|" | head -1)
echo -e "\n当前版本 $static_version...\n" echo -e "\n当前版本 $static_version...\n"
cd $dir_root
rm -rf $dir_root/build && rm -rf $dir_root/dist rm -rf $dir_static
cp -rf $ql_static_repo/* $dir_root cp -rf $ql_static_repo/* $dir_static
if [[ $no_restart != "no-restart" ]]; then if [[ $no_restart != "no-restart" ]]; then
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
echo -e "重启面板中..." echo -e "重启面板中..."
@ -307,10 +307,10 @@ reload_pm2() {
pm2 l &>/dev/null pm2 l &>/dev/null
pm2 delete panel --source-map-support --time &>/dev/null pm2 delete panel --source-map-support --time &>/dev/null
pm2 start $dir_root/build/app.js -n panel --source-map-support --time &>/dev/null pm2 start $dir_static/build/app.js -n panel --source-map-support --time &>/dev/null
pm2 delete schedule --source-map-support --time &>/dev/null pm2 delete schedule --source-map-support --time &>/dev/null
pm2 start $dir_root/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
} }
## 对比脚本 ## 对比脚本

View File

@ -367,8 +367,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
const goToScriptManager = (record: any) => { const goToScriptManager = (record: any) => {
const cmd = record.command.split(' ') as string[]; const cmd = record.command.split(' ') as string[];
if (cmd[0] === 'task') { if (cmd[0] === 'task') {
if (cmd[1].startsWith('/ql/scripts')) { if (cmd[1].startsWith('/ql/data/scripts')) {
cmd[1] = cmd[1].replace('/ql/scripts/', ''); cmd[1] = cmd[1].replace('/ql/data/scripts/', '');
} }
let [p, s] = cmd[1].split('/'); let [p, s] = cmd[1].split('/');

View File

@ -15,7 +15,7 @@
"module": "commonjs", "module": "commonjs",
"pretty": true, "pretty": true,
"sourceMap": true, "sourceMap": true,
"outDir": "./build", "outDir": "./static/build",
"allowJs": true, "allowJs": true,
"noEmit": false, "noEmit": false,
"esModuleInterop": true "esModuleInterop": true

View File

@ -32,7 +32,8 @@
"node_modules", "node_modules",
"lib", "lib",
"es", "es",
"dist", "static",
"data",
"typings", "typings",
"**/__test__", "**/__test__",
"test", "test",