예제 #1
0
파일: Hashing.cs 프로젝트: Bitz/OwO_Bot
        public static Models.Hashing.ImgHash FromPost(Post post)
        {
            Models.Hashing.ImgHash response = new Models.Hashing.ImgHash();
            string path      = post.Url.ToString();
            string extension = Path.GetExtension(path);
            string returnUrl = GoodExtensions.Any(x => x.Equals(extension) && !String.IsNullOrEmpty(extension))
                ? post.Url.ToString()
                : Html.GetOg(post.Url.ToString());

            response.IsValid = Uri.TryCreate(returnUrl, UriKind.Absolute, out var test) &&
                               (test.Scheme == Uri.UriSchemeHttp || test.Scheme == Uri.UriSchemeHttps);
            response.Url       = returnUrl;
            response.PostId    = post.Id;
            response.SubReddit = post.SubredditName;
            if (response.IsValid)
            {
                response.ImageHash = GetHash(response.Url);
                if (response.ImageHash == null || response.ImageHash.Length == 0)
                {
                    response.IsValid = false;
                }
            }
            response.CreatedDate = DateTime.Now;
            return(response);
        }
예제 #2
0
파일: Get.cs 프로젝트: Bitz/OwO_Bot
 public static string GetUrl(Models.Hashing.ImgHash image)
 {
     return($"https://reddit.com/r/{image.SubReddit}/comments/{image.PostId}");
 }