index.js 1.7 KB

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