Skip to content

Commit f8d2a81

Browse files
committed
初始提交
0 parents  commit f8d2a81

21 files changed

+445
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# http://editorconfig.org
4+
5+
root = true
6+
7+
[*]
8+
indent_style = space
9+
indent_size = 2
10+
end_of_line = lf
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*.csv
2+
*.dat
3+
*.iml
4+
*.log
5+
*.out
6+
*.pid
7+
*.seed
8+
*.sublime-*
9+
*.swo
10+
*.swp
11+
*.tgz
12+
*.xml
13+
.DS_Store
14+
.idea
15+
.project
16+
.strong-pm
17+
coverage
18+
node_modules
19+
npm-debug.log

.jshintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/client/
2+
/node_modules/

.jshintrc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"node": true,
3+
"esnext": true,
4+
"bitwise": true,
5+
"camelcase": true,
6+
"eqeqeq": true,
7+
"eqnull": true,
8+
"immed": true,
9+
"indent": 2,
10+
"latedef": "nofunc",
11+
"newcap": true,
12+
"nonew": true,
13+
"noarg": true,
14+
"quotmark": "single",
15+
"regexp": true,
16+
"undef": true,
17+
"unused": false,
18+
"trailing": true,
19+
"sub": true,
20+
"maxlen": 80
21+
}

.yo-rc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"generator-loopback": {}
3+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# My Application
2+
3+
The project is generated by [LoopBack](http://loopback.io).

client/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Client
2+
3+
This is the place for your application front-end files.

common/models/app.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
module.exports = function (App) {
2+
App.prototype.checkVersion = function checkVersion(device_deploy_uuid, device_app_version, device_platform, cb) {
3+
//uuid=compare h5version,app_version= in(min,max)
4+
var compatible_binary = false;
5+
var update_available = false;
6+
var comp_result = false;
7+
//var uuid = '';
8+
var zipurl = '';
9+
//console.log(this.versions.find({ where: {device_platform:'versionType'}})) ;
10+
this.versions(function (err, results) {
11+
//console.log(results);
12+
for (i = 0; i < results.length; i++) {
13+
console.log('h5Version:' + results[i]['h5Version']);
14+
console.log('max:' + results[i]['binMax']);
15+
console.log('min:' + results[i]['binMin']);
16+
console.log('uuid:' + device_deploy_uuid + 'appver:' + device_app_version);
17+
var latest_h5 = results[i]['h5Version'];
18+
var obj = results[i];
19+
var max = results[i]['binMax'];
20+
var min = results[i]['binMin'];
21+
var versionType = results[i]['versionType'];
22+
//todo:好像少了个判断
23+
if (device_platform == versionType) {
24+
comp_result = compareH5(device_deploy_uuid, device_app_version, latest_h5, max, min, obj, cb);
25+
} else {
26+
cb(null, compatible_binary, update_available, {uuid: device_deploy_uuid, url: zipurl});
27+
28+
}
29+
30+
}
31+
});
32+
33+
34+
var compareH5 = function compareH5(device_deploy_uuid, device_app_version, latest_h5, max, min, obj, cb) {
35+
36+
//if (parseInt(latest_h5) > parseInt(uuid)) {
37+
if (compare(latest_h5, device_deploy_uuid) === 1) {
38+
//if (parseInt(min) <= parseInt(app_version) && parseInt(app_version) <= parseInt(max)) {
39+
if (compare(device_app_version, min) === 1 && compare(max, device_app_version) === 1) {
40+
device_deploy_uuid = latest_h5;
41+
console.log(obj);
42+
zipurl = obj['url'];
43+
44+
console.log('zurl:' + zipurl);
45+
compatible_binary = true;
46+
update_available = true;
47+
console.log('compatible_binary:' + compatible_binary);
48+
console.log('update_available:' + update_available);
49+
50+
cb(null, compatible_binary, update_available, {uuid: latest_h5, url: zipurl});
51+
52+
return true;
53+
} else {
54+
device_deploy_uuid = latest_h5;
55+
compatible_binary = true;
56+
update_available = false;
57+
58+
cb(null, compatible_binary, update_available, {uuid: device_deploy_uuid, url: zipurl});
59+
60+
return false;
61+
}
62+
} else {
63+
64+
cb(null, compatible_binary, update_available, {uuid: device_deploy_uuid, url: zipurl});
65+
return false;
66+
}
67+
68+
};
69+
70+
71+
};
72+
73+
74+
var compare = function compare(v1, v2) {
75+
var v1_tmp = v1, v2_tmp = v2;
76+
v1 = v1.replace(/\./g, '');
77+
v2 = v2.replace(/\./g, '');
78+
console.log("去掉小数点:", v1, v2);
79+
var len = Math.max(v1.length, v2.length);
80+
v1 = v1 + Array(len - v1.length + 1).join(0);
81+
v2 = v2 + Array(len - v2.length + 1).join(0);
82+
console.log("补长对齐:", v1, v2);
83+
v1 = parseInt(v1.replace(/^0+/, ''));
84+
v2 = parseInt(v2.replace(/^0+/, ''));
85+
console.log("去掉前导0:", v1, v2);
86+
console.log("大的是:", Math.max(v1, v2));
87+
var ret = v1 > v2 ? 1 : v1 == v2 ? 0 : -1;
88+
console.log("compare:", v1_tmp, " ? ", v2_tmp, " : ", ret);
89+
return ret;
90+
}
91+
92+
93+
App.remoteMethod('checkVersion', {
94+
isStatic: false,
95+
96+
accepts: [
97+
{arg: 'device_deploy_uuid', type: 'string'},
98+
{arg: 'device_app_version', type: 'string'},
99+
{arg: 'device_platform', type: 'string'}
100+
],
101+
102+
returns: [
103+
{arg: 'compatible_binary', type: 'boolean'},
104+
{arg: 'update_available', type: 'boolean'},
105+
{arg: 'update', type: 'object'}
106+
],
107+
108+
http: {path: '/updates/check', verb: 'post'}
109+
});
110+
};

common/models/app.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "app",
3+
"base": "PersistedModel",
4+
"idInjection": false,
5+
"options": {
6+
"validateUpsert": true
7+
},
8+
"properties": {
9+
"id": {
10+
"type": "number",
11+
"id" : true,
12+
"required": true
13+
},
14+
"name": {
15+
"type": "string",
16+
"required": true
17+
},
18+
"createTime": {
19+
"type": "date"
20+
},
21+
"updateTime": {
22+
"type": "date"
23+
}
24+
},
25+
"validations": [],
26+
"relations": {
27+
"versions": {
28+
"type": "hasMany",
29+
"model": "version",
30+
"foreignKey": ""
31+
}
32+
},
33+
"acls": [],
34+
"methods": {}
35+
}

common/models/version.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function(Version) {
2+
3+
};

0 commit comments

Comments
 (0)