ajslater / codex

Codex is a web based comic archive browser and reader
GNU General Public License v3.0
210 stars 8 forks source link

Codex

A comic archive browser and reader.

โœจ Features

Examples

๐Ÿ‘€ Demonstration

You may browse a live demo server to get a feel for Codex.

๐Ÿ“œ News

Codex has a NEWS file to summarize changes that affect users.

๐Ÿ“ฆ Installation

Install & Run with Docker

Run the official Docker Image. Instructions for running the docker image are on the Docker Hub README. This is the recommended way to run Codex.

You'll then want to read the Administration section of this document.

Install & Run on HomeAssistant server

If you have a HomeAssistant server, Codex can be installed with the following steps :

Install & Run as a Native Application

You can also run Codex as a natively installed python application with pip.

Binary Dependencies

You'll need to install the appropriate system dependencies for your platform before installing Codex.

Linux Dependencies
Debian Dependencies

...and Ubuntu, Mint, MX, Window Subsystem for Linux, and others.

apt install build-essential libimagequant0 libjpeg-turbo8 libopenjp2-7 libssl libyaml-0-2 libtiff6 libwebp7 python3-dev python3-pip mupdf sqlite3 unrar zlib1g

Versions of packages like libjpeg, libssl, libtiff may differ between flavors and versions of your distribution. If the package versions listed in the example above are not available, try searching for ones that are with apt-cache or aptitude.

apt-cache search libjpeg-turbo
Alpine Dependencies
apk add bsd-compat-headers build-base jpeg-dev libffi-dev libwebp openssl-dev sqlite yaml-dev zlib-dev
Install unrar Runtime Dependency on non-debian Linux

Codex requires unrar to read CBR formatted comic archives. Unrar is often not packaged for Linux, but here are some instructions: How to install unrar in Linux

Unrar as packaged for Alpine Linux v3.14 seems to work on Alpine v3.15+

macOS Dependencies

Using Homebrew:

brew install jpeg libffi libyaml libzip openssl python sqlite unrar webp
Windows Dependencies

Windows users are encouraged to use Docker to run Codex, but it will also run natively on the Windows Subsystem for Linux.

Installation instructions are in the Native Windows Dependencies Installation Document.

Run Codex Natively

Once you have installed codex, the codex binary should be on your path. To start codex, run:

codex

Use Codex

Once installed and running you may navigate to http://localhost:9810/

๐Ÿ‘‘ Administration

Navigate to the Admin Panel

Change the Admin password

The first thing you should do is log in as the admin user and change the admin password.

Add Comic Libraries

The second thing you will want to do is log in as an Administrator and add one or more comic libraries.

Reset the admin password

If you forget all your superuser passwords, you may restore the original default admin account by running codex with the CODEX_RESET_ADMIN environment variable set.

CODEX_RESET_ADMIN=1 codex

or, if using Docker:

docker run -e CODEX_RESET_ADMIN=1 -v host-parent-dir/config:/config ajslater/codex

Private Libraries

In the Admin Panel you may configure private libraries that are only accessible to specific groups.

A library with no groups is accessible to every user including anonymous users.

A library with any groups is accessible only to users who are in those groups.

Use the Groups admin panel to create groups and the Users admin panel to add and remove users to groups.

Include and Exclude Groups

Codex can make groups for libraries that exclude groups of users or exclude everyone and include only certain groups of users.

PDF Metadata

Codex reads PDF metadata from the filename, PDF metadata fields and also many formats of common complex comic metadata if they are embedded in the PDF keywords field.

If you decide to include PDFs in your comic library, I recommend taking time to rename your files so Codex can find some metadata. Codex recognizes several file naming schemes. This one has good results:

{series} v{volume} #{issue} {title} ({year}) {ignored}.pdf

Complex comic metadata, such as ComicInfo.xml, can be also be embedded in the keywords field by using the comicbox command line tool. Codex will read this data because it relies on comicbox internally. Not many people use comicbox or embedded metadata in PDFs in this fashion, so you likely won't find it unless you've added it yourself.

๐Ÿ—๏ธ API with Key Access

Codex has a limited number of API endpoints available with API Key Access. The API Key is available on the admin/stats tab.

๐ŸŽ›๏ธ Configuration

Config Dir

The default config directory is config/ directly under the working directory you run codex from. You may specify an alternate config directory with the environment variable CODEX_CONFIG_DIR.

The config directory contains a file named hypercorn.toml where you can specify ports and bind addresses. If no hypercorn.toml is present Codex copies a default one to that directory on startup.

The default values for the config options are:

bind = ["0.0.0.0:9810"]
quick_bind = ["0.0.0.0:9810"]
root_path = "/codex"

The config directory also holds the main sqlite database, the Whoosh search index, a Django cache and comic book cover thumbnails.

Environment Variables

General

Logging

Throttling

Codex contains some experimental throttling controls. The value supplied to these variables will be interpreted as the maximum number of allowed requests per minute. For example, the following settings would limit each described group to 2 queries per second.

Reverse Proxy

nginx is often used as a TLS terminator and subpath proxy.

Here's an example nginx config with a subpath named '/codex'.

