def post(self): """ video create api """ data = request.get_json() data = mash_load_validate(self.raw_video_schema, data) video_data = self.convert_timestamp_info(data) video = mash_load_validate(self.video_schema, video_data) ret = self.video_schema.dump(video.save()) current_app.logger.info('video %s created successfully', video.title) return ret, http.HTTPStatus.CREATED
def post(self, video_id): """ post api for subvideos """ data = request.get_json() video = Video.query.get(video_id) if not video: return { 'message': 'video entry not exist' }, http.HTTPStatus.NOT_FOUND raw_file = mash_load_validate(self.raw_file_schema, data) dest_path = os.path.join(current_app.config['FILE_STORAGE_PATH'], video.title, raw_file['name']) self.convert_tmpfile(raw_file['num'], dest_path) videofile_data = {'name': raw_file['name'], 'file_path': dest_path} videofile = mash_load_validate(self.videofile_schema, videofile_data) video.video_files.append(videofile) ret = self.video_schema.dump(video.save()) return ret, http.HTTPStatus.OK
def put(self): """ modify user avatar api """ raw_data = request.get_json() data = mash_load_validate(self.avatar_schema, raw_data) user = User.query.filter_by(id=get_jwt_identity()).first() origin_avatar = user.avatar_image storage_path = self.storage_path.format( storage_path=current_app.config.get('FILE_STORAGE_PATH'), username=user.username) self.save_image(data['file_name'], data['image_name'], storage_path) user.avatar_image = data['image_name'] user.save() self.delete_avatar(origin_avatar, storage_path) ret = self.user_schema.dump(user) return ret, HTTPStatus.OK
def put(self, video_id): """ video put api """ video = Video.query.get(video_id) data = request.get_json() exclude_fields = list(item for item in self.video_schema.load_fields if item not in data) include_fields = list(item for item in data if item in self.video_schema.load_fields) exclude_fields.append('image_files') exclude_fields.append('video_files') updated_video = mash_load_validate(self.video_schema, data, partial=exclude_fields) for key in include_fields: setattr(video, key, getattr(updated_video, key)) video.save() result = self.video_schema.dump(video) return result, http.HTTPStatus.OK
def post(self): """ user sign in api and send email """ data = request.get_json() user = mash_load_validate(self.user_schema, data) ret = UserSchema(exclude=('created_at', 'updated_at', 'is_activate')).dump(user.save()) token = generate_token(user.email, salt='activate') subject = 'Please confirm your registration' link = url_for('user_route.useractivateresource', token=token, _external=True) text = 'Hi, Thanks for using multimedia manager! Please confirm your registration\ by clicking on the link: {}'.format(link) send_mail.delay(subject=subject, sender='*****@*****.**', recipients=[user.email], text=text) # current_app.logger.info('user %s send activate email successfully', user.username) return ret, HTTPStatus.CREATED