t-comm
Version:
专业、稳定、纯粹的工具库
121 lines (116 loc) • 3.52 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var tslib_es6 = require('../tslib.es6-01322ba9.js');
var tencentDoc_tencentDoc = require('./tencent-doc.js');
require('axios');
function checkUrl(_a) {
var accessToken = _a.accessToken,
clientId = _a.clientId,
openId = _a.openId,
fileId = _a.fileId,
operationId = _a.operationId;
return tslib_es6.__awaiter(this, void 0, void 0, function () {
var res;
return tslib_es6.__generator(this, function (_b) {
switch (_b.label) {
case 0:
return [4 /*yield*/, tencentDoc_tencentDoc.checkExportTencentDocProgress({
accessToken: accessToken,
clientId: clientId,
openId: openId,
fileId: fileId,
operationId: operationId
})];
case 1:
res = _b.sent();
return [2 /*return*/, res.data];
}
});
});
}
var holding = function holding(time) {
return new Promise(function (resolve) {
setTimeout(function () {
return resolve(time);
}, time);
});
};
function pollCheckUrl(_a) {
var accessToken = _a.accessToken,
clientId = _a.clientId,
openId = _a.openId,
fileId = _a.fileId,
operationId = _a.operationId,
waitTime = _a.waitTime;
return tslib_es6.__awaiter(this, void 0, void 0, function () {
var res;
return tslib_es6.__generator(this, function (_b) {
switch (_b.label) {
case 0:
return [4 /*yield*/, holding(waitTime)];
case 1:
_b.sent();
return [4 /*yield*/, checkUrl({
accessToken: accessToken,
clientId: clientId,
openId: openId,
fileId: fileId,
operationId: operationId
})];
case 2:
res = _b.sent();
console.log('[checkUrl] res: ', res);
if (res.url) {
return [2 /*return*/, res.url];
}
return [2 /*return*/, pollCheckUrl({
accessToken: accessToken,
clientId: clientId,
openId: openId,
fileId: fileId,
operationId: operationId,
waitTime: waitTime
})];
}
});
});
}
function exportTencentDoc(_a) {
var accessToken = _a.accessToken,
clientId = _a.clientId,
openId = _a.openId,
fileId = _a.fileId,
exportType = _a.exportType,
_b = _a.waitTime,
waitTime = _b === void 0 ? 0 : _b;
return tslib_es6.__awaiter(this, void 0, void 0, function () {
var data, operationId;
return tslib_es6.__generator(this, function (_c) {
switch (_c.label) {
case 0:
return [4 /*yield*/, tencentDoc_tencentDoc.asyncExportTencentDoc({
accessToken: accessToken,
clientId: clientId,
openId: openId,
fileId: fileId,
exportType: exportType
})];
case 1:
data = _c.sent();
console.log('[asyncExportTencentDoc] data: ', data);
operationId = (data.data || {}).operationID;
console.log('[exportTencentDoc] operationId: ', operationId);
if (!operationId) return [2 /*return*/];
return [2 /*return*/, pollCheckUrl({
accessToken: accessToken,
clientId: clientId,
openId: openId,
fileId: fileId,
operationId: operationId,
waitTime: waitTime
})];
}
});
});
}
exports.exportTencentDoc = exportTencentDoc;