The effective fetch implementation run by the rest of the code.
There is no default fetch implementation for node.js
, hence the necessity to import 'node-fetch'. However, if the code
runs in a browser, there is an error message whereby only the fetch implementation in the Window is acceptable.
This variable is a simple, polyfill like switch between the two, relying on the existence (or not) of the
process
variable (built-in for node.js
).
I guess this makes this entry a bit polyfill like:-)
Basic sanity check on a URL supposed to be used to retrieve a Web Resource.
The function returns a (possibly slightly modified) version of the URL if everything is fine, or a null value if the input argument is not a URL (but should be used as a filename).
There might be errors, however, in the case it is a URL.
The checks are as follows:
localhost
(or equivalents, see invalid_host_names); this is not allowed, unless the code runs in a client or the environment variable R2EPUB_LOCAL
is set.null
if this is, in fact, not a URLFetch an HTML file via fetch_resource and parse the result into a DOM instance.
Fetch an JSON file via fetch_resource and parse the result into an object.
Fetch a resource.
"Fetch" means fetching the resource on the Web. There is one exception, though: some W3C files (e.g., SVG logos) have been modified for EPUB use.
These files are also available on the Web (see modified_epub_files
) but
if the local environment variable R2EPUB_MODIFIED_EPUB_FILES
is set,
then the value is considered to be the name of a local directory, and the files are picked up from that directory via direct, local file system access.
This may speed up and, mainly, avoid some fetch errors that unfortunately occur.
(I am not sure why those errors occur, mainly when collections are created. I suspect this may be related to an almost simultaneous access to the same files more or less in parallel via an async call to a Promise array, and the servers may not be properly set up for that.)
whether the resource should be returned as text in case no content type is set by the server
Fetch the media type of the resource.
Fetch
Wrappers around the fetch function.