index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. const success = {
  3. success: true
  4. }
  5. const fail = {
  6. success: false
  7. }
  8. const checkVersion = require('./checkVersion')
  9. exports.main = async (event, context) => {
  10. //event为客户端上传的参数
  11. const db = uniCloud.database()
  12. const appListDBName = 'opendb-app-list'
  13. const appVersionDBName = 'opendb-app-versions'
  14. let res = {};
  15. let params = event.data || event.params;
  16. switch (event.action) {
  17. case 'checkVersion':
  18. res = await checkVersion(event, context)
  19. break;
  20. case 'deleteFile':
  21. res = await uniCloud.deleteFile({
  22. fileList: params.fileList
  23. })
  24. break;
  25. case 'setNewAppData':
  26. params.value.create_date = Date.now()
  27. res = await db.collection(appListDBName).doc(params.id).set(params.value)
  28. break;
  29. case 'getAppInfo':
  30. let dbAppList
  31. try {
  32. dbAppList = db.collection(appListDBName)
  33. } catch (e) {}
  34. if (!dbAppList) return fail;
  35. const dbAppListRecord = await dbAppList.where({
  36. appid: params.appid
  37. }).get()
  38. if (dbAppListRecord && dbAppListRecord.data.length)
  39. return Object.assign({}, success, dbAppListRecord.data[0])
  40. //返回数据给客户端
  41. return fail
  42. break;
  43. case 'getAppVersionInfo':
  44. let dbVersionList
  45. try {
  46. dbVersionList = db.collection(appVersionDBName)
  47. } catch (e) {}
  48. if (!dbVersionList) return fail;
  49. const dbVersionListrecord = await dbVersionList.where({
  50. appid: params.appid,
  51. platform: params.platform,
  52. type: "native_app",
  53. stable_publish: true
  54. })
  55. .orderBy('create_date', 'desc')
  56. .get();
  57. if (dbVersionListrecord && dbVersionListrecord.data && dbVersionListrecord.data.length > 0)
  58. return Object.assign({}, dbVersionListrecord.data[0], success)
  59. return fail
  60. break;
  61. }
  62. //返回数据给客户端
  63. return res
  64. };