Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Sv443/JokeAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Jul 3, 2020
2 parents cb19570 + 5289a9d commit 1f47b71
Show file tree
Hide file tree
Showing 16 changed files with 279 additions and 203 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div align="center" style="text-align:center">

# [![icon](https://sv443.net/cdn/jokeapi/icon_150x150.png)](#readme)<br>JokeAPI
# [![icon](https://sv443.net/cdn/jokeapi/icon_readme.png)](#readme)<br>JokeAPI
### A REST API that serves uniformly and well formatted jokes and offers a great variety of filtering methods and response customization
[![GitHub](https://img.shields.io/github/license/Sv443/JokeAPI)](https://sv443.net/LICENSE)
[![Uptime / 7 Days](https://img.shields.io/uptimerobot/ratio/7/m782998549-afcc0d10c27c87df47e73289)](https://status.sv443.net/)
Expand Down
31 changes: 21 additions & 10 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
====================

JokeAPI Changelog
- Version 2.1.4 -
- Version 2.1.5 -

====================



[PLANNED: 2.2.0]
- Allow definition of max requests per minute per each client (GitHub issue #37)
- Add support for jokes and error messages of different languages (GitHub issue #75)
- Add joke category "Pun" (issue #105)
- Allow definition of max requests per minute per each client (issue #37)
- Add support for jokes and error messages of different languages (issue #75)
- /langcode/{LANGUAGE} endpoint
- /languages endpoint
- "?lang=code" URL parameter
- Fix ID caching (again, sigh)
- Add pm2 custom metrics
- Fix HTTP 403 errors
- Remake the URL parser using a package
- Daemonize the auth token refreshing
- Fix ID caching (again, sigh) (issue #80)
- Add pm2 custom metrics (issue #91)
- Fix HTTP 403 errors (issue #96)
- Remake the URL parser using a "commercial" package (issue #97)
- Daemonize the API token refreshing (issue #102)
- Rate limit joke submissions more harshly (issue #104)
- Fix resources not being served with Brotli even though it is supported by the client (issue #106)


[CURRENT: 2.1.4] - 2020 Q3 general patch #1
[CURRENT: 2.1.5] - 2020 Q3 general patch #2
- Ditched my botched rate limiting package for a "commercial" one (issue #113)
- Added API token section to documentation (issue #114)
- Client now receives a "Token-Valid" header with the value 0 or 1 depending on token validity (issue #115)
- Renamed "X-Auth-Token" header to "Authorization" so requests don't get blocked by Cloudflare (issue #117)
- Cleaned up a lot of code


[2.1.4] - 2020 Q3 general patch #1
- Fixed the IP getter module for like the 500th time now


[2.1.3] - 2020 Q2 general patch #1
- Added option to disable all console output but error messages (GitHub isse #72)
- Added option to disable all console output but error messages (GitHub issue #72)
- The content of jokes in the joke submission form is now correctly escaped and can no longer mess up the page (GitHub issue #68)
- Fixed crash when parsing a malformatted URI (GitHub issue #69 (nice))
- Re-flagged some jokes
Expand Down
5 changes: 0 additions & 5 deletions data/lists/ipBlacklist.json

This file was deleted.

21 changes: 11 additions & 10 deletions docs/raw/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
--doc-header-font-size: 27px;
--doc-sub-header-font-size: 19px;

--sidenav-animation-speed: 0.3s;
--sidenav-animation-speed: 0.15s;
--sidenav-colorblur-speed: 0.5s;
--targetblink-animation-delay: 0.5s;

--scrollbar-track-color: #222;
Expand Down Expand Up @@ -54,7 +55,7 @@ body {

overflow-y: hidden;

transition: background-color var(--sidenav-animation-speed);
transition: background-color ease-out var(--sidenav-colorblur-speed);

/* I had to do this for some unknown reason - don't ask me why: */
-webkit-touch-callout: inherit;
Expand Down Expand Up @@ -172,7 +173,7 @@ header {
background-color: var(--header-bg-color);
z-index: 1000;

transition: filter linear var(--sidenav-animation-speed), width linear var(--sidenav-animation-speed);
transition: filter ease-out var(--sidenav-colorblur-speed), width linear var(--sidenav-animation-speed);

display: flex;
flex-direction: row;
Expand Down Expand Up @@ -321,7 +322,7 @@ label {
}

#statusCodeTable tr td.dr, span.col.dr {
color: #df0909;
color: #f52727;
}

.colB {
Expand Down Expand Up @@ -351,7 +352,7 @@ mark {
padding: 3px;
font-family: "Cascadia Code", "Roboto", "Courier New", monospace;
color: #ccc;
transition: background-color linear var(--sidenav-animation-speed);
transition: background-color ease-out var(--sidenav-colorblur-speed);
}

body[data-sidenav="opened"] mark {
Expand Down Expand Up @@ -421,7 +422,7 @@ body[data-sidenav="closed"] code, body code {

filter: grayscale(0%);

transition: filter linear var(--sidenav-animation-speed);
transition: filter ease-out var(--sidenav-colorblur-speed);
}

body code > .actualCode {
Expand All @@ -440,7 +441,7 @@ body[data-sidenav="opened"] code {

filter: grayscale(50%);

transition: filter linear var(--sidenav-animation-speed);
transition: filter ease-out var(--sidenav-colorblur-speed);
}

body code .nocode.codeheader {
Expand Down Expand Up @@ -504,12 +505,12 @@ ul.lispacer li {
padding: 3px;
padding-left: 10px;
padding-right: 40px;
transition: background-color linear var(--sidenav-animation-speed);
transition: background-color ease-out var(--sidenav-colorblur-speed);
}

body[data-sidenav="opened"] .requestURLwrapper {
background-color: var(--bg-accent-color-darker-sidenav-opened);
transition: background-color linear var(--sidenav-animation-speed);
transition: background-color ease-out var(--sidenav-colorblur-speed);
}

.requestMethodGET, .requestMethodPUT {
Expand Down Expand Up @@ -950,4 +951,4 @@ input[disabled]+label {
#urlBuilderUrl {
display: inline-block;
padding: 10px 5px 10px 8px;
}
}
49 changes: 38 additions & 11 deletions docs/raw/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
<div class="multiselect noselect">
<input type="radio" id="fmt-cb1" name="formatRadio" value="json" onchange="reRender()"><label for="fmt-cb1">default (json)</label>
<input type="radio" id="fmt-cb2" name="formatRadio" value="xml" onchange="reRender()"><label for="fmt-cb2">xml</label>
<input type="radio" id="fmt-cb3" name="formatRadio" value="yaml" onchange="reRender()"><label for="fmt-cb3">yaml</label> <!-- TODO: -->
<input type="radio" id="fmt-cb4" name="formatRadio" value="txt" onchange="reRender()"><label for="fmt-cb4">plaintext</label>
<input type="radio" id="fmt-cb3" name="formatRadio" value="yaml" onchange="reRender()"><label for="fmt-cb3">yaml</label>
<input type="radio" id="fmt-cb4" name="formatRadio" value="txt" onchange="reRender()"><label for="fmt-cb4">plain text</label>
</div>
</td>
</tr>
Expand Down Expand Up @@ -538,12 +538,12 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to

<!-- #MARKER Errors -->
<div class="docHeader targetBlink" id="errors"><a class="headerAnchorContainer" href="#errors" title="Click to link to this header">🔗</a><span class="docHeaderText">Errors:</span></div>
In <!--%#INSERT:NAME#%--> all response data, no matter from which endpoint will have an "error" parameter.<br>
In <!--%#INSERT:NAME#%--> all response data, no matter from which endpoint will have a boolean "error" parameter.<br>
Usually, it is set to false, which means there was no error in your request or on the server.<br>
If the "error" parameter is set to true though, there was an error and <!--%#INSERT:NAME#%--> will add an "internalError", "message", "causedBy", "additionalInfo" and "timestamp" parameter.<br>
<br>
The "internalError" parameter will be set to false, if the error was due to a malformed or failed request and it will be true, if the error is <!--%#INSERT:NAME#%-->'s fault.<br>
The "message" parameter will contain a short version of the error message and the "timestamp" parameter will contain a 13-character UNIX timestamp in Central European time (GMT+1).<br>
The "message" parameter will contain a short version of the error message and the "timestamp" parameter will contain a 13-character Unix timestamp.<br>
The "causedBy" parameter is an array of possible causes of this error and the "addidionalInfo" parameter contains a more descriptive error message.<br>
<br>
You can view an example of an error, where an invalid category was used, just below this paragraph.<br>
Expand Down Expand Up @@ -615,11 +615,18 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
<td>Internal Server Error</td>
<td>There was a general internal error within <!--%#INSERT:NAME#%-->. You can get more info from the properties in the response text</td>
</tr>
<tr>
<td class="dr">523</td>
<td>Origin Unreachable</td>
<td>My server is temporarily offline due to maintenance or a dynamic IP update. Please be patient in this case.</td>
</tr>
</table>

<br>

<span class="col g">Success</span> &bull; <span class="col r">Client Error</span> &bull; <span class="col dr">Server Error</span>
<mark>
<span class="col g">Success</span> &bull; <span class="col r">Client Error</span> &bull; <span class="col dr">Server Error</span>
</mark>



Expand Down Expand Up @@ -671,8 +678,11 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
This endpoint provides some information on <!--%#INSERT:NAME#%-->:<br>
- The version number<br>
- The amount of jokes<br>
- All the available categories, flags, types and formats<br>
- A 13-character UNIX timestamp<br>
- The URL to a joke submission form
- The URL to a joke submission form<br>
- The minimum and maximum values of an ID range<br>
- A string with some information, like a message of the day
<br><br>
Supported URL parameters:<br>
<ul>
Expand Down Expand Up @@ -848,6 +858,17 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
</ul>



<!-- #MARKER API Tokens -->
<div class="docHeader targetBlink" id="api-tokens"><a class="headerAnchorContainer" href="#api-tokens" title="Click to link to this header">🔗</a><span class="docHeaderText">API Tokens:</span></div>
<!--%#INSERT:NAME#%--> has a way of whitelisting certain clients. This is achieved through an API token.<br>
At the moment, you will only receive one of these tokens temporarily if something breaks or if you are a business and need more than <!--%#INSERT:RATELIMITCOUNT#%--> requests per minute.<br>
If you do end up receiving a token, using it is as easy as adding an <mark>Authorization</mark> header with the actual token as its value.<br>
You will receive a response header called <mark>Token-Valid</mark> which will contain the number 1 if the token is valid.<br>
If the token is invalid, the Token-Valid header will be set to 0 and <!--%#INSERT:NAME#%--> will treat your request as if you didn't supply a token in the first place.



<!-- #MARKER Examples -->
<div class="docHeader targetBlink" id="examples"><a class="headerAnchorContainer" href="#examples" title="Click to link to this header">🔗</a><span class="docHeaderText">Examples:</span></div>
These are some examples in some commonly used languages to show you how you could implement <!--%#INSERT:NAME#%-->:<br><br>
Expand Down Expand Up @@ -1115,17 +1136,22 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
<!-- #SECTION Dependencies -->
<br><br><span class="subHeader">Dependencies:</span>
<div class="indented">
These are the packages <!--%#INSERT:NAME#%--> depends on (excluding dependencies of dependencies):
These are the packages <!--%#INSERT:NAME#%--> depends on (excluding dependencies of dependencies and devDependencies):
<ul>
<li><a href="https://npmjs.com/package/dotenv" target="_blank">dotenv</a></li>
<li><a href="https://npmjs.com/package/farmhash" target="_blank">farmhash</a></li>
<li><a href="https://npmjs.com/package/http-ratelimit" target="_blank">HTTP-RateLimit</a></li>
<li><a href="https://npmjs.com/package/js2xmlparser" target="_blank">js2xmlparser</a></li>
<li><a href="https://npmjs.com/package/svjsl" target="_blank">JSLib</a></li>
<li><a href="https://npmjs.com/package/json-to-pretty-yaml" target="_blank">json-to-pretty-yaml</a></li>
<li><a href="https://npmjs.com/package/mysql" target="_blank">MySQL</a></li>
<li><a href="https://npmjs.com/package/node-wrap" target="_blank">Node-Wrap</a></li>
<li><a href="https://www.npmjs.com/package/xss" target="_blank">xss</a></li>
<li><a href="https://npmjs.com/package/node-wrap" target="_blank">node-wrap</a></li>
<li><a href="https://npmjs.com/package/promise-all-sequential" target="_blank">promise-all-sequential</a></li>
<li><a href="https://npmjs.com/package/rate-limiter-flexible" target="_blank">rate-limiter-flexible</a></li>
<li><a href="https://npmjs.com/package/request-ip" target="_blank">request-ip</a></li>
<li><a href="https://npmjs.com/package/svjsl" target="_blank">JSLib</a></li>
<li><a href="https://npmjs.com/package/xss" target="_blank">xss</a></li>
<!--
<li><a href="https://npmjs.com/package/XXXX" target="_blank">XXXX</a></li>
-->
</ul>
</div>

Expand Down Expand Up @@ -1185,6 +1211,7 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
</ul>
</details>
<a class="noul" onclick="closeNav()" href="#filtering">Filtering Jokes</a>
<a class="noul" onclick="closeNav()" href="#api-tokens">API Tokens</a>
<a class="noul" onclick="closeNav()" href="#examples">Examples</a>
<!-- <details>
<summary>
Expand Down
18 changes: 13 additions & 5 deletions endpoints/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,23 @@ const call = (req, res, url, params, format) => {
};
}

let totalJokesCount = (!jsl.isEmpty(parseJokes.jokeCount) ? parseJokes.jokeCount : 0);

if(format != "xml")
{
responseText = convertFileFormat.auto(format, {
"error": false,
"version": settings.info.version,
"jokes":
{
"totalCount": (!jsl.isEmpty(parseJokes.jokeCount) ? parseJokes.jokeCount : 0),
"totalCount": totalJokesCount,
"categories": [settings.jokes.possible.anyCategoryName, ...settings.jokes.possible.categories],
"flags": settings.jokes.possible.flags,
"submissionURL": settings.jokes.jokeSubmissionURL
"types": settings.jokes.possible.types,
"submissionURL": settings.jokes.jokeSubmissionURL,
"idRange": [ 0, --totalJokesCount ]
},
"formats": settings.jokes.possible.formats,
"info": settings.info.infoMsg,
"timestamp": new Date().getTime()
});
Expand All @@ -80,11 +85,14 @@ const call = (req, res, url, params, format) => {
"version": settings.info.version,
"jokes":
{
"totalCount": (!jsl.isEmpty(parseJokes.jokeCount) ? parseJokes.jokeCount : 0),
"totalCount": totalJokesCount,
"categories": {"category": [settings.jokes.possible.anyCategoryName, ...settings.jokes.possible.categories]},
"flags": {"flag": settings.jokes.possible.flags},
"submissionURL": settings.jokes.jokeSubmissionURL
"types": {"type": settings.jokes.possible.types},
"submissionURL": settings.jokes.jokeSubmissionURL,
"idRange": [ 0, --totalJokesCount ]
},
"formats": {"format": settings.jokes.possible.formats},
"info": settings.info.infoMsg,
"timestamp": new Date().getTime()
});
Expand All @@ -93,4 +101,4 @@ const call = (req, res, url, params, format) => {
httpServer.pipeString(res, responseText, parseURL.getMimeTypeFromFileFormatString(format));
};

module.exports = { meta, call };
module.exports = { meta, call };
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sv443/jokeapi",
"version": "2.1.4",
"version": "2.1.5",
"description": "A RESTful API that serves jokes from many categories while also offering a lot of filtering methods",
"main": "JokeAPI.js",
"homepage": "https://sv443.net/jokeapi/v2",
Expand Down Expand Up @@ -56,6 +56,8 @@
"json-to-pretty-yaml": "^1.2.2",
"mysql": "^2.18.1",
"node-wrap": "^0.2.0",
"promise-all-sequential": "^1.0.0",
"rate-limiter-flexible": "^2.1.7",
"request-ip": "^2.1.3",
"snyk": "^1.321.0",
"svjsl": "^1.9.4",
Expand Down
Loading

0 comments on commit 1f47b71

Please sign in to comment.