Exemplo n.º 1
0
 public static BookContentView Map(this BookContentModel source)
 => new BookContentView
 {
     Id       = source.Id,
     BookId   = source.BookId,
     Language = source.Language,
     MimeType = source.MimeType
 };
Exemplo n.º 2
0
        public ActionResult UmbEpubReader_Read(ContentModel model, string booknameid = "", string readparameters = "")
        {
            BookContentModel result = new BookContentModel(model.Content);

            var epubFileContent = model.Content.GetProperty("epubFile").GetValue();

            if (epubFileContent != null)
            {
                var epubFileContentMedia = Umbraco.Media(((IPublishedContent)epubFileContent).Id);
                var epubUrl  = epubFileContentMedia.Url();
                var epubPath = Server.MapPath(epubUrl);

                var startAtChapter = Convert.ToInt32(model.Content.GetProperty("startAtChapter").GetValue() ?? 0); // if no chapter is requested then start at this chapter index. 0  = the first chapter

                EpubServer epub = new EpubServer(epubPath, readparameters, startAtChapter);

                if (epub.ProcessEpub())
                {
                    // try and get a cover image url from the Umbraco book page content
                    var cover = model.Content.GetProperty("bookCoverImage").GetValue();

                    if (cover != null)
                    {
                        var coverMedia = Umbraco.Media(((IPublishedContent)cover).Id);
                        var coverUrl   = coverMedia.Url();
                        if (!string.IsNullOrEmpty(coverUrl)) // cover image found in umbraco content for this book
                        {
                            epub.ePubDisplayModel.CoverImageUrl = coverUrl;
                        }
                    }
                    result.epub = epub.ePubDisplayModel;
                }
                else // either a redirect or a embeded file to be served
                {
                    if (!string.IsNullOrEmpty(epub.ePubDisplayModel.RedirectToChapter)) // we need to redirect to this chapter probably because no chapter was requested
                    {
                        // build route url to redirect chapter i.e. /books/book_name/read/chapter_name
                        string redirectUrl = string.Format("/{0}/{1}/{2}/{3}", appSettingsConfig.BooksPathSegment, booknameid, appSettingsConfig.ReadPathSegment, epub.ePubDisplayModel.RedirectToChapter);

                        return(Redirect(redirectUrl));
                    }
                    else if (epub.FileToServe != null) // this request is for a file embeded in the e-book
                    {
                        if (epub.FileToServe.IsValid())
                        {
                            Response.AppendHeader("Last-Modified", epub.FileToServe.LastModified);                     // allows the file to be cached in the users client (browser)
                            return(File(epub.FileToServe.Data, epub.FileToServe.MimeType, epub.FileToServe.Filename)); // serve the file and halt all
                        }
                        return(null);
                    }
                }
            }

            return(CurrentTemplate(result));
        }
Exemplo n.º 3
0
        public BookContentView Render(BookContentModel source, int libraryId)
        {
            var result = source.Map();

            var links = new List <LinkView>
            {
                _linkRenderer.Render(new Link {
                    ActionName = nameof(BookController.GetBookContent),
                    Method     = HttpMethod.Get,
                    Rel        = RelTypes.Self,
                    Language   = source.Language,
                    MimeType   = source.MimeType,
                    Parameters = new { libraryId = libraryId, bookId = source.BookId }
                }),
                _linkRenderer.Render(new Link {
                    ActionName = nameof(BookController.GetBookById),
                    Method     = HttpMethod.Get,
                    Rel        = RelTypes.Book,
                    Parameters = new { libraryId = libraryId, bookId = source.BookId }
                })
            };

            if (!string.IsNullOrWhiteSpace(source.ContentUrl) && _fileStorage.SupportsPublicLink)

            {
                links.Add(new LinkView
                {
                    Href           = _fileStorage.GetPublicUrl(source.ContentUrl),
                    Method         = "GET",
                    Rel            = RelTypes.Download,
                    Accept         = source.MimeType,
                    AcceptLanguage = source.Language
                });
            }
            else
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName = nameof(FileController.GetFile),
                    Method     = HttpMethod.Get,
                    Rel        = RelTypes.Download,
                    Language   = source.Language,
                    MimeType   = source.MimeType,
                    Parameters = new { fileId = source.FileId }
                }));
            }

            if (_userHelper.IsWriter(libraryId) || _userHelper.IsAdmin || _userHelper.IsLibraryAdmin(libraryId))
            {
                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName = nameof(BookController.UpdateBookContent),
                    Method     = HttpMethod.Put,
                    Rel        = RelTypes.Update,
                    Language   = source.Language,
                    MimeType   = source.MimeType,
                    Parameters = new { libraryId = libraryId, bookId = source.BookId }
                }));

                links.Add(_linkRenderer.Render(new Link
                {
                    ActionName = nameof(BookController.DeleteBookContent),
                    Method     = HttpMethod.Delete,
                    Rel        = RelTypes.Delete,
                    Language   = source.Language,
                    MimeType   = source.MimeType,
                    Parameters = new { libraryId = libraryId, bookId = source.BookId }
                }));
            }

            result.Links = links;
            return(result);
        }