forked from wangsijie/static-deploy-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.js
More file actions
27 lines (24 loc) · 733 Bytes
/
get.js
File metadata and controls
27 lines (24 loc) · 733 Bytes
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
const fs = require('fs');
const getClient = require('./oss');
module.exports = async ({ aliyun, local, remote, force }) => {
const client = getClient(aliyun);
if (!force && fs.existsSync(local)) {
throw new Error('local file already exists: ' + local);
}
let tryTime = 1;
const get = async () => {
try {
return client.get(remote, local);
} catch (e) {
tryTime--;
if (tryTime && !process.env.DISABLE_RETRY) {
console.log(`Retrying: ${local}`);
await new Promise(r => setTimeout(r, 1000))
await get();
} else {
throw e;
}
}
}
return await get();
}