index.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright (C) 2020 Tencent Cloud.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. 'use strict';
  17. const { request } = require('./utils.js');
  18. /**
  19. * 获取机器翻译结果
  20. * @param {object} params - 参数包装对象
  21. * @param {string} params.name - 机器翻译 API的Action值 https://cloud.tencent.com/document/product/551/15612
  22. * @param {object} params.payload - API需要的参数
  23. * @return {Promise<object>} API返回数据
  24. */
  25. async function getTmtResult(params) {
  26. if (!params.name) {
  27. throw new Error('缺少API Action参数');
  28. }
  29. try {
  30. const result = await request(params.name, params.payload);
  31. return result;
  32. } catch (e) {
  33. throw new Error(e);
  34. }
  35. }
  36. module.exports = {
  37. getTmtResult
  38. };