# HTTP
proxy_set_header   Host $http_host;
proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header   X-Forwarded-Host $server_name;
proxy_set_header   X-Forwarded-Port $server_port;
proxy_set_header   X-Forwarded-Proto $scheme;
proxy_set_header   X-Real-IP $remote_addr;
proxy_set_header   X-Scheme $scheme;
# Websockets
proxy_http_version 1.1;
proxy_set_header   Upgrade $http_upgrade;

proxy_set_header Connection "Upgrade" location /codex {
  proxy_pass       http://codex:9810;
  # Codex reads http basic authentication.
  # If the nginx credentials are different than codex credentials use this line to
  #   not forward the authorization.
  proxy_set_header Authorization "";
}

Specify a reverse proxy sub path (if you have one) in config/hypercorn.toml

root_path = "/codex"

Nginx Reverse Proxy 502 when container refreshes

Nginx requires a special trick to refresh dns when linked Docker containers recreate. See this nginx with dynamix upstreams article.

Restricted Memory Environments

Codex can run with as little as 1GB available RAM. Large batch jobs โ€“like importing and indexing tens of thousands of comics at onceโ€“ will run faster the more memory is available to Codex. The biggest gains in speed happen when you increase memory up to about 6GB. Codex batch jobs do get faster the more memory it has above 6GB, but with diminishing returns.

If you must run Codex in an admin restricted memory environment you might want to temporarily give Codex a lot of memory to run a very large import job and then restrict it for normal operation.

๐Ÿ“– Use

๐Ÿ‘ค Sessions & Accounts

Once your administrator has added some comic libraries, you may browse and read comics. Codex will remember your preferences, bookmarks and progress in the browser session. Codex destroys anonymous sessions and bookmarks after 60 days. To preserve these settings across browsers and after sessions expire, you may register an account with a username and password. You will have to contact your administrator to reset your password if you forget it.

แฏค OPDS

Codex supports OPDS syndication and OPDS streaming. You may find the OPDS url in the side drawer. It should take the form:

http(s)://host.tld(:9810)(/root_path)/opds/v1.2/

or

http(s)://host.tld(:9810)(/root_path)/opds/v2.0/

OPDS 2.0 support is experimental and not widely or well supported by clients. OPDS 2.0 book readers exist, but I am not yet aware of an OPDS 2.0 comic reader.

Clients

Kybook 3 does not seem to support http basic authentication, so Cbbodex users are not supported.

HTTP Basic Authentication

If you wish to access OPDS as your Codex User. You will have to add your username and password to the URL. Some OPDS clients do not asssist you with authentication. In that case the OPDS url will look like:

http(s)://username:password@host.tld(:9810)(/root_path)/opds/v1.2/

Supported OPDS Specifications

OPDS v1
OPDS v2

๐Ÿฉบ Troubleshooting

๐Ÿ“’ Logs

Codex collects its logs in the config/logs directory. Take a look to see what th e server is doing.

You can change how much codex logs by setting the LOGLEVEL environment variable. By default this level is INFO. To see more verbose messages, run codex like:

LOGLEVEL=DEBUG codex

Watching Filesystem Events with Docker

Codex tries to watch for filesystem events to instantly update your comic libraries when they change on disk. But these native filesystem events are not translated between macOS & Windows Docker hosts and the Docker Linux container. If you find that your installation is not updating to filesystem changes instantly, you might try enabling polling for the affected libraries and decreasing the poll_every value in the Admin console to a frequency that suits you.

Emergency Database Repair

If the database becomes corrupt, Codex includes a facility to rebuild the database. Place a file named rebuild_db in your Codex config directory like so:

touch config/rebuild_db

Shut down and restart Codex.

The next time Codex starts it will back up the existing database and try to rebuild it. The database lives in the config directory as the file config/db.sqlite3. If this procedure goes kablooey, you may recover the original database at config/backups/codex.sqlite3.before-rebuild. Codex will remove the rebuild_db file.

Warnings to Ignore

StreamingHttpResponse Iterator Warning

packages/django/http/response.py:517: Warning: StreamingHttpResponse must consume synchronous iterators in order to serve them asynchronously. Use an asynchronous iterator instead.

This is a known warning and does not represent anything bad happening. It's an artifact of the Django framework slowly supporting asynchronous server endpoints and unfortunately isn't practical to remove yet.

๐Ÿ“šAlternatives

๐Ÿค Contributing

๐Ÿ› Bug Reports

Issues and feature requests are best filed on the Github issue tracker.

๐Ÿšซ Out of Scope

๐Ÿ›  Develop

Codex is a Django Python webserver with a VueJS front end.

/codex/codex/ is the main django app which provides the webserver and database.

/codex/frontend/ is where the vuejs frontend lives.

Most of Codex development is now controlled through the Makefile. Type make for a list of commands.

๐Ÿ’ฌ Support

By the generosity of the good people of Mylar, I and other Codex users answer questions on the Mylar Discord. Please use the #codex-support channel to ask for help with Codex.

๐Ÿ”— Links

๐Ÿ™๐Ÿป Special Thanks

๐Ÿ˜Š Enjoy

These simple people have managed to tap into the spiritual forces that mystics and yogis spend literal lifetimes seeking. I feel... ...I feel...