Skip to content

Commit

Permalink
fix: remove /README.md and remove markdown-it dep
Browse files Browse the repository at this point in the history
  • Loading branch information
rocwind committed Aug 19, 2021
1 parent 56f4905 commit 6100c52
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 115 deletions.
39 changes: 3 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"jsonwebtoken": "8.5.1",
"lodash": "4.17.21",
"log4js": "3.0.6",
"markdown-it": "8.4.1",
"moment": "2.29.1",
"morgan": "1.9.0",
"mysql2": "2.3.0",
Expand Down
145 changes: 67 additions & 78 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,96 @@
var express = require('express');
var express = require("express");
var router = express.Router();
var Promise = require('bluebird');
var AppError = require('../core/app-error');
var middleware = require('../core/middleware');
var ClientManager = require('../core/services/client-manager');
var _ = require('lodash');
var log4js = require('log4js');
var AppError = require("../core/app-error");
var middleware = require("../core/middleware");
var ClientManager = require("../core/services/client-manager");
var _ = require("lodash");
var log4js = require("log4js");
var log = log4js.getLogger("cps:index");

router.get('/', (req, res, next) => {
res.render('index', { title: 'CodePushServer' });
router.get("/", (req, res, next) => {
res.render("index", { title: "CodePushServer" });
});

router.get('/README.md', (req, res, next) => {
var MarkdownIt = require('markdown-it');
const path = require('path');
const fs = require('fs');
const readFile = Promise.promisify(fs.readFile);
const README = path.join(__dirname, '../README.md');
readFile(README, { encoding: 'utf8' })
.then(source => {
var md = new MarkdownIt();
res.send(md.render(source));
})
.catch(e=>{
if (e instanceof AppError.AppError) {
res.send(e.message);
} else {
next(e);
}
});
router.get("/tokens", (req, res) => {
res.render("tokens", { title: "获取token" });
});

router.get('/tokens', (req, res) => {
res.render('tokens', { title: '获取token' });
});

router.get('/updateCheck', (req, res, next) => {
router.get("/updateCheck", (req, res, next) => {
var deploymentKey = _.get(req, "query.deploymentKey");
var appVersion = _.get(req, "query.appVersion");
var label = _.get(req, "query.label");
var packageHash = _.get(req, "query.packageHash")
var clientUniqueId = _.get(req, "query.clientUniqueId")
var packageHash = _.get(req, "query.packageHash");
var clientUniqueId = _.get(req, "query.clientUniqueId");
var clientManager = new ClientManager();
log.debug('req.query', req.query);
clientManager.updateCheckFromCache(deploymentKey, appVersion, label, packageHash, clientUniqueId)
.then((rs) => {
//灰度检测
return clientManager.chosenMan(rs.packageId, rs.rollout, clientUniqueId)
.then((data)=>{
if (!data) {
rs.isAvailable = false;
return rs;
log.debug("req.query", req.query);
clientManager
.updateCheckFromCache(
deploymentKey,
appVersion,
label,
packageHash,
clientUniqueId
)
.then((rs) => {
//灰度检测
return clientManager
.chosenMan(rs.packageId, rs.rollout, clientUniqueId)
.then((data) => {
if (!data) {
rs.isAvailable = false;
return rs;
}
return rs;
});
})
.then((rs) => {
delete rs.packageId;
delete rs.rollout;
res.send({ updateInfo: rs });
})
.catch((e) => {
if (e instanceof AppError.AppError) {
res.status(404).send(e.message);
} else {
next(e);
}
return rs;
});
})
.then((rs) => {
delete rs.packageId;
delete rs.rollout;
res.send({"updateInfo":rs});
})
.catch((e) => {
if (e instanceof AppError.AppError) {
res.status(404).send(e.message);
} else {
next(e);
}
});
});

router.post('/reportStatus/download', (req, res) => {
log.debug('req.body', req.body);
router.post("/reportStatus/download", (req, res) => {
log.debug("req.body", req.body);
var clientUniqueId = _.get(req, "body.clientUniqueId");
var label = _.get(req, "body.label");
var deploymentKey = _.get(req, "body.deploymentKey");
var clientManager = new ClientManager();
clientManager.reportStatusDownload(deploymentKey, label, clientUniqueId)
.catch((err) => {
if (!err instanceof AppError.AppError) {
console.error(err.stack)
}
});
res.send('OK');
clientManager
.reportStatusDownload(deploymentKey, label, clientUniqueId)
.catch((err) => {
if (!err instanceof AppError.AppError) {
console.error(err.stack);
}
});
res.send("OK");
});

router.post('/reportStatus/deploy', (req, res) => {
log.debug('req.body', req.body);
router.post("/reportStatus/deploy", (req, res) => {
log.debug("req.body", req.body);
var clientUniqueId = _.get(req, "body.clientUniqueId");
var label = _.get(req, "body.label");
var deploymentKey = _.get(req, "body.deploymentKey");
var clientManager = new ClientManager();
clientManager.reportStatusDeploy(deploymentKey, label, clientUniqueId, req.body)
.catch((err) => {
if (!err instanceof AppError.AppError) {
console.error(err.stack)
}
});
res.send('OK');
clientManager
.reportStatusDeploy(deploymentKey, label, clientUniqueId, req.body)
.catch((err) => {
if (!err instanceof AppError.AppError) {
console.error(err.stack);
}
});
res.send("OK");
});

router.get('/authenticated', middleware.checkToken, (req, res) => {
return res.send({authenticated: true});
})
router.get("/authenticated", middleware.checkToken, (req, res) => {
return res.send({ authenticated: true });
});

module.exports = router;

0 comments on commit 6100c52

Please sign in to comment.