index.js 1.8 KB

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