public Feed SearchBySeries(string series, [FromUri] int page = 1) { if (page < 1) { page = 1; } series = Uri.UnescapeDataString(series); var searcher = new LuceneIndexStorage(); int total; var books = searcher.SearchExact(out total, "series_exact", series, page); var feed = new Feed(); feed.Id = $"tag:root:series:{series}"; feed.Title = T._("Books in the series {0}", series); feed.Total = total; AddNavigation($"{Prefix}/series/{Uri.EscapeDataString(series)}", feed, page, total, searcher); foreach (var book in books) { feed.Entries.Add(GetBook(book)); } return(feed); }
public Feed SearchByAuthor(string author, [FromUri] int page = 1) { if (page < 1) { page = 1; } author = Uri.UnescapeDataString(author); var searcher = new LuceneIndexStorage(); int total; var books = searcher.SearchExact(out total, "author_exact", author, page); var feed = new Feed(); feed.Id = $"tag:root:author:{author}"; feed.Title = T._("Books by {0}", author); feed.Total = total; AddNavigation($"{Prefix}/author/{Uri.EscapeDataString(author)}", feed, page, total, searcher); foreach (var book in books) { feed.Entries.Add(GetBook(book)); } return(feed); }
public HttpResponseMessage GetCover(Guid id) { var searcher = new LuceneIndexStorage(); int total; var books = searcher.SearchExact(out total, "guid", id.ToString(), take: 1); if (total != 1) { logger.Debug("File {0} not found", id); throw new KeyNotFoundException("Key Not Found: " + id); } logger.Debug("File {0} found in {1}ms", id, searcher.Time); var book = books[0]; if (book.Cover == null) { logger.Warn("No cover found for file {0}", id); return(Request.CreateResponse(HttpStatusCode.NotFound)); } var result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new ByteArrayContent(book.Cover.Data); result.Content.Headers.ContentType = new MediaTypeHeaderValue(book.Cover.ContentType); return(result); }
public Feed SearchByGenre(string genre, [FromUri] int page = 1) { if (page < 1) { page = 1; } genre = Uri.UnescapeDataString(genre); var searcher = new LuceneIndexStorage(); int total; var books = searcher.SearchExact(out total, "genre", genre, page); var feed = new Feed(); feed.Id = "tag:root:genre:" + genre; feed.Title = T._("Books in the genre of {0}", GenreExtensions.GetDisplayName(genre)); feed.Total = total; AddNavigation($"{Prefix}/genre/{Uri.EscapeDataString(genre)}", feed, page, total, searcher); foreach (var book in books) { feed.Entries.Add(GetBook(book)); } return(feed); }
public HttpResponseMessage GetFile(Guid id, string ext) { var searcher = new LuceneIndexStorage(); int total; var books = searcher.SearchExact(out total, "guid", id.ToString(), take: 1); if (total != 1) { logger.Debug("File {0} not found", id); throw new KeyNotFoundException("Key Not Found: " + id); } logger.Debug("File {0} found in {1}ms", id, searcher.Time); var book = books[0]; var converter = Settings.Instance.Converters .FirstOrDefault(x => x.From.Equals(book.Ext, StringComparison.InvariantCultureIgnoreCase) && x.To.Equals(ext, StringComparison.InvariantCultureIgnoreCase)); if (!ext.Equals(book.Ext, StringComparison.InvariantCultureIgnoreCase) && converter == null) { logger.Warn("No converter found for '{0}'->'{1}'", book.Ext, ext); return(new HttpResponseMessage(HttpStatusCode.NotFound)); } var content = GetFileInFormat(book, converter); var result = new HttpResponseMessage(HttpStatusCode.OK); var mimeType = MimeHelper.GetMimeType(ext); result.Content = new StreamContent(content); result.Content.Headers.ContentType = new MediaTypeHeaderValue(mimeType); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); result.Content.Headers.ContentDisposition.FileName = Util.GetBookSafeName(book, ext); logger.Info("Book {0} served to {1}", id, Request.GetOwinContext().Request.RemoteIpAddress); return(result); }