From ca22aedaaac0787d02ae7e8db35c9e7d80f8ff80 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sat, 17 Oct 2020 22:54:00 +0200 Subject: [PATCH] Added rudimentary API documentation to README. --- README.md | 16 ++++++++++++++++ src/entities.js | 7 ++++--- src/web/tags.js | 1 - 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 537047ec2..40670e178 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,22 @@ To generate thumbnails for new logos and tag photos, install ImageMagick and run * `--no-save`: Do not store retrieved information in local database, forcing re-fetch. * `--level`: Change log level to `silly`, `verbose`, `info`, `warn` or `error`. +### API +A GraphQL API is available at `/graphql`, and a REST API is available at the following endpoints: + +* `/api/scenes`: Fetch the latest releases. Supports search with `query` or `q` parameter; +* `/api/scenes/{ID}`: Fetch scene by ID. +* `/api/actors`: Fetch actors. Search `query` or `q` parameter required. +* `/api/actors/{ID|slug}`: Fetch detailed actor by ID or slug. +* `/api/entities`: Fetch networks and channels. Use the `type` parameter to filter for either `channel`s or `network`s. +* `/api/entities/{ID|slug}`: Fetch detailed network or channel by ID. To fetch by slug, the `type` parameter must specify either `channel` or `network`. +* `/api/channels`: Fetch channel entities. Supports the `q` or `query` parameter for searching. +* `/api/channels/{ID|slug}`: Fetch detailed channel by ID or slug. +* `/api/networks`: Fetch networks. Supports a `q` or `query` parameter for searching. +* `/api/networks/{ID|slug}`: Fetch detailed network by ID or slug. +* `/api/tags`: Fetch tags. +* `/api/tags/{ID|slug|name}`: Fetch detailed tag by ID, slug or name. + ## Supported networks & sites 896 channels on 64 networks, continuously expanding! diff --git a/src/entities.js b/src/entities.js index 9c63988b5..1b8ec94d9 100644 --- a/src/entities.js +++ b/src/entities.js @@ -166,7 +166,7 @@ async function fetchEntities(type, limit) { } async function searchEntities(query, type, limit) { - const entities = await knex + const entities = knex .select(knex.raw(` entities.*, COALESCE(json_agg(tags) FILTER (WHERE tags.id IS NOT NULL), '[]') as tags, @@ -184,9 +184,10 @@ async function searchEntities(query, type, limit) { .groupBy('entities.id', 'parents.id') .limit(limit || 100); - return curateEntities(entities); -} + console.log(entities.toString()); + return curateEntities(await entities); +} module.exports = { curateEntity, diff --git a/src/web/tags.js b/src/web/tags.js index 3842d46d6..0e3c797aa 100644 --- a/src/web/tags.js +++ b/src/web/tags.js @@ -19,7 +19,6 @@ async function fetchTagsApi(req, res) { res.send({ tags }); } - module.exports = { fetchTag: fetchTagApi, fetchTags: fetchTagsApi,