-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
2,039 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ignore webstorm | ||
*.iml | ||
.idea/ | ||
|
||
# nodegs modules | ||
node_modules/ | ||
|
||
# log ignore | ||
log/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* Created by chaclus on 2016/11/5. | ||
*/ | ||
|
||
var mongoose = require('mongoose'); | ||
var mysql = require('mysql'); | ||
var Schema = mongoose.Schema; | ||
|
||
mongoose.connect('mongodb://192.168.3.30/deelive', {keepAlive: 10}, function (err) { | ||
if (err) { | ||
console.error('connect to %s error: ', 'mongodb://192.168.3.30/deelive', err.message); | ||
process.exit(1); | ||
} | ||
console.log("db success") | ||
}); | ||
var users = mongoose.model('deeusers', | ||
{ | ||
loginid: Schema.Types.ObjectId, | ||
num_revenue: Number, | ||
num_consume: Number | ||
}); | ||
|
||
|
||
var findUserByLoginId = function (loginid, cb) { | ||
// users.find({loginid: new Schema.Types.ObjectId(loginid)}, function (err, data) { | ||
users.findOne({loginid: loginid}, function (err, data) { | ||
if(err) { | ||
console.error(err); | ||
cb(err, null) | ||
}else{ | ||
cb(null, data); | ||
} | ||
}); | ||
}; | ||
|
||
|
||
var connMysql = function () { | ||
var connection = mysql.createConnection({ | ||
host : '192.168.3.30', | ||
user : 'root', | ||
password : 'dev_sql.2016', | ||
database : 'artisan_pay_online' | ||
}); | ||
|
||
connection.connect(); | ||
connection.query('SELECT * from t_user', function(err, rows, fields) { | ||
if (err) throw err; | ||
|
||
if(rows && rows.length >0) { | ||
rows.forEach(function (row) { | ||
|
||
findUserByLoginId(row.id, function (err, user) { | ||
if(user) { | ||
console.log(user.loginid+" /// "+user.num_revenue + " /// " + user.num_consume); | ||
|
||
var sql = "UPDATE t_user set num_revenue=" + user.num_revenue +", num_consume="+user.num_consume +" where id= '"+user.loginid.toString()+"'"; | ||
connection.query(sql, function (err, result) { | ||
if(err) { | ||
console.error("update err,", err); | ||
}else{ | ||
console.log("change rows : ", result.changedRows); | ||
} | ||
}) | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
}); | ||
}; | ||
connMysql(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{ | ||
"name": "nodeclub", | ||
"version": "2.0.0", | ||
"private": true, | ||
"main": "app.js", | ||
"description": "A Node.js bbs using MongoDB", | ||
"repository": "https://github.com/cnodejs/nodeclub", | ||
"customHost": [ | ||
"cnodejs.org", | ||
"club.cnodejs.org" | ||
], | ||
"engines": { | ||
"node": "0.12.x" | ||
}, | ||
"dependencies": { | ||
"amqp": "^0.2.6", | ||
"amqplib": "^0.5.0", | ||
"async": "0.9.0", | ||
"body-parser": "1.9.2", | ||
"colors": "1.1.0", | ||
"compression": "1.2.0", | ||
"connect-busboy": "0.0.1", | ||
"connect-mongo": "0.4.1", | ||
"connect-redis": "2.2.0", | ||
"cookie-parser": "1.3.3", | ||
"cors": "2.5.0", | ||
"crypto": "0.0.3", | ||
"csurf": "1.6.2", | ||
"data2xml": "0.8.0", | ||
"ejs-mate": "2.0.0", | ||
"encoding": "^0.1.11", | ||
"eventproxy": "0.3.1", | ||
"express": "4.9.5", | ||
"express-session": "1.9.1", | ||
"ftp": "0.3.10", | ||
"googleapis": "^14.1.0", | ||
"helmet": "~0.9.1", | ||
"iconv-lite": "^0.4.13", | ||
"ioredis": "^2.4.0", | ||
"jpush-sdk": "3.2.0", | ||
"jsonwebtoken": "5.1.0", | ||
"loader": "0.1.4", | ||
"lodash": "3.6.0", | ||
"log4js": "0.6.26", | ||
"markdown-it": "3.0.3", | ||
"md5": "^2.2.1", | ||
"memory-cache": "0.0.5", | ||
"method-override": "1.0.2", | ||
"moment": "2.9.0", | ||
"moment-timezone": "^0.5.10", | ||
"mongoose": "~4.0.3", | ||
"multiline": "1.0.1", | ||
"mysql": "^2.13.0", | ||
"newrelic": "1.19.2", | ||
"node-uuid": "1.4.1", | ||
"nodemailer": "^2.6.4", | ||
"nodemailer-smtp-transport": "^2.7.2", | ||
"passport": "0.1.18", | ||
"passport-github": "0.1.5", | ||
"piliv2": "2.0.1", | ||
"pingpp": "^2.0.6", | ||
"pm2": "0.14.3", | ||
"qiniu": "6.1.8", | ||
"qn": "1.0.1", | ||
"ready": "0.1.1", | ||
"redis": "2.6.2", | ||
"redis-clustr": "^1.5.1", | ||
"redis-lock": "^0.1.0", | ||
"redislock": "^1.2.1", | ||
"request": "2.54.0", | ||
"response-time": "2.2.0", | ||
"socket.io": "^1.5.0", | ||
"socket.io-client": "^1.5.0", | ||
"socket.io-emitter": "^1.0.0", | ||
"socket.io-ioredis": "^1.4.1", | ||
"socket.io-redis": "^1.0.0", | ||
"socketio-jwt": "^4.3.2", | ||
"superagent": "1.1.0", | ||
"utility": "1.0.0", | ||
"validator": "3.22.1", | ||
"ws": "^1.1.1", | ||
"xmlbuilder": "2.5.0", | ||
"xss": "0.1.15" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "2.11.2", | ||
"errorhandler": "1.2.2", | ||
"istanbul": "0.3.2", | ||
"mm": "0.2.1", | ||
"mocha": "2.0.1", | ||
"nock": "1.4.0", | ||
"pedding": "1.0.0", | ||
"should": "4.1.0", | ||
"supertest": "0.14.0" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/** | ||
* Created by Andrewbo on 15/8/16. | ||
*/ | ||
|
||
var config = require('../config'); | ||
var qiniu = require('qiniu'); | ||
|
||
qiniu.conf.ACCESS_KEY = config.qn.accessKey; | ||
qiniu.conf.SECRET_KEY = config.qn.secretKey; | ||
|
||
exports.uptoken = function(req, res, next) { | ||
|
||
var putPolicy = new qiniu.rs.PutPolicy('pic-daimao'); | ||
putPolicy.callbackUrl = config.qn.callback_url; | ||
putPolicy.callbackBody = 'avatar=$(key)&hash=$(etag)&loginid=$(x:loginid)'; | ||
|
||
var token = { | ||
'uptoken': putPolicy.token() | ||
}; | ||
res.send({ | ||
returncode : 200, | ||
data : token | ||
}); | ||
}; | ||
|
||
exports.uptoken_avatar = function(req, res, next) { | ||
|
||
var putPolicy = new qiniu.rs.PutPolicy('pic-daimao'); | ||
putPolicy.callbackUrl = config.qn.callback_url_avatar; | ||
putPolicy.callbackBody = 'avatar=$(key)&hash=$(etag)&loginid=$(x:loginid)'; | ||
|
||
var token = { | ||
'uptoken': putPolicy.token() | ||
}; | ||
res.send({ | ||
returncode : 200, | ||
data : token | ||
}); | ||
}; | ||
|
||
exports.uptoken_snapshot = function(req, res, next) { | ||
var putPolicy = new qiniu.rs.PutPolicy('pic-daimao'); | ||
putPolicy.callbackUrl = config.qn.callback_url_snapshot; | ||
putPolicy.callbackBody = 'snapshot=$(key)&hash=$(etag)'; | ||
|
||
var token = { | ||
'uptoken': putPolicy.token() | ||
}; | ||
res.send({ | ||
returncode : 200, | ||
data : token | ||
}); | ||
} | ||
|
||
exports.upload_cb = function(req, res, next) { | ||
|
||
var loginid = req.body.loginid; | ||
var avatar = req.body.avatar; | ||
|
||
if ((loginid != null) && (avatar != null)) { | ||
|
||
avatar = config.qn.img_url_ + avatar; | ||
UserProxy.updateUserAvatar(loginid, avatar, function (err, user) { | ||
if (err || !user) { | ||
return res.send({ | ||
returncode: 303, | ||
data: {} | ||
}); | ||
} | ||
return res.send({ | ||
returncode: 200, | ||
data: user | ||
}); | ||
}); | ||
} else { | ||
return res.send({ | ||
returncode: 303, | ||
data: {} | ||
}); | ||
} | ||
}; | ||
|
||
exports.upload_cb_avatar = function(req, res, next) { | ||
|
||
var loginid = req.body.loginid; | ||
var avatar = req.body.avatar; | ||
|
||
if ((loginid != null) && (avatar != null)) { | ||
|
||
avatar = config.qn.img_url_ + avatar; | ||
UserProxy.updateUserAvatar(loginid, avatar, function (err, user) { | ||
if (err || !user) { | ||
return res.send({ | ||
returncode: 303, | ||
data: {} | ||
}); | ||
} | ||
return res.send({ | ||
returncode: 200, | ||
data: user | ||
}); | ||
}); | ||
} else { | ||
return res.send({ | ||
returncode: 301, | ||
data: {} | ||
}); | ||
} | ||
}; | ||
|
||
exports.upload_cb_snapshot = function(req, res, next) { | ||
var snapshot = req.body.snapshot; | ||
|
||
if (snapshot != null) { | ||
snapshot = config.qn.img_url_ + snapshot; | ||
return res.send({ | ||
returncode: 200, | ||
data: { | ||
'snapshot' : snapshot | ||
} | ||
}); | ||
} else { | ||
return res.send({ | ||
returncode: 301, | ||
data: {} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Created by chaclus on 2016/12/21. | ||
*/ | ||
|
||
|
||
var io = require('socket.io-client'); | ||
|
||
|
||
var connect = function () { | ||
var socket = io.connect('http://127.0.0.1:8199/ios', {'forceNew': true, 'transports': ['websocket']}); | ||
socket.on('connect', function () { | ||
console.log("socket connected"); | ||
socket.emit('enter', {liveid: 'aaaaaaaa'}); | ||
|
||
socket.on("im", function (data) { | ||
console.log("im data >>>>> ", data); | ||
}); | ||
}); | ||
}; | ||
|
||
for (var i=0;i<2;i++) { | ||
connect(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Created by chaclus on 2016/12/21. | ||
*/ | ||
var http = require('http'); | ||
var IoRedis = require('ioredis'); | ||
|
||
var express = require('express'); | ||
|
||
var router = express.Router(); | ||
|
||
//http server | ||
var app = express(); | ||
var server = http.createServer(app); | ||
server.listen(8200); | ||
|
||
app.use('/route', router); | ||
|
||
//redis | ||
var redis = IoRedis({ | ||
host: '192.168.3.30', | ||
port: 6379, | ||
password: 'TUTU@live2016' | ||
}); | ||
|
||
|
||
router.get('/', function (req, res, next) { | ||
var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; | ||
console.log(ip); | ||
getServer(); | ||
res.send('Hello World'); | ||
}); | ||
|
||
|
||
var getServer = function () { | ||
redis.hgetall("SOCKET_SERVER_INFO", function (err, data) { | ||
console.log(data) | ||
}); | ||
}; |
Oops, something went wrong.