diff --git a/script/package/index.mjs b/config/package/index.mjs similarity index 100% rename from script/package/index.mjs rename to config/package/index.mjs diff --git a/script/package/package.json b/config/package/package.json similarity index 100% rename from script/package/package.json rename to config/package/package.json diff --git a/script/release/generate-token.mjs b/config/release/generate-token.mjs similarity index 100% rename from script/release/generate-token.mjs rename to config/release/generate-token.mjs diff --git a/script/release/index.mjs b/config/release/index.mjs similarity index 88% rename from script/release/index.mjs rename to config/release/index.mjs index c9eee8b..c61307f 100644 --- a/script/release/index.mjs +++ b/config/release/index.mjs @@ -22,7 +22,7 @@ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); const releasePath = path.join(cwd, 'release'); const distPath = path.join(cwd, 'dist'); - +const scriptPath = path.join(cwd, 'script'); const zip = archiver('zip', { zlib: { level: 9 }, }); @@ -68,9 +68,15 @@ const getZip = async () => { npm i -g pnpm pnpm install --prod `; - zip.append(sh, { name: 'start.sh' }); + zip.append(sh, { + name: 'start.sh', + //类型是可执行文件 + mode: 0o755, + }); // 把dist目录下的文件添加到zip中 zip.directory(distPath, 'dist'); + zip.directory(scriptPath, 'script'); + // 把README.md添加到zip中 zip.file(path.join(cwd, 'README.md'), { name: 'README.md' }); // 把package.json添加到zip中 @@ -92,15 +98,15 @@ const getZip = async () => { } `; zip.append(ecosystemContent, { name: 'ecosystem.config.cjs' }); - const json5Content = fs.readFileSync(path.join(cwd, 'app.config.json5.example'), 'utf8'); + let json5Content = fs.readFileSync(path.join(cwd, 'app.config.json5.example'), 'utf8'); // tokenSecret 是一个随机字符串,用于生成 token - const tokenSecret = 'XX' + nanoid(39); - json5Content.replace('', tokenSecret); + let tokenSecret = 'XX' + nanoid(39); + json5Content = json5Content.replace('', tokenSecret); // tokenSecret // 把app.config.json5.example添加到zip中 // zip.file(path.join(cwd, 'app.config.json5.example'), { name: 'app.config.json5.example' }); zip.append(json5Content, { name: 'app.config.json5.example' }); - + zip.append('version-check', { name: `version-check-${pkg.version}` }); // 结束归档(必须调用,否则 zip 文件无法完成) zip.finalize(); }); @@ -112,5 +118,4 @@ getZip().then(() => { console.log(`envision switch system && envision deploy ./release/${zipName} -v 1.0.0 -k code-center -y y -u`); console.log(`download zip:\n\ncurl -O https://kevisual.xiongxiao.me/system/code-center/${zipName} && unzip ${zipName}`); - }); diff --git a/package.json b/package.json index cd1e52c..f317610 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/code-center", - "version": "0.0.4", + "version": "0.0.5-alpha.2", "description": "code center", "type": "module", "main": "index.js", @@ -16,7 +16,7 @@ "reload": "ssh light pm2 restart codecenter", "pub": "npm run build && npm run deploy && npm run reload", "start": "pm2 start dist/app.mjs --name codecenter", - "release": "node ./script/release/index.mjs" + "release": "node ./config/release/index.mjs" }, "keywords": [], "types": "types/index.d.ts", @@ -29,7 +29,7 @@ "dependencies": { "@kevisual/auth": "1.0.5", "@kevisual/local-app-manager": "0.1.9", - "@kevisual/router": "^0.0.6", + "@kevisual/router": "^0.0.7", "@kevisual/use-config": "^1.0.8", "@types/semver": "^7.5.8", "archiver": "^7.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e9fc5d6..c694d50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,13 +18,13 @@ importers: version: 1.0.5 '@kevisual/local-app-manager': specifier: 0.1.9 - version: 0.1.9(@kevisual/router@0.0.6)(@kevisual/types@0.0.6)(@kevisual/use-config@1.0.7)(pm2@5.4.3) + version: 0.1.9(@kevisual/router@0.0.7)(@kevisual/types@0.0.6)(@kevisual/use-config@1.0.8)(pm2@5.4.3) '@kevisual/router': - specifier: ^0.0.6 - version: 0.0.6 + specifier: ^0.0.7 + version: 0.0.7 '@kevisual/use-config': - specifier: ^1.0.7 - version: 1.0.7 + specifier: ^1.0.8 + version: 1.0.8 '@types/semver': specifier: ^7.5.8 version: 7.5.8 @@ -356,14 +356,14 @@ packages: '@kevisual/use-config': ^1.0.5 pm2: ^5.4.3 - '@kevisual/router@0.0.6': - resolution: {integrity: sha512-7FQUY87Zy5A4V30OAggRbGpO/Asd7SUpnhHv8mlxnSFFTto25xpXmjHYp12mu/HJTsHM7RTaxVEyD1DeP44D2A==} + '@kevisual/router@0.0.7': + resolution: {integrity: sha512-4n1Tp4YLoraJv7jtfy7jbuLGyAj0B2QkTlnlEDHCUTlEUOvOkjtf7DHAe2SL92fTgXhSbod0I/0vUcDF85oj/w==} '@kevisual/types@0.0.6': resolution: {integrity: sha512-7yxe1QmuC5g7lI/1Hm+zXly8if0z+ZqGM1SVOVv2VNRwRAVYBJDc365zWCCfRwE+5YaB2daWTe5zBOU4EkltkQ==} - '@kevisual/use-config@1.0.7': - resolution: {integrity: sha512-Ft1NICwj4NonnAnmEUMlh3tWi1GTcEtWaybg6Kv0j3+ZSp6d1v1HEXmiZvotGHkCQm6X8JSYdOeqILjOZYpERg==} + '@kevisual/use-config@1.0.8': + resolution: {integrity: sha512-eobq7Ex61dV7k9buKIaBffoUgBwWSZu4/LBlAVS611spVqugQDrl8fx/F3tG3obNjKtMSNRkwrn78L9SIEuFJA==} '@ljharb/resumer@0.1.3': resolution: {integrity: sha512-d+tsDgfkj9X5QTriqM4lKesCkMMJC3IrbPKHvayP00ELx2axdXvDfWkqjxrLXIzGcQzmj7VAUT1wopqARTvafw==} @@ -2562,14 +2562,14 @@ snapshots: '@kevisual/auth@1.0.5': {} - '@kevisual/local-app-manager@0.1.9(@kevisual/router@0.0.6)(@kevisual/types@0.0.6)(@kevisual/use-config@1.0.7)(pm2@5.4.3)': + '@kevisual/local-app-manager@0.1.9(@kevisual/router@0.0.7)(@kevisual/types@0.0.6)(@kevisual/use-config@1.0.8)(pm2@5.4.3)': dependencies: - '@kevisual/router': 0.0.6 + '@kevisual/router': 0.0.7 '@kevisual/types': 0.0.6 - '@kevisual/use-config': 1.0.7 + '@kevisual/use-config': 1.0.8 pm2: 5.4.3 - '@kevisual/router@0.0.6': + '@kevisual/router@0.0.7': dependencies: path-to-regexp: 8.2.0 selfsigned: 2.4.1 @@ -2580,7 +2580,7 @@ snapshots: '@kevisual/types@0.0.6': {} - '@kevisual/use-config@1.0.7': {} + '@kevisual/use-config@1.0.8': {} '@ljharb/resumer@0.1.3': dependencies: diff --git a/scripts/update.sh b/scripts/update.sh new file mode 100644 index 0000000..3c95ce1 --- /dev/null +++ b/scripts/update.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +pnpm i -g npm-check-updates +ncu -u +pnpm install \ No newline at end of file diff --git a/src/route.ts b/src/route.ts index 7ac46c8..3545423 100644 --- a/src/route.ts +++ b/src/route.ts @@ -15,24 +15,35 @@ app path: 'auth', key: 'admin', id: 'auth-admin', + isDebug: true, middleware: ['auth'], }) .define(async (ctx) => { const tokenUser = ctx.state.tokenUser; - const user = await User.findOne({ - where: { - id: tokenUser.id, - }, - }); - if (!user) { - ctx.throw(404, 'user not found'); + if (!tokenUser) { + ctx.throw(401, 'No User For authorized'); } - const orgs = await user.getOrgs(); + try { + const user = await User.findOne({ + where: { + id: tokenUser.id, + }, + }); + if (!user) { + ctx.throw(404, 'user not found'); + } + user.setTokenUser(tokenUser); + const orgs = await user.getOrgs(); - if (orgs.includes('admin')) { - ctx.body = 'admin'; - } else { - ctx.throw(403, 'forbidden'); + if (orgs.includes('admin')) { + ctx.body = 'admin'; + ctx.nextQuery = ctx.query; + } else { + ctx.throw(403, 'forbidden'); + } + } catch (e) { + console.error('auth-admin error', e); + ctx.throw(500, e.message); } }) .addTo(app);