-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 117503445 <[email protected]>
- Loading branch information
Showing
40 changed files
with
7,019 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM node:lts-slim AS runtime | ||
|
||
WORKDIR /workspace/GT-Manual | ||
|
||
COPY . . | ||
|
||
RUN npm install | ||
|
||
ENTRYPOINT [ "node", "app" ] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 米游社手动验证 | ||
|
||
原仓库 <https://gitee.com/QQ1146638442/GT-Manual/tree/master> | ||
|
||
* 此demo仅提供思路,可以参考demo自行编写内容至您的站点 | ||
|
||
* ~~使用Yunzai-Bot可以参考此[提交](https://gitee.com/QQ1146638442/Miao-Yunzai/commit/c286fd0627253f8790912ad5802d6da0b9192774)~~ | ||
使用Miao-Yunzai可以参考此插件[GT-Manual-plugin](https://static.hlhs-nb.cn/upload/GT-Manual-plugin.zip) | ||
若您不想部署demo或没有公网地址可以使用他人提供的公益接口 | ||
|
||
* 值得一提的是QQ不允许直接访问IP地址 | ||
需要添加域名解析或复制地址到浏览器访问 | ||
|
||
* 若外部网络无法访问地址请前往防火墙放行对应端口,具体操作需自行百度 | ||
|
||
# 测试 | ||
|
||
``` | ||
git clone https://gitee.com/QQ1146638442/GT-Manual.git | ||
cd GT-Manual | ||
npm install | ||
``` | ||
修改config.yaml配置 | ||
``` | ||
# 前台启动 | ||
node app | ||
# 后台启动 | ||
npm start | ||
# 显示log | ||
npm run log | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import server from './lib/server.js' | ||
|
||
/** 全局变量 Server */ | ||
global.Server = await server.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# 您对外显示的域名或IP地址 | ||
Host: 127.0.0.1 | ||
|
||
# 为/register添加?key=114514校验,留空则不校验 | ||
Key: '' | ||
|
||
# HTML页脚标签内容 | ||
Copyright: 'Copyright GT-Manual' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# server地址,一般不用修改 | ||
HOST: '0.0.0.0' | ||
|
||
# http端口 | ||
HTTP_PORT: 8081 | ||
# https端口 | ||
HTTPS_PORT: 443 | ||
|
||
# 使用https | ||
HTTPS: false | ||
# http重定向https | ||
HTTP_TO_HTTPS: true | ||
# ssl证书crt文件路径 | ||
CA_CERTIFICATE: './config/SSL/certificate.crt' | ||
# ssl证书key文件路径 | ||
CA_PRIVATE: './config/SSL/private.key' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# 是否连接redis | ||
open: false | ||
|
||
# redis地址 | ||
host: localhost | ||
|
||
# redis端口 | ||
port: 6379 | ||
|
||
# redis密码,没有密码请留空 | ||
password: '' | ||
|
||
# redis数据库 | ||
db: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
services: | ||
gt-manaual: | ||
image: node:lts-slim | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile | ||
ports: | ||
- "8081:8081" | ||
volumes: | ||
- ./:/workspace/GT-Manual | ||
|
||
working_dir: /workspace/GT-Manual | ||
entrypoint: bash | ||
|
||
stdin_open: true | ||
tty: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import fs from 'node:fs' | ||
import { exec } from 'node:child_process' | ||
|
||
export async function checkRun () { | ||
if (process.argv[1].includes('pm2')) return | ||
if (process.argv[1].includes('test')) return | ||
|
||
let cfg = pm2Cfg() | ||
let status = await execSync(`pm2 show ${cfg.apps[0].name}`) | ||
|
||
if (status.stdout.includes('online')) { | ||
logger.mark('检测到后台正在运行') | ||
logger.mark('已停止后台进程,防止重复运行') | ||
execSync(`pm2 stop ${cfg.apps[0].name}`) | ||
} | ||
} | ||
|
||
async function execSync (cmd) { | ||
return new Promise((resolve, reject) => { | ||
exec(cmd, (error, stdout, stderr) => { | ||
resolve({ error, stdout, stderr }) | ||
}) | ||
}) | ||
} | ||
|
||
function pm2Cfg () { | ||
let cfg = fs.readFileSync('pm2.json') | ||
cfg = JSON.parse(cfg) | ||
return cfg | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import YAML from 'yaml' | ||
import fs from 'node:fs' | ||
import chokidar from 'chokidar' | ||
|
||
/** 配置文件 */ | ||
class Cfg { | ||
/** 初始化配置 */ | ||
constructor () { | ||
let file = 'config/config.yaml' | ||
let fileDef = 'config/default_config.yaml' | ||
if (!fs.existsSync(file)) { | ||
fs.copyFileSync(fileDef, file) | ||
} | ||
if (!fs.existsSync('data')) fs.mkdirSync('data') | ||
this.config = {} | ||
} | ||
|
||
get http () { | ||
return this.getConfig('config') | ||
} | ||
|
||
get http_listen () { | ||
return [this.http.HTTPS ? this.http.HTTPS_PORT : this.http.HTTP_PORT, this.http.HOST] | ||
} | ||
|
||
https_address (originalUrl, hostname) { | ||
let Url = new URL(originalUrl, `https://${hostname}`) | ||
Url.port = this.http.HTTPS_PORT | ||
return Url.href | ||
} | ||
|
||
get redis () { | ||
return this.getConfig('redis') | ||
} | ||
|
||
get cert() { | ||
return { | ||
cert: fs.readFileSync(this.http.CA_CERTIFICATE, 'utf8'), | ||
key: fs.readFileSync(this.http.CA_PRIVATE, 'utf8') | ||
} | ||
} | ||
|
||
/** package.json */ | ||
get package () { | ||
if (this._package) return this._package | ||
|
||
this._package = JSON.parse(fs.readFileSync('package.json', 'utf8')) | ||
return this._package | ||
} | ||
|
||
/** 用户配置 */ | ||
getConfig (name) { | ||
return this.getYaml(name) | ||
} | ||
|
||
/** | ||
* 获取配置yaml | ||
* @param type 默认跑配置-defSet,用户配置-config | ||
* @param name 名称 | ||
*/ | ||
getYaml (name) { | ||
let file = `config/${name}.yaml` | ||
if (this.config[name]) return this.config[name] | ||
|
||
this.config[name] = YAML.parse( | ||
fs.readFileSync(file, 'utf8') | ||
) | ||
|
||
return this.config[name] | ||
} | ||
} | ||
|
||
export default new Cfg() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import setLog from './log.js' | ||
import cfg from "./config.js" | ||
import redisInit from './redis.js' | ||
import { checkRun } from './check.js' | ||
import fs from 'node:fs' | ||
|
||
/** 设置标题 */ | ||
process.title = cfg.package.name | ||
/** 设置时区 */ | ||
process.env.TZ = 'Asia/Shanghai' | ||
|
||
/** 捕获未处理的错误 */ | ||
process.on('uncaughtException', (error) => { | ||
let err = error | ||
if (logger) { | ||
logger.error(err) | ||
} else { | ||
console.log(err) | ||
} | ||
}) | ||
|
||
/** 捕获未处理的Promise错误 */ | ||
process.on('unhandledRejection', (error, promise) => { | ||
let err = error | ||
if (logger) { | ||
logger.error(err) | ||
} else { | ||
console.log(err) | ||
} | ||
}) | ||
|
||
/** 退出事件 */ | ||
process.on('exit', async (code) => { | ||
if (typeof redis != 'undefined' && typeof test == 'undefined') { | ||
await redis.save() | ||
} | ||
}) | ||
|
||
await checkInit() | ||
|
||
/** 初始化事件 */ | ||
async function checkInit () { | ||
/** 检查node_modules */ | ||
if (!fs.existsSync('./node_modules') || !fs.existsSync('./node_modules/express')) { | ||
console.log('请先pnpm install -P安装') | ||
process.exit() | ||
} | ||
|
||
/** 日志设置 */ | ||
setLog() | ||
|
||
await redisInit() | ||
|
||
await checkRun() | ||
|
||
logger.info(`${cfg.package.name} 启动中...`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import log4js from 'log4js' | ||
import chalk from 'chalk' | ||
import fs from 'node:fs' | ||
|
||
/** | ||
* 设置日志样式 | ||
*/ | ||
export default function setLog () { | ||
let file = './logs' | ||
let log_level = 'info' | ||
if (!fs.existsSync(file)) { | ||
fs.mkdirSync(file) | ||
} | ||
|
||
/** 调整error日志等级 */ | ||
// log4js.levels.levels[5].level = Number.MAX_VALUE | ||
// log4js.levels.levels.sort((a, b) => a.level - b.level) | ||
|
||
log4js.configure({ | ||
appenders: { | ||
console: { | ||
type: 'console', | ||
layout: { | ||
type: 'pattern', | ||
pattern: '%[[Server][%d{hh:mm:ss}][%4.4p]%] %m' | ||
} | ||
}, | ||
command: { | ||
type: 'dateFile', // 可以是console,dateFile,file,Logstash等 | ||
filename: 'logs/command', // 将会按照filename和pattern拼接文件名 | ||
pattern: 'yyyy-MM-dd.log', | ||
numBackups: 15, | ||
alwaysIncludePattern: true, | ||
layout: { | ||
type: 'pattern', | ||
pattern: '[%d{hh:mm:ss}][%4.4p] %m' | ||
} | ||
}, | ||
error: { | ||
type: 'file', | ||
filename: 'logs/error.log', | ||
alwaysIncludePattern: true, | ||
layout: { | ||
type: 'pattern', | ||
pattern: '[%d{hh:mm:ss}][%4.4p] %m' | ||
} | ||
} | ||
}, | ||
categories: { | ||
default: { appenders: ['console'], level: log_level }, | ||
command: { appenders: ['console', 'command'], level: 'info' }, | ||
error: { appenders: ['console', 'command', 'error'], level: 'error' } | ||
} | ||
}) | ||
|
||
const defaultLogger = log4js.getLogger('message') | ||
const commandLogger = log4js.getLogger('command') | ||
const errorLogger = log4js.getLogger('error') | ||
|
||
/* eslint-disable no-useless-call */ | ||
/** 全局变量 logger */ | ||
global.logger = { | ||
trace () { | ||
defaultLogger.trace.call(defaultLogger, ...arguments) | ||
}, | ||
debug () { | ||
defaultLogger.debug.call(defaultLogger, ...arguments) | ||
}, | ||
info () { | ||
defaultLogger.info.call(commandLogger, ...arguments) | ||
}, | ||
// warn及以上的日志采用error策略 | ||
warn () { | ||
commandLogger.warn.call(defaultLogger, ...arguments) | ||
}, | ||
error () { | ||
errorLogger.error.call(errorLogger, ...arguments) | ||
}, | ||
fatal () { | ||
errorLogger.fatal.call(errorLogger, ...arguments) | ||
}, | ||
mark () { | ||
errorLogger.mark.call(commandLogger, ...arguments) | ||
} | ||
} | ||
|
||
logColor() | ||
} | ||
|
||
function logColor () { | ||
logger.chalk = chalk | ||
logger.red = chalk.red | ||
logger.green = chalk.green | ||
logger.yellow = chalk.yellow | ||
logger.blue = chalk.blue | ||
logger.magenta = chalk.magenta | ||
logger.cyan = chalk.cyan | ||
} |
Oops, something went wrong.