Skip to content

Commit f8d2a81

Browse files
committed
初始提交
0 parents  commit f8d2a81

21 files changed

+445
-0
lines changed

.editorconfig

+13
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

+19
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

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/client/
2+
/node_modules/

.jshintrc

+21
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

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"generator-loopback": {}
3+
}

README.md

+3
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

+3
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

+110
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

+35
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

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

common/models/version.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "version",
3+
"base": "PersistedModel",
4+
"idInjection": false,
5+
"options": {
6+
"validateUpsert": true
7+
},
8+
"properties": {
9+
"vid": {
10+
"type": "number",
11+
"id":true,
12+
"required": true
13+
},
14+
"versionType": {
15+
"type": "string",
16+
"required": true
17+
},
18+
"url": {
19+
"type": "string"
20+
},
21+
"createTime": {
22+
"type": "date"
23+
},
24+
"h5Version": {
25+
"type": "string"
26+
},
27+
"binMax": {
28+
"type": "string"
29+
},
30+
"binMin": {
31+
"type": "string"
32+
},
33+
"updateTime": {
34+
"type": "date"
35+
}
36+
},
37+
"validations": [],
38+
"relations": {},
39+
"acls": [],
40+
"methods": {}
41+
}

package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "appversion",
3+
"version": "1.0.0",
4+
"main": "server/server.js",
5+
"scripts": {
6+
"pretest": "jshint ."
7+
},
8+
"dependencies": {
9+
"compression": "^1.0.3",
10+
"cors": "^2.5.2",
11+
"loopback": "^2.22.0",
12+
"loopback-boot": "^2.6.5",
13+
"loopback-component-explorer": "^2.1.0",
14+
"loopback-connector-mongodb": "^1.13.2",
15+
"loopback-datasource-juggler": "^2.39.0",
16+
"serve-favicon": "^2.0.1"
17+
},
18+
"devDependencies": {
19+
"jshint": "^2.5.6"
20+
},
21+
"repository": {
22+
"type": "",
23+
"url": ""
24+
},
25+
"description": "appversion"
26+
}

server/boot/authentication.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = function enableAuthentication(server) {
2+
// enable authentication
3+
server.enableAuth();
4+
};

server/boot/root.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(server) {
2+
// Install a `/` route that returns server status
3+
var router = server.loopback.Router();
4+
router.get('/', server.loopback.status());
5+
server.use(router);
6+
};

server/component-config.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"loopback-component-explorer": {
3+
"mountPath": "/explorer"
4+
}
5+
}

server/config.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"restApiRoot": "/api",
3+
"host": "0.0.0.0",
4+
"port": 3000,
5+
"remoting": {
6+
"context": {
7+
"enableHttpContext": false
8+
},
9+
"rest": {
10+
"normalizeHttpPath": false,
11+
"xml": false
12+
},
13+
"json": {
14+
"strict": false,
15+
"limit": "100kb"
16+
},
17+
"urlencoded": {
18+
"extended": true,
19+
"limit": "100kb"
20+
},
21+
"cors": false,
22+
"errorHandler": {
23+
"disableStackTrace": false
24+
}
25+
},
26+
"legacyExplorer": false
27+
}

server/datasources.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"db": {
3+
"name": "db",
4+
"connector": "memory"
5+
},
6+
"appversion": {
7+
"host": "0.0.0.0",
8+
"port": 27017,
9+
"database": "appversion",
10+
"name": "appversion",
11+
"connector": "mongodb"
12+
}
13+
}

server/middleware.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"initial:before": {
3+
"loopback#favicon": {}
4+
},
5+
"initial": {
6+
"compression": {},
7+
"cors": {
8+
"params": {
9+
"origin": true,
10+
"credentials": true,
11+
"maxAge": 86400
12+
}
13+
}
14+
},
15+
"session": {},
16+
"auth": {},
17+
"parse": {},
18+
"routes": {
19+
"loopback#rest": {
20+
"paths": [
21+
"${restApiRoot}"
22+
]
23+
}
24+
},
25+
"files": {},
26+
"final": {
27+
"loopback#urlNotFound": {}
28+
},
29+
"final:after": {
30+
"loopback#errorHandler": {}
31+
}
32+
}

server/middleware.production.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"final:after": {
3+
"loopback#errorHandler": {
4+
"params": {
5+
"includeStack": false
6+
}
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)