index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const {
  2. db,
  3. _
  4. } = require("../../utils/http");
  5. async function MediaService(data) {
  6. const list = [];
  7. const skip = (data.skip || 0) * (data.limit || 100);
  8. console.log('---------------', data)
  9. const orilist = await db.collection('AudioAndVideo').where({
  10. type: _.eq(data.typeMedia),
  11. activity_name: _.eq(data.activityName)
  12. }).skip(skip).limit(data.limit || 100).get();
  13. const keysOir = {};
  14. for (let i = 0; i < orilist.data.length; i++) {
  15. const v = orilist.data[i];
  16. if (keysOir[v.localtion] !== undefined) {
  17. // 已经存在
  18. list[keysOir[v.localtion]].child.push({
  19. url: v.url,
  20. title: v.title,
  21. cover: v.cover,
  22. id: v._id,
  23. type: v.type
  24. })
  25. } else {
  26. // push
  27. keysOir[v.localtion] = list.length;
  28. list.push({
  29. location: v.localtion,
  30. date: v.uptime,
  31. id: v._id,
  32. child: [{
  33. url: v.url,
  34. title: v.title,
  35. cover: v.cover,
  36. id: v._id,
  37. type: v.type
  38. }]
  39. })
  40. }
  41. }
  42. return list
  43. }
  44. async function MediaOnceService(data) {
  45. const list = [];
  46. const orilist = await db.collection('AudioAndVideo').where({
  47. type: _.eq(data.typeMedia),
  48. localtion: _.eq(data.group),
  49. activity_name: _.eq(data.activityName)
  50. }).get();
  51. const keysOir = {};
  52. for (let i = 0; i < orilist.data.length; i++) {
  53. const v = orilist.data[i];
  54. if (keysOir[v.localtion] !== undefined) {
  55. // 已经存在
  56. list[keysOir[v.localtion]].child.push({
  57. url: v.url,
  58. title: v.title,
  59. cover: v.cover,
  60. id: v._id,
  61. type: v.type
  62. })
  63. } else {
  64. // push
  65. keysOir[v.localtion] = list.length;
  66. list.push({
  67. location: v.localtion,
  68. date: v.uptime,
  69. id: v._id,
  70. child: [{
  71. url: v.url,
  72. title: v.title,
  73. cover: v.cover,
  74. id: v._id,
  75. type: v.type
  76. }]
  77. })
  78. }
  79. }
  80. return list
  81. }
  82. module.exports = {
  83. MediaService,
  84. MediaOnceService
  85. }