remove console.log, add cross-platform del, optimize prod config for DB

pull/152/merge
Bosn 7 years ago
parent 48eacfebfc
commit c36171cef4

@ -7,9 +7,9 @@
"description": "", "description": "",
"main": "dist/dispatch.js", "main": "dist/dispatch.js",
"scripts": { "scripts": {
"build": "rm -rf dist/ && tsc", "build": "rimraf -rf dist/ && tsc",
"test": "cross-env NODE_ENV=development cross-env TEST_MODE=true nyc mocha --exit --reporter nyan", "test": "cross-env NODE_ENV=development cross-env TEST_MODE=true nyc mocha --exit --reporter nyan",
"check": "echo \"Checking...\" && npm run tslint", "check": "echo \"Checking...\" && tsc && npm run tslint",
"dev": "cross-env NODE_ENV=development nodemon --watch scripts --watch dist dist/scripts/dev.js", "dev": "cross-env NODE_ENV=development nodemon --watch scripts --watch dist dist/scripts/dev.js",
"create-db": "cross-env NODE_ENV=development node dist/scripts/init", "create-db": "cross-env NODE_ENV=development node dist/scripts/init",
"tslint": "tslint -c tslint.json -p tsconfig.json", "tslint": "tslint -c tslint.json -p tsconfig.json",
@ -74,6 +74,7 @@
"nyc": "^11.4.1", "nyc": "^11.4.1",
"pm2": "^2.10.2", "pm2": "^2.10.2",
"pre-commit": "^1.2.2", "pre-commit": "^1.2.2",
"rimraf": "^2.6.2",
"source-map-support": "^0.5.0", "source-map-support": "^0.5.0",
"standard": "^10.0.2", "standard": "^10.0.2",
"supertest": "^3.0.0", "supertest": "^3.0.0",

@ -15,13 +15,14 @@ let config: IConfigOptions = {
port: 3306, port: 3306,
username: 'root', username: 'root',
password: '', password: '',
database: 'RAP2_DELOS_APP', database: 'rap',
pool: { pool: {
max: 5, max: 80,
min: 0, min: 0,
idle: 10000, idle: 20000,
acquire: 20000,
}, },
logging: true, logging: false,
}, },
} }

