Adding media and recent watch media

This commit is contained in:
aeroreyna
2022-12-30 07:54:49 -05:00
parent b616a6f6f9
commit 2e339f6b36
2 changed files with 112 additions and 7 deletions
+83
View File
@@ -101,6 +101,15 @@ DB.getDB.then((DB) => {
return res.json(posts);
});
router.get("/usr/:id/images", async (req, res) => {
const profileid = req.params.id;
const posts = await DB.getMediaTagPostOfUser(profileid);
return res.json({
status: "ok",
posts
});
});
router.get("/video/:id", async (req, res) => {
videoId = req.params.id;
return res.json([]);
@@ -218,6 +227,80 @@ DB.getDB.then((DB) => {
})
});
router.get("/images", async (req, res) => {
const profileid = getProfileId(req);
const posts = await DB.getMediaTagPostOfUser(profileid);
return res.json({
status: "ok",
posts
});
});
router.get("/embedded", async (req, res) => {
const profileid = getProfileId(req);
const posts = await DB.getMediaTagPostOfUser(profileid, "@iframe:");
return res.json({
status: "ok",
posts
});
});
router.get("/media", async (req, res) => {
const profileid = getProfileId(req);
const posts = await DB.getMediaTagPostOfUser(profileid, "@youtube:|@vimeo:|@hls:");
return res.json({
status: "ok",
posts
});
});
router.get("/course/recent", async (req, res) => {
const profileid = getProfileId(req);
const profile = await DB.getProfileCache(profileid);
const mediaPostsId = []
const recentMedia = {};
const mediaProfileP = []
let postPromises = [];
// Get watch information from profile data
Object.keys(profile.data).forEach(key => {
// So far we only use watch info using postid keys
if(DB.ObjectID.isValid(key)){
mediaPostsId.push(profile.data[key]);
postPromises.push(DB.getPostCached(profile.data[key].postId));
if(!recentMedia[profile.data[key].profileId]){
recentMedia[profile.data[key].profileId] = [];
mediaProfileP.push(DB.getProfileCache(profile.data[key].profileId));
}
}
});
recentMediaArray = mediaPostsId.sort((a,b)=>{
return b.ts - a.ts;
});
const postObjs = await Promise.all(postPromises);
const postObjsMap = postObjs.reduce((map, item)=>{
map[item._id] = item;
return map
}, {});
recentMediaArray.forEach(record => {
const postAndRecord = {
watchRecord: record,
... postObjsMap[record.postId]
}
recentMedia[record.profileId].push(postAndRecord);
});
// Transform profiles array to dict
let mediaProfile = await Promise.all(mediaProfileP);
let mediaProfileMap = mediaProfile.reduce((dict, item) => {
dict[item._id] = item;
return dict;
}, {});
return res.json({
status: "ok",
recentMedia,
mediaProfileMap,
});
});
router.get("/:id", async (req, res) => {
const postId = req.params.id;
const post = await DB.getPost(postId);