private async Task <int> scanComic(DirectoryInfo directory, int galleryId) { int addCount = 0; foreach (var subDir in directory.GetDirectories()) { if (subDir.Name.StartsWith(".") || subDir.Name.StartsWith("@")) { continue; } var images = Comic.GetImageFiles(subDir.FullName); int imagesCount = images.Count(); if (imagesCount > 0 && await _comicService.GetComic(subDir.FullName) == null) { Comic comic = new Comic { Title = subDir.Name, CoverImage = images.FirstOrDefault().Name, DirectoryPath = subDir.FullName, PageCount = imagesCount, AddTime = subDir.CreationTime, GalleryId = galleryId }; await SendMessage($"新增漫画 {comic.Title}"); await _comicService.AddComic(comic); addCount++; } addCount += await scanComic(subDir, galleryId); } return(addCount); }
public async Task <IActionResult> OnGetAsync() { if (!ModelState.IsValid) { return(NotFound()); } var comic = await _comicService.GetComic(Id); if (comic == null) { return(NotFound()); } Comic = comic; return(Page()); }
public async Task <IActionResult> Image(int comicId, string imageFilename) { Comic comic = await _comicService.GetComic(comicId); string filePath = comic.GetImageFullPath(imageFilename); FileInfo file = new FileInfo(filePath); if (!file.Exists) { return(NotFound()); } else { var contentTypeProvider = new FileExtensionContentTypeProvider(); string contentType = contentTypeProvider.Mappings[file.Extension]; var stream = System.IO.File.OpenRead(filePath); return(File(stream, contentType)); } }