refactor: remove certd v1 code

This commit is contained in:
xiaojunnuo
2022-10-31 21:27:32 +08:00
parent 6094a4af79
commit e68862b633
113 changed files with 181 additions and 4868 deletions
-16
View File
@@ -1,16 +0,0 @@
module.exports = {
root: true,
parserOptions: {
sourceType: 'module',
ecmaVersion: '2020'
},
parser: 'babel-eslint',
extends: ['standard'],
env: {
node: true
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
}
-7
View File
@@ -1,7 +0,0 @@
.vscode/
node_modules/
npm-debug.log
yarn-error.log
yarn.lock
package-lock.json
/.idea/
-6
View File
@@ -1,6 +0,0 @@
FROM registry.cn-shenzhen.aliyuncs.com/greper/node:15.8.0-alpine
ENV TZ=Asia/Shanghai
EXPOSE 3000
ADD ./ /app/
RUN cd /app/ && ls
ENTRYPOINT node /app/bin/www.js
-59
View File
@@ -1,59 +0,0 @@
import Koa from 'koa'
import json from 'koa-json'
import onerror from 'koa-onerror'
import bodyparser from 'koa-bodyparser'
import logger from 'koa-logger'
import Static from 'koa-static'
import fs from 'fs'
import _ from 'lodash-es'
import './install.js'
import pathUtil from './utils/util.path.js'
import compress from 'koa-compress'
const app = new Koa()
// error handler
onerror(app)
// middlewares
app.use(bodyparser({
enableTypes: ['json', 'form', 'text']
}))
app.use(json())
app.use(logger())
// gzip
// app.use(compress({ threshold: 5120 }))
const staticPlugin = Static(pathUtil.join('public'), {
maxage: 30 * 24 * 60 * 3600,
gzip: true
})
app.use(staticPlugin)
// logger
app.use(async (ctx, next) => {
const start = new Date()
await next()
const ms = new Date() - start
console.log(`${ctx.method} ${ctx.url} - ${ms}ms`)
})
// routes
const files = fs.readdirSync(new URL('controllers/', import.meta.url))
// 过滤出.js文件:
const jsFiles = files.filter((f) => {
return f.endsWith('.js')
})
_.forEach(jsFiles, async item => {
let mapping = await import(new URL('controllers/' + item, import.meta.url))
mapping = mapping.default
app.use(mapping.routes(), mapping.allowedMethods())
})
// error-handling
app.on('error', (err, ctx) => {
console.error('server error', err, ctx)
})
console.log('http://localhost:3000/')
export default app
-93
View File
@@ -1,93 +0,0 @@
#!/usr/bin/env node
/**
* Module dependencies.
*/
import app from '../app.js';
import debuger from 'debug'
const debug = debuger('demo:serer')
// require('debug')('demo:server');
import http from 'http';
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
// app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app.callback());
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
var port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
@@ -1,16 +0,0 @@
import Router from 'koa-router'
import { accessProviderRegistry } from '@certd/api'
import _ from 'lodash-es'
import { Ret } from '../models/Ret.js'
const router = Router()
router.prefix('/api/access-providers')
router.get('/list', function (ctx, next) {
const list = []
_.forEach(accessProviderRegistry.collection, item => {
list.push(item.define())
})
ctx.body = Ret.success(list)
})
export default router
@@ -1,16 +0,0 @@
import Router from 'koa-router'
import { dnsProviderRegistry } from '@certd/api'
import _ from 'lodash-es'
import { Ret } from '../models/Ret.js'
const router = Router()
router.prefix('/api/dns-providers')
router.get('/list', function (ctx, next) {
const list = []
_.forEach(dnsProviderRegistry.collection, item => {
list.push(item.define())
})
ctx.body = Ret.success(list)
})
export default router
@@ -1,23 +0,0 @@
import Router from 'koa-router'
import fs from 'fs'
import exportsService from '../service/exports-service.js'
const router = Router()
router.prefix('/api/exports')
router.post('/toZip', async function (ctx, next) {
// const request = ctx.request
// const query = request.query
const body = ctx.request.body
// const req_queryString = request.queryString
const { zipPath, fileName } = await exportsService.exportsToZip(body.options, 'certd-run')
console.log('zipFile', zipPath)
ctx.set('Content-disposition', 'attachment;filename=' + fileName)
ctx.set('Content-Type', 'application/zip')
ctx.body = fs.createReadStream(zipPath)
//
// // ctx.body = Ret.success(zipPath)
})
export default router
@@ -1,10 +0,0 @@
import Router from 'koa-router'
const router = Router()
router.get('/api/', async (ctx, next) => {
await ctx.render('index', {
title: 'Hello CertD!'
})
})
export default router
@@ -1,16 +0,0 @@
import Router from 'koa-router'
import { pluginRegistry } from '@certd/api'
import _ from 'lodash-es'
import { Ret } from '../models/Ret.js'
const router = Router()
router.prefix('/api/plugins')
router.get('/list', function (ctx, next) {
const list = []
_.forEach(pluginRegistry.collection, item => {
list.push(item.define())
})
ctx.body = Ret.success(list)
})
export default router
-8
View File
@@ -1,8 +0,0 @@
import PluginAliyun from '@certd/plugin-aliyun'
import PluginTencent from '@certd/plugin-tencent'
import PluginHost from '@certd/plugin-host'
// 安装默认插件和授权提供者
PluginAliyun.install()
PluginTencent.install()
PluginHost.install()
-15
View File
@@ -1,15 +0,0 @@
export class Ret {
constructor (code = 0, msg, data) {
this.code = code
this.msg = msg
this.data = data
}
static success (data) {
return new Ret(0, '', data)
}
static error (msg) {
return new Ret(1, msg)
}
}
-43
View File
@@ -1,43 +0,0 @@
{
"name": "@certd/server",
"version": "0.2.2",
"private": false,
"type": "module",
"scripts": {
"start": "node bin/www.js",
"dev": "./node_modules/.bin/nodemon bin/www.js",
"prd": "pm2 start bin/www.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@certd/api": "^0.3.0",
"@certd/executor": "^0.3.0",
"@certd/plugin-aliyun": "^0.3.0",
"@certd/plugin-host": "^0.3.0",
"@certd/plugin-tencent": "^0.3.0",
"compressing": "^1.5.1",
"debug": "^4.1.1",
"fs-extra": "^9.1.0",
"koa": "^2.7.0",
"koa-bodyparser": "^4.2.1",
"koa-compress": "^5.0.1",
"koa-convert": "^1.2.0",
"koa-json": "^2.0.2",
"koa-logger": "^3.2.0",
"koa-onerror": "^4.1.0",
"koa-router": "^7.4.0",
"koa-static": "^5.0.0",
"koa-views": "^6.2.0",
"lodash-es": "^4.17.20"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.19.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"nodemon": "^1.19.1"
},
"gitHead": "5fbd7742665c0a949333d805153e9b6af91c0a71"
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

@@ -1,17 +0,0 @@
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="500" height="500" viewBox="0 0 500.000000 500.000000"
>
<path d="M28.34 56.68h28.34V36.12H28.34a7.79 7.79 0 1 1 0-15.58h19.84v9.05h8.5V12H28.34a16.29 16.29 0 0 0 0 32.58h19.84v3.56H28.34a19.84 19.84 0 0 1 0-39.68h28.34V0H28.34a28.34 28.34 0 0 0 0 56.68z"
fill="#2c3e50"
transform="translate(124, 60) scale(4,4)"
></path>
<path d="M13.00-21.91L21.24-21.91L21.24-17.23L14.04-17.23Q10.39-17.23 9-15.62L9-15.62Q7.65-14.08 7.65-10.93L7.65-10.93Q7.65-7.42 9.86-5.80L9.86-5.80Q10.75-5.17 11.81-4.93Q12.87-4.68 14.76-4.68L14.76-4.68L21.24-4.68L21.24 0L13.00 0Q9.67 0 7.74-0.67Q5.80-1.35 4.32-3.01L4.32-3.01Q1.48-6.17 1.48-11.03L1.48-11.03Q1.48-16.88 4.86-19.75L4.86-19.75Q6.21-20.93 8.10-21.42Q9.99-21.91 13.00-21.91L13.00-21.91ZM31.05-13.32L43.74-13.32L43.74-8.64L31.05-8.64Q31.23-6.48 32.44-5.58Q33.66-4.68 36.41-4.68L36.41-4.68L43.74-4.68L43.74 0L35.73 0Q33.12 0 31.48-0.47Q29.83-0.94 28.39-2.02L28.39-2.02Q24.39-5.13 24.39-11.25L24.39-11.25Q24.39-15.21 26.50-18.18L26.50-18.18Q27.94-20.20 29.97-21.06Q31.99-21.91 35.28-21.91L35.28-21.91L43.74-21.91L43.74-17.23L35.73-17.23Q33.25-17.23 32.27-16.40Q31.27-15.57 31.05-13.32L31.05-13.32ZM48.64 0L48.64-21.91L57.55-21.91Q60.30-21.91 61.81-21.53Q63.31-21.15 64.31-20.25L64.31-20.25Q65.30-19.35 65.70-18Q66.10-16.65 66.10-14.13L66.10-14.13L66.10-12.01L60.30-12.01L60.30-13.18Q60.30-15.52 59.49-16.38Q58.68-17.23 56.38-17.23L56.38-17.23L54.67-17.23L54.67 0L48.64 0ZM67.50-21.91L71.33-21.91L71.33-30.02L77.36-30.02L77.36-21.91L82.94-21.91L82.94-17.23L77.36-17.23L77.36-9.27Q77.36-6.48 77.85-5.76L77.85-5.76Q78.61-4.68 80.55-4.68L80.55-4.68L82.94-4.68L82.94 0L78.57 0Q74.66 0 72.99-1.89Q71.33-3.78 71.33-8.23L71.33-8.23L71.33-17.23L67.50-17.23L67.50-21.91ZM96.08-21.91L101.75-21.91L101.75-30.02L107.73-30.02L107.73 0L97.38 0Q94.23 0 92.61-0.49L92.61-0.49Q88.78-1.71 86.90-5.26L86.90-5.26Q85.59-7.65 85.59-11.12L85.59-11.12Q85.59-16.74 89.37-19.84L89.37-19.84Q91.84-21.91 96.08-21.91L96.08-21.91ZM97.38-4.68L101.75-4.68L101.75-17.23L97.38-17.23Q94.50-17.23 93.02-15.30L93.02-15.30Q91.71-13.68 91.71-11.12L91.71-11.12Q91.71-7.38 93.87-5.76L93.87-5.76Q95.36-4.68 97.38-4.68L97.38-4.68Z"
fill="#2c3e50"
transform="translate(28, 430) scale(4,4)"
></path>
</svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

@@ -1,55 +0,0 @@
import os from 'os'
import fs from 'fs-extra'
import pathUtil from '../utils/util.path.js'
import cryptoRandomString from 'crypto-random-string'
import zipUtil from '../utils/util.zip.js'
import path from 'path'
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
export default {
async exportsToZip (options, dirName) {
const tempDir = os.tmpdir()
const targetDir = path.join(tempDir, 'certd-server', cryptoRandomString(10))
const projectName = dirName
const targetProjectDir = path.join(targetDir, projectName)
const templateDir = pathUtil.join('templates/' + projectName)
console.log('targetDir', targetDir)
console.log('projectName', projectName)
console.log('tempalteDir', templateDir)
console.log('targetProjectDir', targetProjectDir)
fs.copySync(templateDir, targetProjectDir)
// options
const optionsFilePath = path.join(targetProjectDir, 'options.json')
fs.writeJsonSync(optionsFilePath, options)
// 依赖版本
const exePkgJson = fs.readFileSync(pathUtil.join('node_modules/@certd/executor/package.json'))
const executorPkg = JSON.parse(exePkgJson)
const currentVersion = executorPkg.version
const templatePkgJson = fs.readFileSync(pathUtil.join('templates/certd-run/package.json'))
const templatePkg = JSON.parse(templatePkgJson)
templatePkg.dependencies['@certd/executor'] = '^' + currentVersion
templatePkg.dependencies['@certd/plugin-aliyun'] = '^' + currentVersion
templatePkg.dependencies['@certd/plugin-host'] = '^' + currentVersion
templatePkg.dependencies['@certd/plugin-tencent'] = '^' + currentVersion
const pkgFilePath = path.join(targetProjectDir, 'package.json')
fs.writeJsonSync(pkgFilePath, templatePkg)
const zipName = dirName + '.zip'
const outputFilePath = path.join(targetDir, zipName)
console.log('outputFilePath', outputFilePath)
await zipUtil.compress({ dir: targetProjectDir, output: outputFilePath })
return {
dir: targetDir,
fileName: zipName,
zipPath: outputFilePath
}
}
}
@@ -1,18 +0,0 @@
import { Executor } from '@certd/executor'
import PluginAliyun from '@certd/plugin-aliyun'
import PluginTencent from '@certd/plugin-tencent'
import PluginHost from '@certd/plugin-host'
// import options
import { createRequire } from 'module'
// 安装默认插件和授权提供者
PluginAliyun.install()
PluginTencent.install()
PluginHost.install()
const require = createRequire(import.meta.url)
const options = require('./options.json')
// 开始执行
const executor = new Executor()
await executor.run(options)
@@ -1 +0,0 @@
{}
@@ -1,22 +0,0 @@
{
"name": "certd-run",
"version": "1.0.0",
"description": "certd run",
"main": "index.js",
"scripts": {
"certd": "node index.js"
},
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/certd/certd"
},
"author": "greper",
"license": "MIT",
"dependencies": {
"@certd/executor": "^0.3.0",
"@certd/plugin-aliyun": "^0.3.0",
"@certd/plugin-host": "^0.3.0",
"@certd/plugin-tencent": "^0.3.0"
}
}
@@ -1,11 +0,0 @@
import os from 'os'
export default {
join (...dirs) {
const url = new URL('../' + dirs.join('/'), import.meta.url)
let path = url.pathname
if (os.type() === 'Windows_NT') {
path = path.substring(1)
}
return path
}
}
@@ -1,8 +0,0 @@
import compressing from 'compressing'
export default {
compress ({
dir, output
}) {
return compressing.zip.compressDir(dir, output)
}
}