index.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 { report } = require('./common');
  18. const modules = {
  19. COS: require('./cos'),
  20. SMS: require('./sms'),
  21. OCR: require('./ocr'),
  22. VOD: require('./vod'),
  23. CAPTCHA: require('./captcha'),
  24. TIIA: require('./tiia'),
  25. TMS: require('./tms'),
  26. IMS: require('./ims'),
  27. ASR: require('./asr'),
  28. SOE: require('./soe'),
  29. HTTPDNS: require('./httpdns'),
  30. TTS: require('./tts'),
  31. TMT: require('./tmt'),
  32. IAI: require('./iai'),
  33. FACEID: require('./faceid')
  34. };
  35. /**
  36. * 腾讯云uni-app插件依赖的云函数入口
  37. * @param {object} event - 通过uniCloud.callFunction调用云函数时传入的data对象
  38. * @param {string} event.module - 云函数模块(目前仅支付传入"COS"),必传参数
  39. * @param {string} event.action - 云函数模块下的方法名,必传参数
  40. * @return {Promise<any>}
  41. */
  42. exports.main = async (event) => {
  43. const { module, action, ...params } = event;
  44. if (!modules[module] || !modules[module][action]) {
  45. throw new Error(`${module}.${action}不存在`);
  46. }
  47. // 数据统计
  48. const getExtraInfoMethod = modules[module].getExtraReportInfo;
  49. const extraInfo = getExtraInfoMethod ? getExtraInfoMethod() : {};
  50. report(module, extraInfo);
  51. // 调用相应的模块
  52. const result = await modules[module][action](params);
  53. return result;
  54. };