imtbl / hyve

Expose and consume your hydrus media via HTTP API
GNU Affero General Public License v3.0
31 stars 3 forks source link
api booru bulma hydrus hydrusnetwork vue vuejs

hyve logo
hyve Build status Docker Hub build JavaScript Standard Style

Expose and consume your hydrus media via HTTP API

Unmaintained: hyve is no longer maintained. Due to the limitations and annoyances of hydrus server, I would recommend "abusing" a hydrus client instance as a server instead (this can also be done on headless machines, e.g., containerized via suika/hydrus), which allows you to use the hydrus client API. And instead of running hyve you can then access your media over the web via clients like Hydrus Web or Hydroid. hyve still does some things that you (as of January 2021) can not yet do via client API, so if you do decide to continue using it regardless of it being unmaintained, I recommend you fork it and keep the dependencies up-to-date (to protect against potential vulnerabilities).

hyve is an application that allows you to serve hydrus media over an HTTP API. It can connect to either hydrus client or server. A web-based, booru-like client that consumes the API is also included.

As a rough overview, hyve currently has the following features:

hyve does not allow you to modify or manage your hydrus media in any way, it simply provides a different way to view them.

Table of contents

Install

The recommended way to run is via Docker. Basic instructions on how to run without it are also provided.

Installing with Docker

To install hyve for running with Docker, you can simply pull the prebuilt image from Docker Hub:

user@local:~$ docker pull mtbl/hyve

Alternatively, you can also build the image yourself. The user that is used inside the container has UID 1000 and GID 1000 by default. You can adjust this (e.g., to match your host UID/GID) by providing the arguments USER_ID and GROUP_ID when making a build.

Installing without Docker

To install without Docker, you can simply clone the repository and install dependencies:

user@local:~$ git clone https://github.com/imtbl/hyve.git
user@local:~$ cd hyve
user@local:hyve$ yarn && yarn bootstrap

Dependencies

hyve should work with both the latest LTS and the latest stable version of Node.js. If you encounter any issues with either of those versions when running without Docker, please let me know.

Updating

hyve follows semantic versioning and any breaking changes that require additional attention will be released under a new major version (e.g., 2.0.0). Minor version updates (e.g., 1.1.0 or 1.2.0) are therefore always safe to simply install.

When necessary, this section will be expanded with upgrade guides for new major versions.

Updating with Docker

Simply pull the latest Docker image to update:

user@local:~$ docker pull mtbl/hyve

Updating without Docker

If you have installed via cloning the repository, you can update via Git:

user@local:hyve$ git pull
user@local:hyve$ yarn && yarn bootstrap
user@local:hyve$ cd services/server
user@local:hyve/services/server$ yarn migrate

Upgrading from 2.x.x to 3.x.x

3.0.0 has introduced no breaking API changes and merely reflects the switch to a new license (AGPLv3).

Upgrading from 1.x.x to 2.x.x

2.0.0 has introduced the ability to (optionally) connect to hydrus client instead of hydrus server.

Aside from renaming services/sync to services/sync-server (which you might need to adjust in any start scripts you might have set up when running without Docker), a few environment variables have been added, so you can simply compare with your current configuration and make additions/adjustments where necessary.

Usage

hyve consists of three different services:

In general, you will probably want to run all three services, unless you plan to use a different client to connect to the HTTP API.

Depending on on your choice on you want what to connect to, you will also need to run either hydrus client or server. If you are considering using hyve, you are probably already familiar with the client. In that case, you can just continue using it as you normally would. If you want to set up a server (to connect hyve to that instead), you can find a guide for doing so here.

If you plan to expose the HTTP API outside your local network, it is heavily recommended to use HTTPS. To do this, you will likely want to set up a reverse proxy (I recommend nginx).

hyve uses a lock file called .sync-lock to prevent additional syncs from running while one is already in progress. This file is located in the same directory as hyve's content database. In some instances (e.g., shutdown during a sync), this file might not be removed (causing it to become stale). In that case, you may have to delete it manually before attempting to run the next sync. When running with Docker, the lock file (should it exist at that point) will automatically get removed during sync container startup for your convenience (keep this in mind if you are sharing the same hyve content database between multiple instances).

Running with Docker

To make running with Docker as easy as possible, a working Docker Compose example setup is provided. This setup also includes a dockerized hydrus server and stores the data inside a named volume (which you might want to adjust if you are a more experienced Docker user).

Running hyve with hydrus server might be preferable if you want to manage your media with a local hydrus client and are fine with pushing any files you want to use with hyve to hydrus server.

