Ejemplo n.º 1
0
        public static FeedsIndexDoc ToFeedIndexDoc(this UserReaction reaction, string[] likedby, string[] sharedby)
        {
            var doc = new FeedsIndexDoc
            {
                Id       = reaction.ArticleId,
                LikedBy  = likedby,
                SharedBy = sharedby
            };

            return(doc);
        }
Ejemplo n.º 2
0
        public async Task <bool> PostArticle([FromBody] UnpublishedPost post)
        {
            DocumentIndexResult uploadedDoc;

            try
            {
                if (post.ShouldSkip)
                {
                    SkippedUrlsIndexDoc skippedDoc = post.ToSkippedUrlsIndexDoc();
                    uploadedDoc = await _skippedUrlsIndex.UploadDocument(skippedDoc);

                    return(uploadedDoc.Results.First().Succeeded);
                }

                FeedsIndexDoc doc = post.ToFeedsIndexDoc();

                // Upload image to local resource
                var filename   = string.Format("{0}.jpeg", doc.Id);
                var uploadSucc = await _ds.UploadImageAsync(filename, doc.ImageUrl);

                // If tagged, upload to image db
                bool imageUploaded = true;
                var  uploadedUrl   = string.Format("https://storage.googleapis.com/www.archishainnovators.com/images/{0}", filename);
                if (post.Image.Tags.Any())
                {
                    ImagesIndexDoc imageDoc = new ImagesIndexDoc
                    {
                        Id        = doc.Id,
                        DateAdded = DateTime.Now,
                        SourceUrl = doc.ImageUrl,
                        Url       = uploadedUrl,
                        Tags      = post.Image.Tags
                    };
                    var uploadResult = await _imagesIndex.UploadDocument(imageDoc);

                    imageUploaded = uploadResult.Results.First().Succeeded;
                }
                doc.ImageUrl = uploadedUrl;

                // Upload post
                uploadedDoc = await _feedsIndex.UploadDocument(doc);

                return(uploadedDoc.Results.First().Succeeded&& imageUploaded);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 3
0
        public static PublishedPost ToPublishedPost(this FeedsIndexDoc indexDoc)
        {
            var publishedPost = new PublishedPost
            {
                Id           = indexDoc.Id,
                Heading      = indexDoc.Title,
                Snippet      = indexDoc.Text,
                CreatedTime  = indexDoc.CreatedTime.HasValue ? indexDoc.CreatedTime.Value : DateTime.UtcNow,
                ImageUrl     = indexDoc.ImageUrl,
                OriginalLink = indexDoc.OriginalLink,
                CardStyle    = indexDoc.CardStyle,
                PostedBy     = indexDoc.PostedBy,
                SharedBy     = indexDoc.SharedBy,
                LikedBy      = indexDoc.LikedBy,
                Streams      = indexDoc.Streams,
                Language     = indexDoc.Language,
                Tags         = indexDoc.Tags
            };

            return(publishedPost);
        }
Ejemplo n.º 4
0
        public static FeedsIndexDoc ToFeedsIndexDoc(this UnpublishedPost unpublishedPost)
        {
            var doc = new FeedsIndexDoc
            {
                Id             = Guid.NewGuid().ToString(),
                Title          = unpublishedPost.Heading,
                Text           = unpublishedPost.Snippet,
                CreatedTime    = DateTime.UtcNow,
                ImageUrl       = unpublishedPost.Image.Url,
                LandingPageUrl = unpublishedPost.OriginalLink.ToLower(),
                OriginalLink   = unpublishedPost.OriginalLink,
                CardStyle      = unpublishedPost.CardStyle.ToLower(), // TODO:
                PostedBy       = unpublishedPost.PostedBy.ToLower(),
                SharedBy       = new string[] { },
                LikedBy        = new string[] { },
                Language       = unpublishedPost.Language.ToLower(),
                Tags           = unpublishedPost.Tags,
                Streams        = unpublishedPost.Streams
            };

            return(doc);
        }