private async Task <GetPostQueryResult.File> ProcessFile(GetPostQueryResult.FullPost post, GetPostDbResult.PostFileDbResult file, PostSecurityResult access, AccessSignatureExpiryInformation expiry) { var fileInformation = await this.fileInformationAggregator.GetFileInformationAsync(post.ChannelId, file.FileId, file.Purpose); RenderSize renderSize = null; if (file.RenderWidth.HasValue && file.RenderHeight.HasValue) { renderSize = new RenderSize(file.RenderWidth.Value, file.RenderHeight.Value); } var fileSourceInformation = new FileSourceInformation( file.FileName, file.FileExtension, this.mimeTypeMap.GetMimeType(file.FileExtension), file.FileSize, renderSize); BlobSharedAccessInformation accessInformation = null; if (access == PostSecurityResult.Denied) { if (file.Purpose == FilePurposes.PostImage) { accessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( fileInformation.ContainerName, file.FileId.Value.EncodeGuid() + "/" + FileManagement.Shared.Constants.PostPreviewImageThumbnailName, expiry.Private); } } else if (access == PostSecurityResult.FreePost) { if (file.Purpose == FilePurposes.PostImage) { accessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( fileInformation.ContainerName, file.FileId.Value.EncodeGuid() + "/" + FileManagement.Shared.Constants.PostFeedImageThumbnailName, expiry.Private); } else if (file.Purpose == FilePurposes.PostFile) { accessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( fileInformation.ContainerName, file.FileId.Value.EncodeGuid(), expiry.Private); } } var completeFile = new GetPostQueryResult.File(fileInformation, fileSourceInformation, accessInformation); return(completeFile); }
public async Task <IReadOnlyList <GetCreatorBacklogQueryResult> > HandleAsync(GetCreatorBacklogQuery query) { query.AssertNotNull("query"); await this.requesterSecurity.AuthenticateAsAsync(query.Requester, query.RequestedUserId); await this.requesterSecurity.AssertInRoleAsync(query.Requester, FifthweekRole.Creator); var posts = await this.getCreatorBacklogDbStatement.ExecuteAsync(query.RequestedUserId, DateTime.UtcNow); var result = new List <GetCreatorBacklogQueryResult>(); foreach (var post in posts) { FileInformation image = null; if (post.ImageId != null) { image = await this.fileInformationAggregator.GetFileInformationAsync( post.ChannelId, post.ImageId, FilePurposes.PostImage); } RenderSize imageRenderSize = null; if (post.ImageRenderWidth.HasValue && post.ImageRenderHeight.HasValue) { imageRenderSize = new RenderSize(post.ImageRenderWidth.Value, post.ImageRenderHeight.Value); } var completePost = new GetCreatorBacklogQueryResult( post.PostId, post.ChannelId, post.QueueId, post.PreviewText, image, image == null ? null : new FileSourceInformation(post.ImageName, post.ImageExtension, this.mimeTypeMap.GetMimeType(post.ImageExtension), post.ImageSize ?? 0, imageRenderSize), post.PreviewWordCount, post.WordCount, post.ImageCount, post.FileCount, post.VideoCount, post.LiveDate); result.Add(completePost); } return(result); }
public async Task <GetPreviewNewsfeedQueryResult> HandleAsync(GetNewsfeedQuery query) { query.AssertNotNull("query"); var requestingUserId = await this.requesterSecurity.TryAuthenticateAsync(query.Requester); var now = this.timestampCreator.Now(); var postsResult = await this.getPreviewNewsfeedDbStatement.ExecuteAsync( requestingUserId, query.CreatorId, query.ChannelIds, now, query.Origin ?? now, query.SearchForwards, query.StartIndex, query.Count); var posts = postsResult.Posts; var expiry = this.getAccessSignatureExpiryInformation.Execute(now); var results = new List <GetPreviewNewsfeedQueryResult.PreviewPost>(); foreach (var post in posts) { FileInformation profileImage = null; if (post.ProfileImageFileId != null) { profileImage = await this.fileInformationAggregator.GetFileInformationAsync( null, post.ProfileImageFileId, FilePurposes.ProfileImage); } FileInformation image = null; BlobSharedAccessInformation imageAccessInformation = null; if (post.ImageId != null) { image = await this.fileInformationAggregator.GetFileInformationAsync( post.ChannelId, post.ImageId, FilePurposes.PostImage); var imageType = post.IsFreePost ? FileManagement.Shared.Constants.PostFeedImageThumbnailName : FileManagement.Shared.Constants.PostPreviewImageThumbnailName; imageAccessInformation = await this.blobService.GetBlobSharedAccessInformationForReadingAsync( image.ContainerName, image.FileId.Value.EncodeGuid() + "/" + imageType, expiry.Public); } RenderSize imageRenderSize = null; if (post.ImageRenderWidth.HasValue && post.ImageRenderHeight.HasValue) { imageRenderSize = new RenderSize(post.ImageRenderWidth.Value, post.ImageRenderHeight.Value); } var completePost = new GetPreviewNewsfeedQueryResult.PreviewPost( post.CreatorId, new GetPreviewNewsfeedQueryResult.PreviewPostCreator(new Username(post.Username), profileImage), post.PostId, post.BlogId, new GetPreviewNewsfeedQueryResult.PreviewPostBlog(new BlogName(post.BlogName), null, null), post.ChannelId, new GetPreviewNewsfeedQueryResult.PreviewPostChannel(new ChannelName(post.ChannelName)), post.PreviewText, image, image == null ? null : new FileSourceInformation(post.ImageName, post.ImageExtension, this.mimeTypeMap.GetMimeType(post.ImageExtension), post.ImageSize ?? 0, imageRenderSize), imageAccessInformation, post.PreviewWordCount, post.WordCount, post.ImageCount, post.FileCount, post.VideoCount, post.LiveDate, post.LikesCount, post.CommentsCount, post.HasLikedPost, post.IsFreePost); results.Add(completePost); } return(new GetPreviewNewsfeedQueryResult(results)); }