index.js 2.0 KB

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