diff --git a/.env b/.env.sample similarity index 69% rename from .env rename to .env.sample index 374a53f..43ffda4 100644 --- a/.env +++ b/.env.sample @@ -4,4 +4,8 @@ secretKey='Putong Putong Putong' dbURL='mongodb://127.0.0.1:27017/oj' redisURL='redis://127.0.0.1:6379' +title='Putong OJ' +discussOnProblem=true +semiRestful=false + PORT=3000 diff --git a/.gitignore b/.gitignore index 63138be..57f7286 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,11 @@ docker-compose.debug.yml +.env +data/* +!data/example # customary .tern-project requests/ -data/* -!data/1000 migrations/db migrations/backup !migrations/db/.gitkeep diff --git a/README.md b/README.md index cc1efed..9745fa6 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,13 @@ Currently Not available git clone https://github.com/acm309/PutongOJ.git PutongOJ ``` -2. compose up +2. 配置环境变量 + +```bash +mv .env.sample .env +``` + +3. compose up ```bash docker-compose up @@ -80,27 +86,22 @@ npm i -g pnpm pnpm i ``` -5. 尝试连接数据库 - -设置环境变量 +5. 配置环境变量 ```bash -export redisURL='your redis url' -export dbURL='your mongodb url' +mv .env.sample .env ``` -更新 `config/index.js` - -```js -const prod = { - port: 3000 // the port the application will listen on -} +```bash +redisURL='your redis url' +dbURL='your mongodb url' +port=3000 #the port the application will listen on ``` 6. 下载静态文件和启动判题端 ```bash -node manager.js +node manager.js setup ``` `pm2.config.json` 会自动生成. diff --git a/config/index.js b/config/index.js index 3ecc9fb..f52796f 100644 --- a/config/index.js +++ b/config/index.js @@ -48,7 +48,7 @@ config.deploy = { adminInitPwd: 'kplkplkpl', } -config.secretKey = process.env.secretKey +config.secretKey = process.env.secretKey || '' config.dbURL = process.env.DBURL || process.env.dbURL // 之所以两个只为了兼容旧版命名;请优先采用后者 @@ -65,7 +65,7 @@ config.mail = { } config.port = Number.parseInt( - process.env.PORT, + process.env.PORT || 3000, ) module.exports = config diff --git a/config/website.js b/config/website.js index 660c306..cd77481 100644 --- a/config/website.js +++ b/config/website.js @@ -1,7 +1,9 @@ +const process = require('node:process') + module.exports = { - title: 'Putong OJ', - discussOnProblem: true, - semi_restful: false, + title: process.env.title || 'Putong OJ', + discussOnProblem: (process.env.discussOnProblem || 'false').toLocaleLowerCase() === 'true', + semi_restful: (process.env.semiRestful || 'false').toLocaleLowerCase() === 'true', } /** diff --git a/data/1000/657a2950-e753-11e7-b5d5-acbc32d0fe0d.in b/data/example/657a2950-e753-11e7-b5d5-acbc32d0fe0d.in similarity index 100% rename from data/1000/657a2950-e753-11e7-b5d5-acbc32d0fe0d.in rename to data/example/657a2950-e753-11e7-b5d5-acbc32d0fe0d.in diff --git a/data/1000/657a2950-e753-11e7-b5d5-acbc32d0fe0d.out b/data/example/657a2950-e753-11e7-b5d5-acbc32d0fe0d.out similarity index 100% rename from data/1000/657a2950-e753-11e7-b5d5-acbc32d0fe0d.out rename to data/example/657a2950-e753-11e7-b5d5-acbc32d0fe0d.out diff --git a/data/1000/README.md b/data/example/README.md similarity index 100% rename from data/1000/README.md rename to data/example/README.md diff --git a/data/1000/aaa8a3d0-e753-11e7-83cc-9f6f17c0d58c.in b/data/example/aaa8a3d0-e753-11e7-83cc-9f6f17c0d58c.in similarity index 100% rename from data/1000/aaa8a3d0-e753-11e7-83cc-9f6f17c0d58c.in rename to data/example/aaa8a3d0-e753-11e7-83cc-9f6f17c0d58c.in diff --git a/data/1000/aaa8a3d0-e753-11e7-83cc-9f6f17c0d58c.out b/data/example/aaa8a3d0-e753-11e7-83cc-9f6f17c0d58c.out similarity index 100% rename from data/1000/aaa8a3d0-e753-11e7-83cc-9f6f17c0d58c.out rename to data/example/aaa8a3d0-e753-11e7-83cc-9f6f17c0d58c.out diff --git a/data/1000/ac/2.cpp b/data/example/ac/2.cpp similarity index 100% rename from data/1000/ac/2.cpp rename to data/example/ac/2.cpp diff --git a/data/1000/meta.json b/data/example/meta.json similarity index 100% rename from data/1000/meta.json rename to data/example/meta.json diff --git a/manage.js b/manage.js index 8fceed7..4803695 100644 --- a/manage.js +++ b/manage.js @@ -7,8 +7,11 @@ const range = require('lodash.range') // DO not upgrade execa to v6.0.0 as it is esm module const { command: execaCommand } = require('execa') const fetch = require('node-fetch') +const { Command } = require('commander') const config = require('./config') +const program = new Command() + // download and initialize the judgers // start ! @@ -101,7 +104,7 @@ async function judgeSetup () { return fse.outputJSON('pm2.config.json', pm2config, { spaces: 2, EOL: '\n' }) } -async function staticFilesSetUp () { +async function staticFilesSetup () { const res = await fetch('https://api.github.com/repos/acm309/PutongOJ-FE/releases') const json = await res.json() const url = json[0].assets[0].browser_download_url @@ -112,19 +115,40 @@ async function staticFilesSetUp () { }) } -function main () { - return Promise.all([ - judgeSetup(), - staticFilesSetUp(), - ]) +async function exampleProblemSetup () { + fse.move('data/example', 'data/1000') } -main() - .then(() => { - console.log('ok') - process.exit(0) +program.command('setup') + .action(() => { + console.log('setup...') + Promise.all([ + exampleProblemSetup(), + judgeSetup(), + staticFilesSetup(), + ]) + .then(() => { + console.log('ok') + process.exit(0) + }) + .catch((err) => { + console.error(err) + process.exit(-1) + }) }) - .catch((err) => { - console.error(err) - process.exit(-1) + +program.command('update-fe') + .action(() => { + console.log('updating fe...') + staticFilesSetup() + .then(() => { + console.log('ok') + process.exit(0) + }) + .catch((err) => { + console.error(err) + process.exit(-1) + }) }) + +program.parse() diff --git a/package.json b/package.json index 5bbd3c4..4447087 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "deploy:init": "cross-env NODE_ENV=production node manage.js", "deploy:start": "npx pm2 start pm2.config.json", "pretest": "cross-env NODE_ENV=test node test/pretest.js", - "test": "cross-env NODE_ENV=test node test/pretest.js && nyc ava && node test/posttest.js", + "test": "cross-env-shell NODE_ENV=test \"node test/pretest.js && nyc ava && node test/posttest.js\"", "report": "nyc report --reporter=html", "posttest": "cross-env NODE_ENV=test node test/posttest.js", "lint": "eslint .", @@ -67,6 +67,7 @@ "devDependencies": { "ava": "^4.3.3", "codecov": "^3.8.3", + "commander": "^12.1.0", "eslint-config-standard": "^11.0.0", "eslint-plugin-import": "^2.30.0", "eslint-plugin-node": "^6.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 778cc51..c3caf14 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,6 +105,9 @@ importers: codecov: specifier: ^3.8.3 version: 3.8.3 + commander: + specifier: ^12.1.0 + version: 12.1.0 eslint-config-standard: specifier: ^11.0.0 version: 11.0.0(eslint-plugin-import@2.30.0(@typescript-eslint/parser@8.7.0(eslint@8.57.1)(typescript@4.9.5))(eslint@8.57.1))(eslint-plugin-node@6.0.1(eslint@8.57.1))(eslint-plugin-promise@3.8.0)(eslint-plugin-standard@3.1.0(eslint@8.57.1))(eslint@8.57.1) @@ -1316,6 +1319,10 @@ packages: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} + commander@12.1.0: + resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==} + engines: {node: '>=18'} + commander@2.15.1: resolution: {integrity: sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==} @@ -6379,6 +6386,8 @@ snapshots: dependencies: delayed-stream: 1.0.0 + commander@12.1.0: {} + commander@2.15.1: {} comment-parser@1.4.1: {}