Exemplo n.º 1
0
        private async Task <string> Fetch(string id)
        {
            using (var hc = new HttpClient(new HttpClientHandler {
                AllowAutoRedirect = false
            }))
            {
                var requestUri = "http://cameran.in/p/v1/" + id;
                ResolverUtils.RequestingMessage(this._logger, requestUri, null);

                using (var res = await hc.GetAsync(requestUri).ConfigureAwait(false))
                {
                    switch (res.StatusCode)
                    {
                    case HttpStatusCode.NotFound:
                    case HttpStatusCode.Found:
                    case HttpStatusCode.SeeOther:
                        throw new ImageNotFoundException();
                    }

                    res.EnsureSuccessStatusCode();

                    return(ResolverUtils.GetOgImage(
                               await res.Content.ReadAsHtmlDocument().ConfigureAwait(false)));
                }
            }
        }
Exemplo n.º 2
0
        private async Task <CacheItem> FetchFile(string id)
        {
            var document = await this.DownloadHtml(id).ConfigureAwait(false);

            // body の class に preview-photo または preview-video があるならば対応
            return(new CacheItem
            {
                Type = document.Body.ClassList
                       .Where(x => x.StartsWith("preview-", StringComparison.Ordinal))
                       .Select(x => x.Substring(8)).SingleOrDefault(),
                OgImage = ResolverUtils.GetOgImage(document)
            });
        }