This repo has been moved into the NYPL/ereading-clients monorepo under packages/epub-to-webpub.
This repository is a converter between EPUBS and Webpubs. It can either be deployed as an endpoint service, consumed as a package within another Node service, or used as a CLI.
- Exploded EPUB support (packaged EPUBS not currently supported)
- Remote and Local EPUB support
- AxisNow Encrypted EPUB support
- CLI
- Vercel-ready API handlers in
/api
npm i @nypl/epub-to-webpub
❯ epub-to-webpub ./samples/moby-epub2-exploded/META-INF/container.xml ./outputs/test.json
███╗ ██╗██╗ ██╗██████╗ ██╗
████╗ ██║╚██╗ ██╔╝██╔══██╗██║
██╔██╗ ██║ ╚████╔╝ ██████╔╝██║
██║╚██╗██║ ╚██╔╝ ██╔═══╝ ██║
██║ ╚████║ ██║ ██║ ███████╗
╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚══════╝
EPUB to Webpub Converter
✔ Detected type: Local Exploded Epub
✔ Reading EPUB from: ./samples/moby-epub2-exploded/META-INF/container.xml
✔ Converting to Webpub...
✔ Formatting manifest...
✔ Writing Manifest to filesystem at: ./outputs/test.json
✔ Success!
The API endpoints reside in /api
and are deployed via Vercel at https://epub-to-webpub.vercel.app
. The endpoints are:
/api/[containerXmlUrl]
- You provide the url to thecontainer.xml
file of an exploded EPUB, and we will return the webpub manifest./api/axisnow/[isbn]/[book_vault_uuid]
- You provide theisbn
and thebook_vault_uuid
, and we return the webpub manifest.
This repo uses the private github package @nypl-simplified-packages/axisnow-access-control-web
to decrypt the NCX file in exploded AxisNow EPUBS in order to generate the manifest. If you do not have access to the private github package, you will not be able to deploy this with decryption, and attempting to use the decryption API will throw an error.
- Packaged EPUB support.
- Better support for EPUB metadata and other EPUB features.
- Better cover detection to add
width
andheight
to EPUB 2 cover iamges.
There are three main pieces to the architecture:
- The
Epub
class - This class serves as the in-memory respresentation of an Epub. It takes in thecontainer.xml
file and sources all the other files it needs from there. - The
Fetcher
class - TheFetcher
is resonsible for sourcing the contents of a file. It allows theEpub
class to not care how a file is fetched specifically. As such it is an abstract class, and has currently has two concrete implementations:LocalFetcher
andRemoteFetcher
. You could support a packaged EPUB by writing aLocalPackagedFetcher
. - The
/convert
folder - Here we take in anEpub
and return aWebpubManifest
object. This conversion is exposed on the.webpubManifest
property of anEpub
.
npm run start
- start building the package in watch mode.npm run build
- make a production build of the package. This will export CJS and ESmodules module formats to/dist
. The cli application will be exported to/dist/cli
.npm run test
- perform a test run using Jest.npm run test:watch
- perform a test run and re-test on code change.
/api # vercel lambda functions
/mocks # msw mocks for testing network-dependent code
/samples # example EPUBS in various formats
/site # basic index.html file to serve at api root
/src
/__tests__
/cli # cli entrypoint
/convert # generates a Webpub Manifest from an Epub class
/WebpubManifestTypes # ...
Epub.ts # the main Epub class
Fetcher.ts # abstract Fetcher class to be extended by LocalFetcher etc
index.ts # entrypoint of the npm module
LocalFetcher.ts
RemoteFetcher.ts
The API endpoints are located in /api
and deployed to Vercel.
The converter may be deployed as an AWS Lambda function by using the the handler method in the /src/lambda.ts
To invoke the method run npm build
and provide dist/lambda.handler
as the entrypoint in the Lambda configuration.
The API endpoints may also be run as a containerized service. To do so follow these steps:
- Build the container with
docker build -t epub-to-webpub .
- Run the container with
docker run -p 5000:5000 epub-to-webpub
The API will be available at port 5000 on the container (or whichever port you choose to expose on your host)
Tests are written with Jest. There is one particular thing to note here: we use MSW (Magic Service Worker) for testing network-based tasks. It intercepts the Node network requests and allows us to serve custom responses. In this case we serve files from the local filesystem in /samples
, but it also allows us to test other responses a real server might give.