adding vimeo api

This commit is contained in:
aeroreyna
2022-03-13 15:58:30 -07:00
parent 57a91c0470
commit a3fc84fbad
4 changed files with 341 additions and 16 deletions

View File

@@ -4,6 +4,8 @@ var router = express.Router()
const DB = require("./../mongoDB.js");
const Post = require("./../def/post.js");
const Notifications = require("./../notifications.js");
let Vimeo = require('vimeo').Vimeo;
let VimeoClient = new Vimeo(process.env.VIMEO_CLIENT_ID, process.env.VIMEO_CLIENT_SECRET, process.env.VIMEO_TOKEN);
DB.getDB.then((DB) => {
@@ -12,7 +14,7 @@ DB.getDB.then((DB) => {
};
const postBelongToProfile = (post, profileid) => {
if(!post) return false;
if (!post) return false;
return post.profileid == profileid;
};
@@ -25,50 +27,50 @@ DB.getDB.then((DB) => {
// Popular Profiles
const popularProfiles = await DB.getPopularProfiles(5);
content = "Active users to follow:\n";
popularProfiles.forEach((p)=>{
popularProfiles.forEach((p) => {
content += "@p:" + p._id + "\n";
});
let popularProfilesPost = new Post({profileid: 1, content, nonOrganicType: "PopularUsers"});
let popularProfilesPost = new Post({ profileid: 1, content, nonOrganicType: "PopularUsers" });
posts.push(popularProfilesPost);
// Popular Groups
const popularGroups = await DB.getPopularGroups(5);
content = "Popular groups to follow:\n";
popularGroups.forEach((p)=>{
popularGroups.forEach((p) => {
content += "@p:" + p._id + "\n";
});
let popularGroupsPost = new Post({profileid: 1, content, nonOrganicType: "PopularGroups"});
let popularGroupsPost = new Post({ profileid: 1, content, nonOrganicType: "PopularGroups" });
posts.push(popularGroupsPost);
const yourFollowsInterests = await DB.getFriendsFriends(profileid);
content = "People your follow has these interests:\n";
yourFollowsInterests.forEach((p)=>{
yourFollowsInterests.forEach((p) => {
content += "@p:" + p + "\n";
});
let yourFollowsInterestsPost = new Post({profileid: 1, content, nonOrganicType: "PopularUsers"});
let yourFollowsInterestsPost = new Post({ profileid: 1, content, nonOrganicType: "PopularUsers" });
posts.push(yourFollowsInterestsPost);
return posts;
};
const mergePosts = (organic, nonOrganic) => {
if(!organic || organic.length < 5) return nonOrganic;
if (!organic || organic.length < 5) return nonOrganic;
//organic.push(...nonOrganic);
let mergedPosts = [];
while(organic.length + nonOrganic.length){
if(organic.length == 0){
while (organic.length + nonOrganic.length) {
if (organic.length == 0) {
mergedPosts.push(nonOrganic.shift());
continue;
}
if(nonOrganic.length == 0){
if (nonOrganic.length == 0) {
mergedPosts.push(organic.shift());
continue;
}
if(nonOrganic[0].nonOrganicType == 'News'){
if (nonOrganic[0].nonOrganicType == 'News') {
mergedPosts.push(nonOrganic.shift());
continue;
}
if(Math.random() < 0.2){
if (Math.random() < 0.2) {
mergedPosts.push(nonOrganic.shift());
} else {
mergedPosts.push(organic.shift());
@@ -101,6 +103,20 @@ DB.getDB.then((DB) => {
return res.json(posts);
});
router.get("/video/:id", async (req, res) => {
videoId = req.params.id;
if (!videoId) return res.json([]);
VimeoClient.request({
path: '/videos/' + videoId,
}, function (error, body, status_code, headers) {
if (error || status_code !== 200) {
console.log(error);
return res.json([]);
}
return res.json(body);
});
});
router.post("/", async (req, res) => {
let post = {
profileid: getProfileId(req),
@@ -215,7 +231,7 @@ DB.getDB.then((DB) => {
const profileid = getProfileId(req) + '';
const postId = req.params.id;
const post = await DB.getPost(postId);
if(!postBelongToProfile(post, profileid))
if (!postBelongToProfile(post, profileid))
return res.json({
status: "This post is not yours."
});