To get started with the example setup, simply duplicate docker-compose.yml.server.example as docker-compose.yml, adjust the variables in the environment section as described here.

In addition to the environment variables configuring the settings for the respective service, also take note of the time zone set via TZ (for each service). This is particularly important for the sync cron job to run at the time you expect it to. The time zone has to be set in the tz database format.

Finally, start the containers:

user@local:hyve$ docker-compose up -d

Afterwards, proceed with the hydrus server setup, upload your files and tags to it and wait for the first sync to run. The HTTP API and the web client will be available under the configured URLs.

If you want to connect to hydrus client instead, you can have a look at this for a dockerized version of hydrus client that you should be able to run in combination with hyve. I have included a Docker Compose example setup only containing the hyve services (docker-compose.yml.client.example) that you will need to expand accordingly to make it work.

Of course, running hydrus client outside of Docker and using a bind mount to make the databases and media accessible to a dockerized instance of hyve does also work.

Running without Docker

To run without Docker, you will first need to duplicate the .env.example in each service directory (services/sync-client or services/sync-server, services/server and services/web) as .env and adjust the variables as described here.

You will also need to create the content and authentication database files at your desired location:

user@local:hyve$ cd <desired database files location>
user@local:<desired database files location>$ touch content.db && touch authentication.db

Next, run migrations for the authentication database:

user@local:hyve$ cd services/server
user@local:hyve/services/server$ yarn migrate

After that, you can run a sync once you have files in your hydrus client:

user@local:hyve$ cd services/sync-client
user@local:hyve/services/sync-client$ yarn sync

Or, if you have set up hydrus server and pushed files to it:

user@local:hyve$ cd services/sync-server
user@local:hyve/services/sync-server$ yarn sync

Then, start the hyve server:

user@local:hyve$ cd services/server
user@local:hyve/services/server$ yarn start

And finally, build and start the web client:

user@local:hyve$ cd services/web
user@local:hyve/services/web$ yarn build && yarn start

Alternatively, you can also deploy the services/web/dist directory to any static web server after building to serve the client from there.

The HTTP API and the web client will be available under the configured URLs. You might also want to set up a cron job to run the sync periodically.

Configuration

Configuration is done entirely via environment variables. Each of the three services needs to be configured separately. Please keep in mind that some options might not work together or might have to match across services for them to work correctly.

Client sync configuration

Server sync configuration

Server configuration

Web configuration

HTTP API

You can find the HTTP API documentation here.

Screenshots

Here are some screenshots of the web client:

Frontpage

Searching files with tags

Files sorting options

File detail page

Searching tags

Configuring settings

Changing user data

Using the dark theme

FAQ

I am encountering a unique constraint error when syncing. Why does this happen?

This issue can occur when hydrus client or server is running maintenance tasks while hyve runs a sync. In that case, it can usually easily be fixed by waiting a few minutes and trying again. If the error persists, it might indicate issues with your hydrus databases. If you can rule out that this is the case, please open an issue.

Does hyve make changes to my hydrus client/server databases?

No, hyve never makes any changes to the hydrus client/server databases, it only reads from them.

Why does hyve create a copy of the hydrus client/server databases instead of simply connecting to it or using the client API?

Some features like searching by multiple namespaces or constraints would simply not be possible (with decent performance) without using a copy of the databases that is optimized for hyve's purposes.

The database structure of hydrus is not built in a way that allows to deliver paginated results that are also sorted by various criteria, which makes it not suitable for an HTTP API that is meant to be accessed outside of a LAN. hydrus itself does most of the sorting in code after fetching the results, which is really not an option when using pagination.

The client API has not been considered since it is still very limited and does only feature a fraction of what hyve's API can do. As of January 2021, the client API has seen good progress and is certainly a viable option for many use cases. But it is not available for hydrus server, which disqualifies it regardless.

Does hyve also make a copy of my media?

No, only a copy of the hydrus databases is made. hyve directly accesses the hydrus media files.

Why can I not upload files to hyve and sync them back to hydrus client/server?

hyve is only intended as a way to access your media files outside the constraints of hydrus client/server. It is not meant to be yet another booru-like software that allows you to upload and manage media. If you are interested in something like that, I recommend you to check out popular booru softwares like danbooru or szurubooru instead.

hydrus client/server supports x. Will you add this feature to hyve as well?

Maybe. If you want to see a specific feature that you think would be a good fit for hyve, please open an issue. In general, I prefer to add features that are not specific to either hydrus client or hydrus server.

Maintainer

imtbl

Contribute

You are welcome to help out!

Open an issue or submit a pull request.

License

AGPLv3 © imtbl