fetch api with current version param

This commit is contained in:
life
2018-12-11 19:04:06 +08:00
parent e73f853c41
commit 5d456c90ba
2 changed files with 20 additions and 5 deletions

21
node_modules/api.js generated vendored
View File

@@ -9,9 +9,20 @@ var Web = require('web');
var Tags = db.tags;
var needle = require('needle');
var fs = require('fs');
var os = require('os');
var Evt = require('evt');
var macAddr = require('node-getmac');
// 当前版本
var vFile = Evt.getProjectBasePath() + '/data/version';
var currentVersion = os.platform() + '_' + os.arch();
try {
var v = JSON.parse(fs.readFileSync(vFile));
currentVersion += '_' + v.version
} catch(e) {
console.error(e);
}
function log(o) {
// console.log(o);
}
@@ -27,6 +38,10 @@ needle.defaults({
// 远程数据服务
var Api = {
getVersion: function () {
return currentVersion
},
// 检查错误
checkError: function(error, resp) {
var me = this;
@@ -116,7 +131,7 @@ var Api = {
// log({emai: email, pwd: pwd});
// console.log(this.getUrl('auth/login', {email: email, pwd: pwd}));
// console.log('????????????')
needle.post(this.getUrl('auth/login', {macAddr: macAddr}), {email: email, pwd: pwd}, {timeout: 10000}, function(error, response) {
needle.post(this.getUrl('auth/login', {macAddr: macAddr, v: currentVersion}), {email: email, pwd: pwd}, {timeout: 10000}, function(error, response) {
me.checkError(error, response);
if(error) {
return callback && callback(false);
@@ -140,7 +155,7 @@ var Api = {
},
logout: function (callback) {
needle.post(this.getUrl('auth/logout', {macAddr: macAddr}), {timeout: 10000}, function(error, response) {
needle.post(this.getUrl('auth/logout', {macAddr: macAddr, v: currentVersion}), {timeout: 10000}, function(error, response) {
callback();
});
},
@@ -207,7 +222,7 @@ var Api = {
},
getLastSyncState: function(callback) {
var me = this;
var url = this.getUrl('user/getSyncState', {macAddr: macAddr});
var url = this.getUrl('user/getSyncState', {macAddr: macAddr, v: currentVersion});
// console.log(url);
needle.get(url, {timeout: 10000}, function(error, response) {
// console.log('user/getSyncState ret');