Beispiel #1
0
        public async Task <IActionResult> GetEntity([FromQuery] string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(BadRequest());
            }
            var key = KeyGenerator.Concat(EntityKey, url);
            var res = memoryCache.Get <AnfComicEntityTruck>(key);

            if (res == null)
            {
                res = await rootFetcher.FetchEntityAsync(url);

                memoryCache.Set(key, res, new MemoryCacheEntryOptions
                {
                    SlidingExpiration = CacheTime
                });
            }
            if (res != null)
            {
                await comicRankService.IncVisitAsync(res.ComicUrl, 1);

                await visitStatisticalService.AddAsync(new AnfVisitCount
                {
                    Address = url,
                    IP      = HttpContext.Connection.RemoteIpAddress?.ToString(),
                    Time    = DateTime.Now,
                    UserId  = HttpContext.Features.Get <UserSnapshot>()?.Id
                });
            }
            return(Ok(res));
        }
Beispiel #2
0
        public async Task <IActionResult> GetEntity([FromQuery] string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(BadRequest());
            }
            var key = RedisKeyGenerator.Concat(EntityKey, url);
            var res = memoryCache.Get <AnfComicEntityTruck>(key);

            if (res != null)
            {
                await comicRankService.AddScopeAsync(url);

                return(Ok(res));
            }
            res = await rootFetcher.FetchEntityAsync(url);

            if (res != null)
            {
                await comicRankService.AddScopeAsync(url);

                memoryCache.Set(key, res, new MemoryCacheEntryOptions
                {
                    SlidingExpiration = CacheTime
                });
            }
            return(Ok(res));
        }
Beispiel #3
0
        protected override async Task <ComicEntity> MakeEntityAsync(string address)
        {
            var entity = await rootFetcher.FetchEntityAsync(address);

            if (entity is null)
            {
                return(null);
            }
            await comicRankService.IncVisitAsync(entity.ComicUrl, 1);

            return(new ComicEntity
            {
                Chapters = entity.Chapters,
                ComicUrl = entity.ComicUrl,
                Descript = entity.Descript,
                ImageUrl = entity.ImageUrl,
                Name = entity.Name
            });
        }