Merge pull request #15 from filipnyquist/master

Added apiDoc and eslinted some code
This commit is contained in:
Fillerino 2017-09-20 19:50:13 +02:00 committed by GitHub
commit c73c6c8bfe
7 changed files with 254 additions and 66 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
node_modules
.DS_Store
/dist
/doc
npm-debug.log
*.retry
.vscode

13
apidoc.json Normal file
View file

@ -0,0 +1,13 @@
{
"name": "Lighthouse",
"version": "0.0.1",
"description": "Lighthouse - Next-gen search api for LBRY",
"title": "Lighthouse API DOCS",
"url" : "http://localhost/api/lighthouse",
"sampleUrl": "http://localhost/api/lighthouse",
"json_body": true,
"template": {
"withCompare": true,
"withGenerator": true
}
}

View file

@ -28,7 +28,8 @@
"lint": "eslint ./server",
"test": "npm run lint && npm run mocha",
"prod": "npm run build && node dist/",
"mocha": "./node_modules/.bin/mocha --compilers js:babel-register --require babel-polyfill"
"mocha": "./node_modules/.bin/mocha --compilers js:babel-register --require babel-polyfill",
"gendoc": "apidoc -i server/ -o doc/"
},
"dependencies": {
"app-root-path": "^2.0.1",
@ -55,6 +56,7 @@
"winston-stream": "^0.0.0"
},
"devDependencies": {
"apidoc": "^0.17.6",
"babel-cli": "^6.5.1",
"babel-eslint": "^7.1.1",
"babel-plugin-add-module-exports": "^0.2.1",

View file

@ -17,56 +17,56 @@ const eclient = new elasticsearch.Client({
});
function getResults (input) {
if(input.size == undefined) input.size = 10;
if(input.from == undefined) input.from = 0;
if (input.size === undefined) input.size = 10;
if (input.from === undefined) input.from = 0;
return eclient.search({
index: "claims",
index: 'claims',
body : {
"query": {
"bool": {
"must": {
"query_string": {
"query": input.s.trim(),
"fields": [
"name",
"value.stream.metadata.author",
"value.stream.metadata.title",
"value.stream.metadata.description"
]
}
}
}
'query': {
'bool': {
'must': {
'query_string': {
'query' : input.s.trim(),
'fields': [
'name',
'value.stream.metadata.author',
'value.stream.metadata.title',
'value.stream.metadata.description',
],
},
},
},
},
size: input.size,
from: input.from
}
from: input.from,
},
});
}
function getAutoComplete (input) {
if(input.size == undefined) input.size = 10;
if(input.from == undefined) input.from = 0;
if (input.size === undefined) input.size = 10;
if (input.from === undefined) input.from = 0;
return eclient.search({
index: "claims",
_source: ["name", "value.stream.metadata.title", "value.stream.metadata.author"],
index : 'claims',
_source: ['name', 'value.stream.metadata.title', 'value.stream.metadata.author'],
body : {
"query": {
"bool": {
"must": {
"query_string": {
"query": input.s.trim(),
"fields": [
"name",
"value.stream.metadata.title",
"value.stream.metadata.author"
]
}
}
}
'query': {
'bool': {
'must': {
'query_string': {
'query' : input.s.trim(),
'fields': [
'name',
'value.stream.metadata.title',
'value.stream.metadata.author',
],
},
},
},
},
size: input.size,
from: input.from
}
from: input.from,
},
});
}
@ -92,7 +92,6 @@ class LighthouseControllers {
});
}
/**
* Autocomplete API Endpoint.
* @param {ctx} Koa Context
@ -111,7 +110,7 @@ class LighthouseControllers {
var clean = new Array();
for (var i = 0; i < cResults.length; i++) {
if (cResults[i] && cResults[i].length > 3 && clean.indexOf(cResults[i]) == -1) {
if (cResults[i] && cResults[i].length > 3 && clean.indexOf(cResults[i]) === -1) {
clean.push(cResults[i]);
}
}
@ -124,7 +123,7 @@ class LighthouseControllers {
* @param {ctx} Koa Context
*/
async info (ctx) {
ctx.body = "Lighthouse";
ctx.body = 'Lighthouse';
}
/**

View file

@ -14,14 +14,84 @@ router.prefix(`/${baseApi}/${api}`);
// GET /api/lighthouse
router.get('/', LighthouseControllers.info);
// GET /api/search
/**
* @api {post} /search Main Search API
* @apiGroup Search
* @apiParam {String} input The search text (Required)
* @apiParam {Integer} size Amount of results to return as max
* @apiParam {Integer} from The number to start from, good for pagination.
* @apiParamExample {json} Input
* {
* "input": "fillerino", "size": 10, "from": 2
* }
* @apiSuccess {Array[]} array List of search response, each containing the value below.
* @apiSuccess {Object[]} result A search result
* @apiSuccess {String} result.name The name of the claim.
* @apiSuccess {String} result.claimId The claimId of the claim.
* @apiSuccess {Object[]} result.value The decoded value of the metadata
* @apiSuccessExample {json} Success
* HTTP/1.1 200 OK
[
{
"name":"fillerino-js-test",
"claimId":"7bfed722c678a0e0ceb9fb90974bfcc65f528813",
"value":{
"version":"_0_0_1",
"claimType":"streamType",
"stream":{
"source":{
"source":"7ded8c9c7527fce26ced886adcd2eab9fc424c0126eff6572f0615ab66ec3bfbdbbfc1603d95cecd81c9b93fa8ecfbf8",
"version":"_0_0_1",
"contentType":"text/html",
"sourceType":"lbry_sd_hash"
},
"version":"_0_0_1",
"metadata":{
"license":"Public Domain",
"description":"A test file which tries to communicate with the daemon(from inside the app).",
"language":"en",
"title":"Text Javascript Injection",
"author":"",
"version":"_0_1_0",
"nsfw":false,
"licenseUrl":"",
"preview":"",
"thumbnail":""
}
}
}
},
{...},
{...}
]
*/
router.get('/search', LighthouseControllers.search);
// GET /api/search
/**
* @api {post} /autocomplete Autocomplete API
* @apiGroup Search
* @apiParam {String} input The text to be autocompleted (Required).
* @apiParamExample {json} Input
* {
* "input": "fillerino"
* }
* @apiSuccess {Array[]} array List of search response, each containing the value below.
* @apiSuccessExample {json} Success
* HTTP/1.1 200 OK
*
* ["@Fillerino","fillerino-js-test","Text Javascript Injection"]
*/
router.get('/autocomplete', LighthouseControllers.autoComplete);
// GET /api/ligthouse/status
/**
* @api {get} /status Status
* @apiGroup Search
* @apiSuccess {Array[]} array Will contain information about lighthouse.
* @apiSuccessExample {json} Success
* HTTP/1.1 200 OK
*
* {"err": "Not done yet, will be added"}
*/
router.get('/status', LighthouseControllers.status);
export default router;

