index.js 1.9 KB

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