diff --git a/src/Application/Interfaces/Services/IBookService.cs b/src/Application/Interfaces/Services/IBookService.cs index 8bd4ad3..0dce6d4 100644 --- a/src/Application/Interfaces/Services/IBookService.cs +++ b/src/Application/Interfaces/Services/IBookService.cs @@ -16,4 +16,5 @@ public interface IBookService Task GetBookCover(string email, Guid guid); Task DeleteBookCover(string email, Guid guid); Task GetFormatForBook(string email, Guid guid); + Task GetExtensionForBook(string email, Guid guid); } \ No newline at end of file diff --git a/src/Application/Services/BookService.cs b/src/Application/Services/BookService.cs index ac0f806..719a424 100644 --- a/src/Application/Services/BookService.cs +++ b/src/Application/Services/BookService.cs @@ -255,6 +255,19 @@ public async Task GetFormatForBook(string email, Guid guid) return book.Format; } + public async Task GetExtensionForBook(string email, Guid guid) + { + var user = await _userRepository.GetAsync(email, trackChanges: true); + var book = user.Books.SingleOrDefault(book => book.BookId == guid); + if (book == null) + { + const string message = "No book with this id exists"; + throw new CommonErrorException(404, message, 4); + } + + return book.Extension; + } + public async Task ChangeBookCover(string email, Guid guid, MultipartReader reader) { var user = await _userRepository.GetAsync(email, trackChanges: true); diff --git a/src/Presentation/Controllers/BookController.cs b/src/Presentation/Controllers/BookController.cs index 1c36806..fccd72a 100644 --- a/src/Presentation/Controllers/BookController.cs +++ b/src/Presentation/Controllers/BookController.cs @@ -71,9 +71,14 @@ public async Task GetBookBinaryData(Guid guid) var email = HttpContext.User.Identity!.Name; var stream = await _bookService.GetBookBinaryData(email, guid); - + // This is added for legacy purposes. Previously the client depended on getting the format, but newer + // clients use the extension. We keep it to keep the old clients working. Response.Headers.Add("Format", await _bookService.GetFormatForBook(email, guid)); + + Response.Headers.Add("Extension", + await _bookService.GetExtensionForBook(email, guid)); + return File(stream, "application/octet-stream"); } catch (CommonErrorException e)