private string GetTempPath(string bookId) { var path = _storageDirectory.GetTempPath(bookId); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } return(path); }
/// <summary> /// 通过GUID获取存储图片文件实例缩略图。 /// </summary> /// <param name="id">媒体文件Id。</param> /// <param name="width">宽度。</param> /// <param name="height">高度。</param> /// <returns>返回存储缩略图实例。</returns> public async Task <StoredPhysicalFile> FindThumbAsync(Guid id, int width, int height) { var file = await _sfdb.AsQueryable().InnerJoin <MediaFile>((sf, mf) => sf.FileId == mf.FileId) .Where <MediaFile>(x => x.Id == id) .Select <MediaFile>(x => x.Name) .Select(x => new { x.FileId, x.ContentType }) .FirstOrDefaultAsync(reader => new StoredPhysicalFile(reader)); if (file == null) { return(null); } var thumbFile = new FileInfo(Path.Combine(_thumbs, file.PhysicalPath).Replace(".moz", $".{width}x{height}.moz")); if (!thumbFile.Exists) { var storedFile = new FileInfo(Path.Combine(_media, file.PhysicalPath)); if (storedFile.Exists) { storedFile = storedFile.Resize(width, height, _directory.GetTempPath()); if (!Directory.Exists(thumbFile.DirectoryName)) { Directory.CreateDirectory(thumbFile.DirectoryName); } storedFile.MoveTo(thumbFile.FullName); } } file.PhysicalPath = thumbFile.FullName; return(file); }
public IActionResult OnPostSave() { var epub = _epubManager.Create(Input.BookId); epub.AddToc(); epub.AddDefaultStyle(); var path = _storageDirectory.GetTempPath($"{Input.BookId}.epub"); epub.Compile(path); return(PhysicalFile(path, ".epub".GetContentType(), $"{Input.DC.Title}.epub")); }