def _add_info_and_popularity(cls, all_vids, viewer_uuid, token, sort_by_pop=False): final_vids = [] for v in all_vids: res = v.serialize() if cls._cant_view(res["is_private"], res["uuid"], viewer_uuid): continue cls.add_extra_info(res, viewer_uuid) res["author"] = AuthSender.get_author_name(res["uuid"], token) if sort_by_pop: res["popularity"] = cls._calculate_popularity( v, viewer_uuid, res["timestamp"]) final_vids.append(res) if sort_by_pop: final_vids = sorted(final_vids, key=lambda k: k['popularity'], reverse=True) return final_vids
def get(self, vid_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') args = parser.parse_args() self.logger.debug("getting uuid from token, via authsv") uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) self.logger.debug("getting single vid from videoDAO") vid = VideoDAO.get(vid_id, uuid) vid["author"] = AuthSender.get_author_name(vid["uuid"], args["x-access-token"]) self.logger.info(f"Retrieved single video, id {vid_id}, info: {vid}. RESPONSECODE:200") return vid, 200
def post(self, other_user_id): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers', required=True, help='Missing user token!') parser.add_argument("text", location='json', type=str, required=True, help='You must include the text to be sent!') args = parser.parse_args() if args["text"] == "": raise BadRequestError("Invalid message length") sender_uuid = AuthSender.get_uuid_from_token(args['x-access-token']) author_name = AuthSender.get_author_name(sender_uuid, args["x-access-token"]) if not UsersDAO.are_friends(sender_uuid, other_user_id): raise BadRequestError("You are not friends with this user") msg = ChatsDAO.send_message(sender_uuid, other_user_id, args["text"], author_name) self.logger.info(f"Succesfully sent message from user {sender_uuid} to {other_user_id}. RESPONSECODE:200") return msg, 201
def add_cmnt(cls, vid_id, uuid, text, time, tkn): new_cmnt = Comment(uuid=uuid, text=text, vid_time=time) vid = VideoDAO.get_raw(vid_id) new_cmnt.video = vid db.session.add(new_cmnt) db.session.commit() cls.logger().info( f"Succesfully appended comment to video {vid_id}. Comment: {new_cmnt.serialize()}" ) vid.update_relevance() # Notification build w/tkn... cmnt_author = AuthSender.get_author_name(uuid, tkn) if uuid != vid.uuid: NotificationsCreator.notify_new_comment(vid.uuid, vid_id, vid.title, text, cmnt_author) return new_cmnt.serialize()
def get_videos_by(cls, user_id, viewer_uuid, token): cls.logger().info(f"Grabbing all videos by user {user_id}") UsersDAO.check_exists(user_id) videos = [ v.serialize() for v in Video.query.filter(Video.uuid == user_id) ] cls.logger().info( f"Filtering by viewable videos for viewer {viewer_uuid}") filtered = [ f for f in videos if not cls._cant_view(f["is_private"], viewer_uuid, user_id) ] for f in filtered: cls.add_extra_info(f, viewer_uuid) f["author"] = AuthSender.get_author_name(f["uuid"], token) cls.logger().info( f"Found {len(filtered)} viewable videos uploaded by user {user_id}" ) return filtered
def post(self): parser = reqparse.RequestParser() parser.add_argument("x-access-token", location='headers') parser.add_argument( "to", type=int, required=True, help="You must specify who you are sending this request to", location='json') args = parser.parse_args() sender_uuid = AuthSender.get_uuid_from_token(args["x-access-token"]) author_name = AuthSender.get_author_name(sender_uuid, args["x-access-token"]) msg = UsersDAO.send_request(sender_uuid, args["to"], author_name) self.logger.info( f"Succesfully sent request from user {sender_uuid} to {args['to']}. RESPONSECODE:201" ) return msg, 201