Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
OnlyFart committed Oct 6, 2024
1 parent ee23494 commit ad14f44
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Core/Logic/Getters/BooksYandexGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ private async Task<TempFile> GetEpubFile(BookmateBookResponse bookResponse) {

var requestUri = $"https://api.bookmate.ru/api/v5/books/{id}/content/v4".AsUri();
var epubResponse = await Config.Client.GetAsync(requestUri);
return await TempFile.Create(requestUri, Config.TempFolder.Path, epubResponse.Content.Headers.ContentDisposition.FileName.Trim('\"'), await epubResponse.Content.ReadAsStreamAsync());
return epubResponse.StatusCode == HttpStatusCode.OK
? await TempFile.Create(requestUri, Config.TempFolder.Path, epubResponse.Content.Headers.ContentDisposition.FileName.Trim('\"'), await epubResponse.Content.ReadAsStreamAsync())
: default;
}

private async Task<List<TempFile>> GetAudio(BookmateBookResponse bookResponse) {
Expand Down Expand Up @@ -161,7 +163,10 @@ private async Task<BookmateBookResponse> GetBookResponse(string path, string id)
try {
var response = await Config.Client.GetFromJsonAsync<BookmateBookResponse>($"https://api.bookmate.ru/api/v5/{path}/{id}".AsUri());
if (response.AudioBook?.LinkedBooks?.Length > 0) {
return await Config.Client.GetFromJsonAsync<BookmateBookResponse>($"https://api.bookmate.ru/api/v5/books/{response.AudioBook.LinkedBooks[0]}".AsUri());
var linkedResponse = await Config.Client.GetAsync($"https://api.bookmate.ru/api/v5/books/{response.AudioBook.LinkedBooks[0]}".AsUri());
if (linkedResponse.StatusCode == HttpStatusCode.OK) {
return await linkedResponse.Content.ReadFromJsonAsync<BookmateBookResponse>();
}
}

return response;
Expand Down

0 comments on commit ad14f44

Please sign in to comment.