Skip to content

Commit c1a299f

Browse files
committed
sopport tencent cloud cos storageType
1 parent afeb1f6 commit c1a299f

File tree

6 files changed

+184
-161
lines changed

6 files changed

+184
-161
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@
1111
[![Known Vulnerabilities](https://snyk.io/test/npm/code-push-server/badge.svg)](https://snyk.io/test/npm/code-push-server)
1212
[![Licenses](https://img.shields.io/npm/l/code-push-server.svg)](https://spdx.org/licenses/MIT)
1313

14-
CodePush Server is a CodePush progam server! microsoft CodePush cloud is slow in China, we can use this to build our's. I use [qiniu](http://www.qiniu.com/) to store the files, because it's simple and quick! Or you can use [local/s3/oss] storage, just modify config.js file, it's simple configure.
14+
CodePush Server is a CodePush progam server! microsoft CodePush cloud is slow in China, we can use this to build our's. I use [qiniu](http://www.qiniu.com/) to store the files, because it's simple and quick! Or you can use [local/s3/oss/tencentcloud] storage, just modify config.js file, it's simple configure.
15+
16+
## Support Storage mode
17+
18+
- local *storage bundle file in local machine*
19+
- qiniu *storage bundle file in [qiniu](http://www.qiniu.com/)*
20+
- s3 *storage bundle file in [aws](https://aws.amazon.com/)*
21+
- oss *storage bundle file in [aliyun](https://www.aliyun.com/product/oss)*
22+
- tencentcloud *storage bundle file in [tencentcloud](https://cloud.tencent.com/product/cos)*
1523

1624
## qq交流群
1725

18-
- NO.2QQ群: 628921445
19-
- NO.1QQ群: 535491067
26+
- QQ群: 628921445
27+
- QQ群: 535491067
2028

2129
## 正确使用code-push热更新
2230

@@ -56,7 +64,12 @@ $ code-push login http://api.code-push.com #登录
5664

5765

5866
## ISSUES
59-
[code-push-server normal problem](https://github.com/lisong/code-push-server/issues/135)
67+
68+
[code-push-server normal solution](https://github.com/lisong/code-push-server/issues/135)
69+
70+
[An unknown error occurred](https://github.com/lisong/code-push-server/issues?utf8=%E2%9C%93&q=unknown)
71+
72+
[modify password](https://github.com/lisong/code-push-server/issues/43)
6073

6174
## License
6275
MIT License [read](https://github.com/lisong/code-push-server/blob/master/LICENSE)

config/config.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ config.development = {
3838
prefix: "", // Key prefix in object key
3939
downloadUrl: "", // binary files download host address.
4040
},
41+
// Config for tencentyun COS (https://cloud.tencent.com/product/cos) when storageType value is "oss".
42+
tencentcloud: {
43+
accessKeyId: "",
44+
secretAccessKey: "",
45+
bucketName: "",
46+
region: "",
47+
downloadUrl: "", // binary files download host address.
48+
},
4149
// Config for local storage when storageType value is "local".
4250
local: {
4351
// Binary files storage dir, Do not use tmpdir and it's public download dir.
@@ -65,7 +73,7 @@ config.development = {
6573
diffNums: 3,
6674
// data dir for caclulate diff files. it's optimization.
6775
dataDir: process.env.DATA_DIR || os.tmpdir(),
68-
// storageType which is your binary package files store. options value is ("local" | "qiniu" | "s3")
76+
// storageType which is your binary package files store. options value is ("local" | "qiniu" | "s3"| "oss" || "tencentcloud")
6977
storageType: process.env.STORAGE_TYPE || "local",
7078
// options value is (true | false), when it's true, it will cache updateCheck results in redis.
7179
updateCheckCache: false,

core/utils/common.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,19 @@ common.getUploadTokenQiniu = function (mac, bucket, key) {
183183
};
184184

185185
common.uploadFileToStorage = function (key, filePath) {
186-
if (_.get(config, 'common.storageType') === 'local') {
186+
var storageType = _.get(config, 'common.storageType');
187+
if ( storageType === 'local') {
187188
return common.uploadFileToLocal(key, filePath);
188-
} else if (_.get(config, 'common.storageType') === 's3') {
189+
} else if (storageType === 's3') {
189190
return common.uploadFileToS3(key, filePath);
190-
} else if (_.get(config, 'common.storageType') === 'oss') {
191+
} else if (storageType === 'oss') {
191192
return common.uploadFileToOSS(key, filePath);
193+
} else if (storageType === 'qiniu') {
194+
return common.uploadFileToQiniu(key, filePath);
195+
} else if (storageType === 'tencentcloud') {
196+
return common.uploadFileToTencentCloud(key, filePath);
192197
}
193-
return common.uploadFileToQiniu(key, filePath);
198+
throw new AppError.AppError(`${storageType} storageType does not support.`);
194199
};
195200

196201
common.uploadFileToLocal = function (key, filePath) {
@@ -360,16 +365,41 @@ common.uploadFileToOSS = function (key, filePath) {
360365

361366
return new Promise((resolve, reject) => {
362367
upload.on('error', (error) => {
368+
log.debug("uploadFileToOSS", error);
363369
reject(error);
364370
});
365371

366372
upload.on('uploaded', (details) => {
373+
log.debug("uploadFileToOSS", details);
367374
resolve(details.ETag);
368375
});
369376
fs.createReadStream(filePath).pipe(upload);
370377
});
371378
};
372379

380+
common.uploadFileToTencentCloud = function (key, filePath) {
381+
return new Promise((resolve, reject) => {
382+
var COS = require('cos-nodejs-sdk-v5');
383+
var cosIn = new COS({
384+
SecretId: _.get(config, 'tencentcloud.accessKeyId'),
385+
SecretKey: _.get(config, 'tencentcloud.secretAccessKey')
386+
});
387+
cosIn.sliceUploadFile({
388+
Bucket: _.get(config, 'tencentcloud.bucketName'),
389+
Region: _.get(config, 'tencentcloud.region'),
390+
Key: key,
391+
FilePath: filePath
392+
}, function (err, data) {
393+
log.debug("uploadFileToTencentCloud", err, data);
394+
if (err) {
395+
reject(new AppError.AppError(JSON.stringify(err)));
396+
}else {
397+
resolve(data.Key);
398+
}
399+
});
400+
});
401+
}
402+
373403
common.diffCollectionsSync = function (collection1, collection2) {
374404
var diffFiles = [];
375405
var collection1Only = [];

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ $ tail -f "output file path"
156156
- qiniu (qiniu)
157157
- s3 (aws)
158158
- oss (aliyun)
159+
- tencentcloud
159160

160161
## Default listen Host/Port 0.0.0.0/3000
161162

0 commit comments

Comments
 (0)