mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-18 10:20:39 +08:00
v1.0.5
This commit is contained in:
19
src/api.js
19
src/api.js
@@ -8,6 +8,10 @@ const fs = require('fs-extra');
|
||||
import request from 'request';
|
||||
import ProgressBar from 'progress';
|
||||
const packageJson = require('../package.json');
|
||||
const tcpp = require('tcp-ping');
|
||||
const util = require('util');
|
||||
|
||||
const tcpPing = util.promisify(tcpp.ping);
|
||||
|
||||
let session = undefined;
|
||||
let savedSession = undefined;
|
||||
@@ -98,11 +102,20 @@ exports.put = queryWithBody('PUT');
|
||||
exports.doDelete = queryWithBody('DELETE');
|
||||
|
||||
async function uploadFile(fn) {
|
||||
const { url, formData } = await exports.post('/upload', {});
|
||||
const { url, backupUrl, formData } = await exports.post('/upload', {});
|
||||
let realUrl = url;
|
||||
|
||||
if (!/^https?\:\/\//.test(url)) {
|
||||
realUrl = host + url;
|
||||
if (backupUrl) {
|
||||
const pingResult = await tcpPing({
|
||||
address: url.replace('https://', ''),
|
||||
attempts: 3,
|
||||
timeout: 3000,
|
||||
});
|
||||
// console.log({pingResult});
|
||||
if (pingResult.avg > 100) {
|
||||
realUrl = backupUrl;
|
||||
}
|
||||
// console.log({realUrl});
|
||||
}
|
||||
|
||||
const fileSize = fs.statSync(fn).size;
|
||||
|
Reference in New Issue
Block a user