113
yarn.lock
View file

@ -64,6 +64,10 @@ ansi-styles@^3.1.0:
dependencies:
color-convert "^1.9.0"
ansi-styles@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.0.0.tgz#cb102df1c56f5123eab8b67cd7b98027a0279178"
any-promise@^1.1.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"
@ -75,6 +79,28 @@ anymatch@^1.3.0:
micromatch "^2.1.5"
normalize-path "^2.0.0"
apidoc-core@~0.8.2:
version "0.8.3"
resolved "https://registry.yarnpkg.com/apidoc-core/-/apidoc-core-0.8.3.tgz#d9d63545829df250d2cca049683a87e775364b96"
dependencies:
fs-extra "^3.0.1"
glob "^7.1.1"
iconv-lite "^0.4.17"
klaw-sync "^2.1.0"
lodash "~4.17.4"
semver "~5.3.0"
apidoc@^0.17.6:
version "0.17.6"
resolved "https://registry.yarnpkg.com/apidoc/-/apidoc-0.17.6.tgz#4ee8ac610dedddcb1006c3e28fa7dd634b4a5ce6"
dependencies:
apidoc-core "~0.8.2"
fs-extra "~3.0.1"
lodash "~4.17.4"
markdown-it "^8.3.1"
nomnom "~1.8.1"
winston "~2.3.1"
app-root-path@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-2.0.1.tgz#cd62dcf8e4fd5a417efc664d2e5b10653c651b46"
@ -686,7 +712,7 @@ bitcoin-promise@filipnyquist/node-bitcoin-promise#1fbf1cb8913ca3542b66060d48ebea
version "1.3.2"
resolved "https://codeload.github.com/filipnyquist/node-bitcoin-promise/tar.gz/1fbf1cb8913ca3542b66060d48ebea185661e0a7"
dependencies:
bitcoin filipnyquist/node-bitcoin#17552efad852a0ae929dc153988649259536a23d
bitcoin filipnyquist/node-bitcoin
bitcoin@filipnyquist/node-bitcoin#17552efad852a0ae929dc153988649259536a23d:
version "3.0.2"
@ -804,6 +830,14 @@ chalk@^2.0.1:
escape-string-regexp "^1.0.5"
supports-color "^4.0.0"
chalk@~0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f"
dependencies:
ansi-styles "~1.0.0"
has-color "~0.1.0"
strip-ansi "~0.1.0"
chokidar@^1.4.3, chokidar@^1.6.1:
version "1.7.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
@ -1158,6 +1192,10 @@ end-of-stream@^1.0.0:
dependencies:
once "^1.4.0"
entities@~1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.1.tgz#6e5c2d0a5621b5dadaecef80b90edfb5cd7772f0"
error-ex@^1.2.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc"
@ -1525,6 +1563,14 @@ from@~0:
version "0.1.7"
resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe"
fs-extra@^3.0.1, fs-extra@~3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-3.0.1.tgz#3794f378c58b342ea7dbbb23095109c4b3b62291"
dependencies:
graceful-fs "^4.1.2"
jsonfile "^3.0.0"
universalify "^0.1.0"
fs-readdir-recursive@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.0.0.tgz#8cd1745c8b4f8a29c8caec392476921ba195f560"
@ -1684,6 +1730,10 @@ has-ansi@^2.0.0:
dependencies:
ansi-regex "^2.0.0"
has-color@~0.1.0:
version "0.1.7"
resolved "https://registry.yarnpkg.com/has-color/-/has-color-0.1.7.tgz#67144a5260c34fc3cca677d041daf52fe7b78b2f"
has-flag@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa"
@ -1798,6 +1848,10 @@ iconv-lite@0.4.13:
version "0.4.13"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2"
iconv-lite@^0.4.17:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
ienoopen@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ienoopen/-/ienoopen-1.0.0.tgz#346a428f474aac8f50cf3784ea2d0f16f62bda6b"
@ -2084,7 +2138,7 @@ json5@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
jsonfile@^3.0.1:
jsonfile@^3.0.0, jsonfile@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-3.0.1.tgz#a5ecc6f65f53f662c4415c7675a0331d0992ec66"
optionalDependencies:
@ -2150,6 +2204,12 @@ kind-of@^4.0.0:
dependencies:
is-buffer "^1.1.5"
klaw-sync@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/klaw-sync/-/klaw-sync-2.1.0.tgz#3d3bcd8600e7bfdef53231c739ff053aed560e44"
optionalDependencies:
graceful-fs "^4.1.11"
koa-bodyparser@^3.0.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/koa-bodyparser/-/koa-bodyparser-3.2.0.tgz#b916de17e2039fe82650481973d7c294f10b5719"
@ -2265,6 +2325,12 @@ limited-request-queue@^3.0.4:
parse-domain "~0.2.1"
whatwg-url "^3.0.0"
linkify-it@^2.0.0:
version "2.0.3"
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-2.0.3.tgz#d94a4648f9b1c179d64fa97291268bdb6ce9434f"
dependencies:
uc.micro "^1.0.1"
load-json-file@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-2.0.0.tgz#7947e42149af80d696cbf797bcaabcfe1fe29ca8"
@ -2387,7 +2453,7 @@ lodash@2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-2.4.2.tgz#fadd834b9683073da179b3eae6d9c0d15053f73e"
lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.4, lodash@^4.3.0:
lodash@^4.0.0, lodash@^4.13.1, lodash@^4.17.4, lodash@^4.3.0, lodash@~4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
@ -2411,6 +2477,20 @@ map-stream@~0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.1.0.tgz#e56aa94c4c8055a16404a0674b78f215f7c8e194"
markdown-it@^8.3.1:
version "8.4.0"
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-8.4.0.tgz#e2400881bf171f7018ed1bd9da441dac8af6306d"
dependencies:
argparse "^1.0.7"
entities "~1.1.1"
linkify-it "^2.0.0"
mdurl "^1.0.1"
uc.micro "^1.0.3"
mdurl@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-1.0.1.tgz#fe85b2ec75a59037f2adfec100fd6c601761152e"
media-typer@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
@ -2560,6 +2640,13 @@ nodemon@^1.8.1:
undefsafe "0.0.3"
update-notifier "0.5.0"
nomnom@~1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/nomnom/-/nomnom-1.8.1.tgz#2151f722472ba79e50a76fc125bb8c8f2e4dc2a7"
dependencies:
chalk "~0.4.0"
underscore "~1.6.0"
nopt@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d"
@ -3110,7 +3197,7 @@ semver-diff@^2.0.0:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
semver@5.3.0:
semver@5.3.0, semver@~5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
@ -3307,6 +3394,10 @@ strip-ansi@^4.0.0:
dependencies:
ansi-regex "^3.0.0"
strip-ansi@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.1.1.tgz#39e8a98d044d150660abe4a6808acf70bb7bc991"
strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
@ -3466,6 +3557,10 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
uc.micro@^1.0.1, uc.micro@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.3.tgz#7ed50d5e0f9a9fb0a573379259f2a77458d50192"
uid-number@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"
@ -3474,6 +3569,14 @@ undefsafe@0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-0.0.3.tgz#ecca3a03e56b9af17385baac812ac83b994a962f"
underscore@~1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.6.0.tgz#8b38b10cacdef63337b8b24e4ff86d45aea529a8"
universalify@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"
unpipe@1.0.0, unpipe@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
@ -3562,7 +3665,7 @@ winston-stream@^0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/winston-stream/-/winston-stream-0.0.0.tgz#9cd21c9828f688f184768e3fd53254140dca663c"
winston@^2.3.1:
winston@^2.3.1, winston@~2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/winston/-/winston-2.3.1.tgz#0b48420d978c01804cf0230b648861598225a119"
dependencies: