-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploadFirimHost.js
More file actions
88 lines (77 loc) · 2.12 KB
/
uploadFirimHost.js
File metadata and controls
88 lines (77 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* fir.im upload plugin
*/
const fs = require('fs');
const request = require('request');
const chalk = require("chalk");
/**
* fir.im api token
*/
const apiToken = '';
/**
* cli argument
*/
let [packagePath, iconPath, platform, bundleId, appName, version, buildVersion, changelog] = process.argv.slice(2);
console.log('platform: ', platform);
console.log('bundleId: ', bundleId);
console.log('appName: ', appName);
console.log('version: ', version);
console.log('buildVersion: ', buildVersion);
console.log('changelog: ', changelog);
// Main
getUploadToken(platform, bundleId, apiToken).then(result => {
const packageParam = result.cert.binary;
const iconParam = result.cert.icon;
upLoadFile(packageParam, packagePath, appName, version, buildVersion, changelog).then(() => {
console.log(chalk.green('upload package upload succeed!'));
});
upLoadFile(iconParam, iconPath).then(() => {
console.log(chalk.green('upload icon upload succeed!'));
});
});
// Upload package/icon to fir.im
function upLoadFile(param, filePath, appName = '', version = '', buildVersion = '', changelog = '') {
return new Promise((resolve, reject) => {
request.post({
url: param.upload_url,
formData: {
key: param.key,
token: param.token,
'x:name': appName,
'x:version': version,
'x:build': buildVersion,
'x:changelog': changelog,
file: fs.createReadStream(filePath),
},
encoding: 'utf8'
}, (_error, response, body) => {
if (response.statusCode !== 200) {
console.log(chalk.red(body));
reject(chalk.red(`Upload package/icon ${filePath} failed!`));
} else {
resolve(JSON.parse(body));
}
});
});
}
// Get upload token from fir.im
function getUploadToken(type, bundleId, apiToken) {
return new Promise((resolve, reject) => {
request.post({
url: 'http://api.bq04.com/apps',
form: {
type: type,
bundle_id: bundleId,
api_token: apiToken,
},
encoding: 'utf8'
}, (_error, response, body) => {
if (response.statusCode !== 201) {
console.log(chalk.red(body));
reject(chalk.red('Get upload token failed!'));
} else {
resolve(JSON.parse(body));
}
});
});
}