t-comm
Version:
专业、稳定、纯粹的工具库
117 lines (114 loc) • 3.37 kB
JavaScript
import { b as __awaiter, c as __generator } from '../tslib.es6-096fffdd.js';
import { asyncExportTencentDoc, checkExportTencentDocProgress } from './tencent-doc.mjs';
import 'axios';
function checkUrl(_a) {
var accessToken = _a.accessToken,
clientId = _a.clientId,
openId = _a.openId,
fileId = _a.fileId,
operationId = _a.operationId;
return __awaiter(this, void 0, void 0, function () {
var res;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
return [4 /*yield*/, 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 __awaiter(this, void 0, void 0, function () {
var res;
return __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 __awaiter(this, void 0, void 0, function () {
var data, operationId;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
return [4 /*yield*/, 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
})];
}
});
});
}
export { exportTencentDoc };