const { db, _ } = require("../../utils/http"); async function MediaService(data) { const list = []; const orilist = await db.collection('AudioAndVideo').where({ type: _.eq(data.typeMedia) }).get(); const keysOir = {}; for (let i = 0; i < orilist.data.length; i++) { const v = orilist.data[i]; if (keysOir[v.localtion] !== undefined) { // 已经存在 list[keysOir[v.localtion]].child.push({ url: v.url, title: v.title, cover: v.cover, id: v._id }) } else { // push keysOir[v.localtion] = list.length; list.push({ location: v.localtion, date: v.uptime, id: v._id, child: [ { url: v.url, title: v.title, cover: v.cover, id: v._id } ] }) } } return list } async function MediaOnceService(data) { const list = []; const orilist = await db.collection('AudioAndVideo').where({ type: _.eq(data.typeMedia), localtion: _.eq(data.group) }).get(); const keysOir = {}; for (let i = 0; i < orilist.data.length; i++) { const v = orilist.data[i]; if (keysOir[v.localtion] !== undefined) { // 已经存在 list[keysOir[v.localtion]].child.push({ url: v.url, title: v.title, cover: v.cover, id: v._id }) } else { // push keysOir[v.localtion] = list.length; list.push({ location: v.localtion, date: v.uptime, id: v._id, child: [ { url: v.url, title: v.title, cover: v.cover, id: v._id } ] }) } } return list } module.exports = { MediaService, MediaOnceService }