Beispiel #1
0
        public async Task <Response <string> > BulkInsertHotNewsAsync([FromBody] IList <InsertHotNewsDto> dtos)
        {
            var response = new Response <string>();

            string spider = HttpContext.Request.Headers["spider"];

            if (spider != "python")
            {
                response.Msg = "缺少HEADERS值";
                return(response);
            }

            var hotNews = dtos.Select(x => new HotNews
            {
                Id       = Extension.GenerateGuid(),
                Title    = x.Title,
                Url      = x.Url,
                SourceId = x.SourceId,
                Date     = DateTime.Now
            });

            _context.HotNews.RemoveRange(_context.HotNews.Where(x => dtos.Select(z => z.SourceId).Contains(x.SourceId)));
            await _context.SaveChangesAsync();

            await _context.HotNews.AddRangeAsync(hotNews);

            await _context.SaveChangesAsync();

            response.Result = "新增成功";
            return(response);
        }
Beispiel #2
0
        public async Task <Response <string> > InsertAlbumAsync([FromBody] AlbumDto dto)
        {
            var response = new Response <string>();

            var album = new Album
            {
                Id       = Extension.GenerateGuid(),
                Name     = dto.Name,
                ImgUrl   = dto.ImgUrl,
                Date     = DateTime.Now,
                IsPublic = dto.IsPublic,
                Password = dto.Password
            };
            await _context.Albums.AddAsync(album);

            await _context.SaveChangesAsync();

            response.Result = "新增成功";
            return(response);
        }
Beispiel #3
0
        public async Task <Response <string> > InsertImagesAsync([FromBody] ImageV2Dto dto)
        {
            var response = new Response <string>();

            var images = dto.ImgUrls.Select(x => new Image
            {
                Id      = Extension.GenerateGuid(),
                AlbumId = dto.AlbumId,
                ImgUrl  = x,
                Width   = SixLabors.ImageSharp.Image.Load(Path.Combine(AppSettings.Gallery.ImagesPath, x)).Width,
                Height  = SixLabors.ImageSharp.Image.Load(Path.Combine(AppSettings.Gallery.ImagesPath, x)).Height,
                Date    = DateTime.Now
            }).ToList();

            await _context.Images.AddRangeAsync(images);

            await _context.SaveChangesAsync();

            response.Result = "新增成功";
            return(response);
        }
Beispiel #4
0
        public async Task <Response <string> > InsertImageV2Async([FromBody] ImageDto dto)
        {
            var response = new Response <string>();

            var images = dto.Imgs.Select(x => new Image
            {
                Id      = Extension.GenerateGuid(),
                AlbumId = dto.AlbumId,
                ImgUrl  = x.Url,
                Width   = x.Width,
                Height  = x.Height,
                Date    = DateTime.Now
            });

            await _context.Images.AddRangeAsync(images);

            await _context.SaveChangesAsync();

            response.Result = "新增成功";
            return(response);
        }