-
Notifications
You must be signed in to change notification settings - Fork 17
/
utils.js
38 lines (35 loc) · 1.14 KB
/
utils.js
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
/* Copyright (c) Meta Platforms, Inc. and affiliates.
// All rights reserved.
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
*/
const { default: axios } = require("axios");
/**
* Setting retries with 3 seconds delay, as async video upload may take a while in the backed to return success
* @param {*} n
* @returns
*/
function _wait(n) { return new Promise(resolve => setTimeout(resolve, n)); }
/**
* Retrieves container status for the uploaded video, while its uploading in the backend asynchronously
* and checks if the upload is complete.
* @param {*} retryCount
* @param {*} checkStatusUri
* @returns Promise<boolean>
*/
const isUploadSuccessful = async(retryCount, checkStatusUri) => {
try {
if (retryCount > 30) return false;
const response = await axios.get(checkStatusUri);
if(response.data.status_code != "FINISHED") {
await _wait(3000);
await isUploadSuccessful(retryCount+1, checkStatusUri);
}
return true;
} catch(e) {
throw e;
}
}
module.exports = {
isUploadSuccessful
}