调整数据目录

This commit is contained in:
whyour 2022-02-19 13:08:14 +08:00
parent 903007e6ca
commit cf5f1b6f25
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_BRANCH: ${{ github.ref_name }}
run: |
mkdir -p static
cd ./static
cp -rf ../dist ./ && cp -rf ../build ./
mkdir -p tmp
cd ./tmp
cp -rf ../static ./
git init -b ${GITHUB_BRANCH} && git add .
git config --local user.name 'github-actions[bot]'
git config --local user.email 'github-actions[bot]@users.noreply.github.com'

4
.gitignore vendored
View File

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

View File

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

View File

@ -56,12 +56,7 @@ sudo curl -sSL get.docker.com | sh
```bash
docker run -dit \
-v $PWD/ql/config:/ql/config \
-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 \
-v $PWD/ql:/ql/data \
-p 5700:5700 \
--name qinglong \
--hostname qinglong \

View File

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

View File

@ -9,27 +9,26 @@ const lastVersionFile =
const envFound = dotenv.config();
const rootPath = process.cwd();
const envFile = path.join(rootPath, 'config/env.sh');
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 dataPath = path.join(rootPath, 'data/');
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 loginFaild = '请先登录!';
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');
if (envFound.error) {
@ -59,11 +58,6 @@ export default {
confFile,
envFile,
dbPath,
cronDbFile,
envDbFile,
appDbFile,
authDbFile,
dependenceDbFile,
configPath,
scriptPath,
samplePath,
@ -86,4 +80,5 @@ export default {
],
versionFile,
lastVersionFile,
sqliteFile,
};

View File

@ -1,7 +1,4 @@
import DataStore from 'nedb';
import config from '../config';
import Logger from './logger';
import { fileExist } from '../config/util';
import { EnvModel } from '../data/env';
import { CrontabModel } from '../data/cron';
import { DependenceModel } from '../data/dependence';
@ -12,7 +9,11 @@ import { sequelize } from '../data';
export default async () => {
try {
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 {
// 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');
} catch (error) {
Logger.info('✌️ DB load failed');

View File

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

View File

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

View File

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

View File

@ -22,12 +22,12 @@ echo -e "nginx启动成功...\n"
echo -e "======================4. 启动控制面板========================\n"
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 "======================5. 启动定时任务========================\n"
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"
if [[ $AutoStartBot == true ]]; then

View File

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

View File

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

View File

@ -38,10 +38,10 @@ reload_pm2() {
pm2 l &>/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 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() {

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 content = process.argv[3];

View File

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

View File

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

View File

@ -271,9 +271,9 @@ update_qinglong() {
echo -e "\n更新$ql_static_repo成功...\n"
local static_version=$(cat /ql/src/version.ts | perl -pe "s|.*\'(.*)\';\.*|\1|" | head -1)
echo -e "\n当前版本 $static_version...\n"
cd $dir_root
rm -rf $dir_root/build && rm -rf $dir_root/dist
cp -rf $ql_static_repo/* $dir_root
rm -rf $dir_static
cp -rf $ql_static_repo/* $dir_static
if [[ $no_restart != "no-restart" ]]; then
nginx -s reload 2>/dev/null || nginx -c /etc/nginx/nginx.conf
echo -e "重启面板中..."
@ -307,10 +307,10 @@ reload_pm2() {
pm2 l &>/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 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 cmd = record.command.split(' ') as string[];
if (cmd[0] === 'task') {
if (cmd[1].startsWith('/ql/scripts')) {
cmd[1] = cmd[1].replace('/ql/scripts/', '');
if (cmd[1].startsWith('/ql/data/scripts')) {
cmd[1] = cmd[1].replace('/ql/data/scripts/', '');
}
let [p, s] = cmd[1].split('/');

View File

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

View File

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