npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

calibre-serve

v0.6.2

Published

A calibre API and server

Downloads

21

Readme

Calibre-Serve

A Calibre API manager and server.

Opens the Calibre library as read-only; this is a module for reading the library only, the purpose being to serve a or several libraries from a directory that is synced with a local copy of Calibre.

Has an integrated epub reader thanks to epub.js

Stand-Alone Usage:

If you want to use it as a stand-alone server:

npm install -g calibre-serve

Then:

calibre-serve /path/to/calibre/database

the path should be one directory above your actual database directory. That is, if metadata.db is situated at /path/to/calibre/database/metadata.db, then you should use /path/to/calibre. Calibre-server will take care of reading sub-directories and adding all the ones that have a metadata.db. If no directory is provided, calibre-serve will default to the current directory.

You can use calibre-serve -h for help about using options such as port or setting the server's title.

There is very basic protection for books by using the --tokens option, which will require the user to provide a token in the url to download.

this is how the default templates look:

Live: books.xananax.com

preview

The default templates are very simple HTML and CSS with no fancyness and should work in any browser, including mobiles of all sorts.

Only the ebook reader uses javascript, and does not work with IE.


Node API

To use it in another module:

npm install --save calibre-serve

Then:

const calibreAPI = require('calibre-serve');
const path = 'path/to/calibre'
const databases = ['database'];

calibreAPI(path,databases,function(err,LIB){
	if(err){throw err;}
	const defaultLogger = makeManager.defaultLogger; // or anything that has `log` and `error`
	LIB.debug(true); //to get debug output
	LIB.logger(defaultLogger) // to set the logger. DefaultLogger is console.
	//then:
	LIB.getBook('database',8).then(rows=>console.log(rows))
	LIB.getSeries('database',1).then(rows=>console.log(rows))
	LIB.getAuthor('database',9).then(rows=>console.log(rows))
	LIB.getTag('database',33).then(rows=>console.log(rows))
})

Methods:

calibreAPI

calibreAPI(path:string,databases:string[],nodeBack:(err?:Error,LIB:Manager))=>void

returns a manager. A manager has four main methods: getBook, getSeries, getAuthor, and getTag. All methods work the same:

method(databaseName[,locator]) => Promise

  • databaseName is one of the databases passed as a second argument.
  • locator is either a numeric id (exact match), a string (will try to match with LIKE %locator%), or nothing (all results will be returned)

calibreAPI.makeServer

calibreAPI.makeServer(path:string,databases:string[],nodeBack(err?:Error,LIB:manager))=>void

Returns a manager, augmented with an additional method getRequestHandler which returns a request handler.

const server = calibreAPI.makeServer(/*...*/);
const requestHandler = server.getRequestHandler(options:{});
// requestHandler is a regular connect handler with signature
// (res,req,next)

Possible options are:

  • options.mountPoint: required,string. The root point for all URLS in templates.
  • options.static: required, string. The static path to prepend to image requests.
  • options.databases: required, array. An array of database in the form of {name,path,description}. The only important value is path, and it should match one of the paths in your directories array.
  • options.onErrorNext:boolean. If true, the server will yield errors to next() instead of handling errors itself.
  • options.asJson: boolean. If true, no templates will be used and database output will be sent as is.
  • options.title: string. The server title.
  • options.templates: An object of templates ({list,book,author,tag,series,error}). Each template has the signature: (rows,locator,command,dbName,options) where:
    • rows is the returned output
    • locator is the locator argument
    • command is one of book, author, series, or tag
    • dbName is the name of the currently used database
    • options is the options object

If you use that, you should set a static server to allow the Calibre server to request images. This would go something like:


const calibreAPI = require('calibre-serve');
const makeServer = calibreAPI.makeServer;

const root = '/path/to/calibre';
const directories = ['database'];
const databases = [{name:'My Database',path:'database',description:'a very nice database'}]
const staticPath = '/covers';
const mountPoint = '/calibre/'
const options = {
	, static:staticPath
	, databases:databases
	, mountPoint:mountPoint
	, title:'My Server'
}
makeServer(root,directories,function(err,LIB){
	if(err){throw err;}
	const requestHandler = LIB.getRequestHandler(options);
	app.use(staticPath,express.static(root))
	app.use(mountPoint,requestHandler);
	app.listen(3000,function(){
		console.log(`listening!`);
	})
})

calibreAPI.connect

calibreAPI.connect(options)

A nicer API for the above makeServer;

const calibreAPI = require('calibre-serve');
const connect = calibreAPI.connect;

connect(
	{ root
	, databases
	, static
	, mountPoint
	, title
	}
,	function(err,requestHandler){
		if(err){throw err;}

		app.use(static,express.static(root))
		app.use(requestHandler);
		app.listen(3000,function(){
			console.log(`${title} listening on ${port}`);
		})
	}
)

Tests

None yet. Coming up.

Contributions

Oh please yes. Just do the classic fork commit pr dance.

FAQ

Is it stable?

No. It's very fresh and might change

Is it reliable?

No. It doesn't have any test

Is it fast?

No. The SQL requests are absolutely not optimized. This is intended for private usage, like sharing books with family and friends

LICENSE

The MIT License (MIT) Copyright (c) 2016 Jad Sarout

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.