@ -68,8 +68,6 @@ router.get('/account/info', async (ctx) => {
router.post('/account/login', async (ctx) => { router.post('/account/login', async (ctx) => {
let { email, password, captcha } = ctx.request.body let { email, password, captcha } = ctx.request.body
let result, errMsg let result, errMsg
console.log(`captcha=${captcha} ctx.session.captcha=${ctx.session.captcha}`)
if (process.env.TEST_MODE !== 'true' && if (process.env.TEST_MODE !== 'true' &&
(!captcha || !ctx.session.captcha || captcha.trim().toLowerCase() !== ctx.session.captcha.toLowerCase())) { (!captcha || !ctx.session.captcha || captcha.trim().toLowerCase() !== ctx.session.captcha.toLowerCase())) {
errMsg = '错误的验证码' errMsg = '错误的验证码'
@ -235,6 +233,15 @@ router.post('/account/notification/read', async (ctx) => {
// TODO 2.3 账户日志 // TODO 2.3 账户日志
router.get('/account/logger', async (ctx) => { router.get('/account/logger', async (ctx) => {
if (!ctx.session.id) {
ctx.body = {
data: {
isOk: false,
errMsg: 'not login'
}
}
return
}
let auth = await User.findById(ctx.session.id) let auth = await User.findById(ctx.session.id)
let repositories: Model<Repository>[] = [...(<Model<Repository>[]>await auth.$get('ownedRepositories')), ...(<Model<Repository>[]>await auth.$get('joinedRepositories'))] let repositories: Model<Repository>[] = [...(<Model<Repository>[]>await auth.$get('ownedRepositories')), ...(<Model<Repository>[]>await auth.$get('joinedRepositories'))]
let organizations: Model<Organization>[] = [...(<Model<Organization>[]>await auth.$get('ownedOrganizations')), ...(<Model<Organization>[]>await auth.$get('joinedOrganizations'))] let organizations: Model<Organization>[] = [...(<Model<Organization>[]>await auth.$get('ownedOrganizations')), ...(<Model<Organization>[]>await auth.$get('joinedOrganizations'))]

@ -182,13 +182,10 @@ router.all('/app/mock/(\\d+)/(.+)', async (ctx) => {
const data = Tree.ArrayToTreeToTemplateToData(properties, requestData) const data = Tree.ArrayToTreeToTemplateToData(properties, requestData)
ctx.type = 'json' ctx.type = 'json'
ctx.body = JSON.stringify(data, undefined, 2) ctx.body = JSON.stringify(data, undefined, 2)
console.log(itf.url)
if (itf && itf.url.indexOf('[callback]=') > -1) { if (itf && itf.url.indexOf('[callback]=') > -1) {
const query = querystring.parse(itf.url.substring(itf.url.indexOf('?') + 1)) const query = querystring.parse(itf.url.substring(itf.url.indexOf('?') + 1))
console.log(query)
const cbName = query['[callback]'] const cbName = query['[callback]']
const cbVal = ctx.request.query[`${cbName}`] const cbVal = ctx.request.query[`${cbName}`]
console.log(cbName + '|' + cbVal)
if (cbVal) { if (cbVal) {
let body = typeof ctx.body === 'object' ? JSON.stringify(ctx.body, undefined, 2) : ctx.body let body = typeof ctx.body === 'object' ? JSON.stringify(ctx.body, undefined, 2) : ctx.body
ctx.type = 'application/x-javascript' ctx.type = 'application/x-javascript'

@ -54,6 +54,15 @@ router.get('/organization/list', async (ctx) => {
} }
}) })
router.get('/organization/owned', async (ctx) => { router.get('/organization/owned', async (ctx) => {
if (!ctx.session.id) {
ctx.body = {
data: {
isOk: false,
errMsg: 'not login'
}
}
return
}
let where = {} let where = {}
let { name } = ctx.query let { name } = ctx.query
if (name) { if (name) {
@ -79,6 +88,15 @@ router.get('/organization/owned', async (ctx) => {
} }
}) })
router.get('/organization/joined', async (ctx) => { router.get('/organization/joined', async (ctx) => {
if (!ctx.session.id) {
ctx.body = {
data: {
isOk: false,
errMsg: 'not login'
}
}
return
}
let where = {} let where = {}
let { name } = ctx.query let { name } = ctx.query
if (name) { if (name) {

@ -25,7 +25,6 @@ router.get('/test/test.status', (ctx) => {
// proxy // proxy
router.get('/proxy', async(ctx) => { router.get('/proxy', async(ctx) => {
let { target } = ctx.query let { target } = ctx.query
console.log(` <=> ${target}`)
let json = await fetch(target).then(res => res.json()) let json = await fetch(target).then(res => res.json())
ctx.type = 'json' ctx.type = 'json'
ctx.body = json ctx.body = json

@ -5,7 +5,6 @@ export enum ACCESS_TYPE { ORGANIZATION, REPOSITORY, USER }
export class AccessUtils { export class AccessUtils {
public static async canUserAccess(accessType: ACCESS_TYPE, curUserId: number, entityId: number): Promise<boolean> { public static async canUserAccess(accessType: ACCESS_TYPE, curUserId: number, entityId: number): Promise<boolean> {
console.log(`accessType=${accessType}&curUserId=${curUserId}&&entityId=${entityId}`)
if (accessType === ACCESS_TYPE.ORGANIZATION) { if (accessType === ACCESS_TYPE.ORGANIZATION) {
return await OrganizationService.canUserAccessOrganization(curUserId, entityId) return await OrganizationService.canUserAccessOrganization(curUserId, entityId)
} else if (accessType === ACCESS_TYPE.REPOSITORY) { } else if (accessType === ACCESS_TYPE.REPOSITORY) {

@ -14,7 +14,7 @@ appAny.counter = { users: {}, mock: 0 }
app.keys = config.keys app.keys = config.keys
app.use(session(config.session, app)) app.use(session(config.session, app))
if (process.env.NODE_ENV === 'development') app.use(logger()) app.use(logger())
app.use(async(ctx, next) => { app.use(async(ctx, next) => {
await next() await next()
if (ctx.path === '/favicon.ico') return if (ctx.path === '/favicon.ico') return

@ -16,7 +16,6 @@ export default class Migrate {
return return
} }
for (const user of users) { for (const user of users) {
console.log(`load user ${user.id}`)
if (!isMd5(user.password)) { if (!isMd5(user.password)) {
user.password = md5(md5(user.password)) user.password = md5(md5(user.password))
await user.save() await user.save()

@ -17,7 +17,6 @@ export default class OrganizationService {
) as result ) as result
WHERE id = ${organizationId} WHERE id = ${organizationId}
` `
console.log(sql)
return new Promise(resolve => { return new Promise(resolve => {
seq.query(sql).spread((result: any) => { seq.query(sql).spread((result: any) => {
resolve(+result[0].num > 0) resolve(+result[0].num > 0)
@ -46,7 +45,6 @@ export default class OrganizationService {
` `
return new Promise(resolve => { return new Promise(resolve => {
seq.query(sql).spread((result: { id: number }[]) => { seq.query(sql).spread((result: { id: number }[]) => {
console.log(result)
resolve(result.map(item => item.id)) resolve(result.map(item => item.id))
}) })
}) })

Loading…
Cancel
Save