Example #1
0
        public async Task Scan()
        {
            Scanning = true;
            await SendScanStatus();

            DirectoryInfo  rootDir   = new DirectoryInfo(_options.Value.RootDir);
            List <Gallery> galleries = await _galleryService.GetAllGalleries();

            int maxIndex = 0;

            if (galleries.Count() != 0)
            {
                maxIndex = galleries.Select(g => g.Index).OrderByDescending(i => i).FirstOrDefault() + 1;
            }
            List <Gallery> newGalleries = new List <Gallery>();

            await SendMessage("开始扫描");

            foreach (var galleryDir in rootDir.GetDirectories())
            {
                if (galleryDir.Name.StartsWith(".") || galleryDir.Name.StartsWith("@"))
                {
                    continue;
                }
                if (await _galleryService.GetGallery(galleryDir.FullName) == null)
                {
                    Gallery newGallery = new Gallery
                    {
                        Name       = galleryDir.Name,
                        Index      = maxIndex,
                        DefaultDir = galleryDir.FullName
                    };
                    maxIndex++;
                    await SendMessage($"新增分类:{newGallery.Name}");

                    await _galleryService.AddGallery(newGallery);

                    newGalleries.Add(newGallery);
                }
            }
            galleries.AddRange(newGalleries);
            int newComicCount = 0;

            foreach (var gallery in galleries)
            {
                DirectoryInfo dir = new DirectoryInfo(gallery.DefaultDir);
                newComicCount += await scanComic(dir, gallery.Id);
            }
            await SendMessage($"扫描完毕,共增加{newGalleries.Count}个分类,{newComicCount}个漫画");

            Scanning = false;
            await SendScanStatus();
        }
Example #2
0
        public async Task <IHttpActionResult> Post([FromBody] Gallery gallery)
        {
            var res = GalleryService.AddGallery(gallery, await GetCurrentId());

            return(Ok(res));
        }