Skip to content

Commit 1f47b71

Browse files
author
BuildTools
committed
Merge branch 'master' of https://github.com/Sv443/JokeAPI
2 parents cb19570 + 5289a9d commit 1f47b71

File tree

16 files changed

+279
-203
lines changed

16 files changed

+279
-203
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div align="center" style="text-align:center">
22

3-
# [![icon](https://sv443.net/cdn/jokeapi/icon_150x150.png)](#readme)<br>JokeAPI
3+
# [![icon](https://sv443.net/cdn/jokeapi/icon_readme.png)](#readme)<br>JokeAPI
44
### A REST API that serves uniformly and well formatted jokes and offers a great variety of filtering methods and response customization
55
[![GitHub](https://img.shields.io/github/license/Sv443/JokeAPI)](https://sv443.net/LICENSE)
66
[![Uptime / 7 Days](https://img.shields.io/uptimerobot/ratio/7/m782998549-afcc0d10c27c87df47e73289)](https://status.sv443.net/)

changelog.txt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
11
====================
22

33
JokeAPI Changelog
4-
- Version 2.1.4 -
4+
- Version 2.1.5 -
55

66
====================
77

88

99

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

2225

23-
[CURRENT: 2.1.4] - 2020 Q3 general patch #1
26+
[CURRENT: 2.1.5] - 2020 Q3 general patch #2
27+
- Ditched my botched rate limiting package for a "commercial" one (issue #113)
28+
- Added API token section to documentation (issue #114)
29+
- Client now receives a "Token-Valid" header with the value 0 or 1 depending on token validity (issue #115)
30+
- Renamed "X-Auth-Token" header to "Authorization" so requests don't get blocked by Cloudflare (issue #117)
31+
- Cleaned up a lot of code
32+
33+
34+
[2.1.4] - 2020 Q3 general patch #1
2435
- Fixed the IP getter module for like the 500th time now
2536

2637

2738
[2.1.3] - 2020 Q2 general patch #1
28-
- Added option to disable all console output but error messages (GitHub isse #72)
39+
- Added option to disable all console output but error messages (GitHub issue #72)
2940
- The content of jokes in the joke submission form is now correctly escaped and can no longer mess up the page (GitHub issue #68)
3041
- Fixed crash when parsing a malformatted URI (GitHub issue #69 (nice))
3142
- Re-flagged some jokes

data/lists/ipBlacklist.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/raw/index.css

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
--doc-header-font-size: 27px;
2323
--doc-sub-header-font-size: 19px;
2424

25-
--sidenav-animation-speed: 0.3s;
25+
--sidenav-animation-speed: 0.15s;
26+
--sidenav-colorblur-speed: 0.5s;
2627
--targetblink-animation-delay: 0.5s;
2728

2829
--scrollbar-track-color: #222;
@@ -54,7 +55,7 @@ body {
5455

5556
overflow-y: hidden;
5657

57-
transition: background-color var(--sidenav-animation-speed);
58+
transition: background-color ease-out var(--sidenav-colorblur-speed);
5859

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

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

177178
display: flex;
178179
flex-direction: row;
@@ -321,7 +322,7 @@ label {
321322
}
322323

323324
#statusCodeTable tr td.dr, span.col.dr {
324-
color: #df0909;
325+
color: #f52727;
325326
}
326327

327328
.colB {
@@ -351,7 +352,7 @@ mark {
351352
padding: 3px;
352353
font-family: "Cascadia Code", "Roboto", "Courier New", monospace;
353354
color: #ccc;
354-
transition: background-color linear var(--sidenav-animation-speed);
355+
transition: background-color ease-out var(--sidenav-colorblur-speed);
355356
}
356357

357358
body[data-sidenav="opened"] mark {
@@ -421,7 +422,7 @@ body[data-sidenav="closed"] code, body code {
421422

422423
filter: grayscale(0%);
423424

424-
transition: filter linear var(--sidenav-animation-speed);
425+
transition: filter ease-out var(--sidenav-colorblur-speed);
425426
}
426427

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

441442
filter: grayscale(50%);
442443

443-
transition: filter linear var(--sidenav-animation-speed);
444+
transition: filter ease-out var(--sidenav-colorblur-speed);
444445
}
445446

446447
body code .nocode.codeheader {
@@ -504,12 +505,12 @@ ul.lispacer li {
504505
padding: 3px;
505506
padding-left: 10px;
506507
padding-right: 40px;
507-
transition: background-color linear var(--sidenav-animation-speed);
508+
transition: background-color ease-out var(--sidenav-colorblur-speed);
508509
}
509510

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

515516
.requestMethodGET, .requestMethodPUT {
@@ -950,4 +951,4 @@ input[disabled]+label {
950951
#urlBuilderUrl {
951952
display: inline-block;
952953
padding: 10px 5px 10px 8px;
953-
}
954+
}

docs/raw/index.html

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
250250
<div class="multiselect noselect">
251251
<input type="radio" id="fmt-cb1" name="formatRadio" value="json" onchange="reRender()"><label for="fmt-cb1">default (json)</label>
252252
<input type="radio" id="fmt-cb2" name="formatRadio" value="xml" onchange="reRender()"><label for="fmt-cb2">xml</label>
253-
<input type="radio" id="fmt-cb3" name="formatRadio" value="yaml" onchange="reRender()"><label for="fmt-cb3">yaml</label> <!-- TODO: -->
254-
<input type="radio" id="fmt-cb4" name="formatRadio" value="txt" onchange="reRender()"><label for="fmt-cb4">plaintext</label>
253+
<input type="radio" id="fmt-cb3" name="formatRadio" value="yaml" onchange="reRender()"><label for="fmt-cb3">yaml</label>
254+
<input type="radio" id="fmt-cb4" name="formatRadio" value="txt" onchange="reRender()"><label for="fmt-cb4">plain text</label>
255255
</div>
256256
</td>
257257
</tr>
@@ -538,12 +538,12 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
538538

539539
<!-- #MARKER Errors -->
540540
<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>
541-
In <!--%#INSERT:NAME#%--> all response data, no matter from which endpoint will have an "error" parameter.<br>
541+
In <!--%#INSERT:NAME#%--> all response data, no matter from which endpoint will have a boolean "error" parameter.<br>
542542
Usually, it is set to false, which means there was no error in your request or on the server.<br>
543543
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>
544544
<br>
545545
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>
546-
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>
546+
The "message" parameter will contain a short version of the error message and the "timestamp" parameter will contain a 13-character Unix timestamp.<br>
547547
The "causedBy" parameter is an array of possible causes of this error and the "addidionalInfo" parameter contains a more descriptive error message.<br>
548548
<br>
549549
You can view an example of an error, where an invalid category was used, just below this paragraph.<br>
@@ -615,11 +615,18 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
615615
<td>Internal Server Error</td>
616616
<td>There was a general internal error within <!--%#INSERT:NAME#%-->. You can get more info from the properties in the response text</td>
617617
</tr>
618+
<tr>
619+
<td class="dr">523</td>
620+
<td>Origin Unreachable</td>
621+
<td>My server is temporarily offline due to maintenance or a dynamic IP update. Please be patient in this case.</td>
622+
</tr>
618623
</table>
619624

620625
<br>
621626

622-
<span class="col g">Success</span> &bull; <span class="col r">Client Error</span> &bull; <span class="col dr">Server Error</span>
627+
<mark>
628+
<span class="col g">Success</span> &bull; <span class="col r">Client Error</span> &bull; <span class="col dr">Server Error</span>
629+
</mark>
623630

624631

625632

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

850860

861+
862+
<!-- #MARKER API Tokens -->
863+
<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>
864+
<!--%#INSERT:NAME#%--> has a way of whitelisting certain clients. This is achieved through an API token.<br>
865+
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>
866+
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>
867+
You will receive a response header called <mark>Token-Valid</mark> which will contain the number 1 if the token is valid.<br>
868+
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.
869+
870+
871+
851872
<!-- #MARKER Examples -->
852873
<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>
853874
These are some examples in some commonly used languages to show you how you could implement <!--%#INSERT:NAME#%-->:<br><br>
@@ -1115,17 +1136,22 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
11151136
<!-- #SECTION Dependencies -->
11161137
<br><br><span class="subHeader">Dependencies:</span>
11171138
<div class="indented">
1118-
These are the packages <!--%#INSERT:NAME#%--> depends on (excluding dependencies of dependencies):
1139+
These are the packages <!--%#INSERT:NAME#%--> depends on (excluding dependencies of dependencies and devDependencies):
11191140
<ul>
11201141
<li><a href="https://npmjs.com/package/dotenv" target="_blank">dotenv</a></li>
11211142
<li><a href="https://npmjs.com/package/farmhash" target="_blank">farmhash</a></li>
1122-
<li><a href="https://npmjs.com/package/http-ratelimit" target="_blank">HTTP-RateLimit</a></li>
11231143
<li><a href="https://npmjs.com/package/js2xmlparser" target="_blank">js2xmlparser</a></li>
1124-
<li><a href="https://npmjs.com/package/svjsl" target="_blank">JSLib</a></li>
11251144
<li><a href="https://npmjs.com/package/json-to-pretty-yaml" target="_blank">json-to-pretty-yaml</a></li>
11261145
<li><a href="https://npmjs.com/package/mysql" target="_blank">MySQL</a></li>
1127-
<li><a href="https://npmjs.com/package/node-wrap" target="_blank">Node-Wrap</a></li>
1128-
<li><a href="https://www.npmjs.com/package/xss" target="_blank">xss</a></li>
1146+
<li><a href="https://npmjs.com/package/node-wrap" target="_blank">node-wrap</a></li>
1147+
<li><a href="https://npmjs.com/package/promise-all-sequential" target="_blank">promise-all-sequential</a></li>
1148+
<li><a href="https://npmjs.com/package/rate-limiter-flexible" target="_blank">rate-limiter-flexible</a></li>
1149+
<li><a href="https://npmjs.com/package/request-ip" target="_blank">request-ip</a></li>
1150+
<li><a href="https://npmjs.com/package/svjsl" target="_blank">JSLib</a></li>
1151+
<li><a href="https://npmjs.com/package/xss" target="_blank">xss</a></li>
1152+
<!--
1153+
<li><a href="https://npmjs.com/package/XXXX" target="_blank">XXXX</a></li>
1154+
-->
11291155
</ul>
11301156
</div>
11311157

@@ -1185,6 +1211,7 @@ <h2 style="color: orangered;">By using this website and API you are agreeing to
11851211
</ul>
11861212
</details>
11871213
<a class="noul" onclick="closeNav()" href="#filtering">Filtering Jokes</a>
1214+
<a class="noul" onclick="closeNav()" href="#api-tokens">API Tokens</a>
11881215
<a class="noul" onclick="closeNav()" href="#examples">Examples</a>
11891216
<!-- <details>
11901217
<summary>

endpoints/info.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ const call = (req, res, url, params, format) => {
5757
};
5858
}
5959

60+
let totalJokesCount = (!jsl.isEmpty(parseJokes.jokeCount) ? parseJokes.jokeCount : 0);
61+
6062
if(format != "xml")
6163
{
6264
responseText = convertFileFormat.auto(format, {
6365
"error": false,
6466
"version": settings.info.version,
6567
"jokes":
6668
{
67-
"totalCount": (!jsl.isEmpty(parseJokes.jokeCount) ? parseJokes.jokeCount : 0),
69+
"totalCount": totalJokesCount,
6870
"categories": [settings.jokes.possible.anyCategoryName, ...settings.jokes.possible.categories],
6971
"flags": settings.jokes.possible.flags,
70-
"submissionURL": settings.jokes.jokeSubmissionURL
72+
"types": settings.jokes.possible.types,
73+
"submissionURL": settings.jokes.jokeSubmissionURL,
74+
"idRange": [ 0, --totalJokesCount ]
7175
},
76+
"formats": settings.jokes.possible.formats,
7277
"info": settings.info.infoMsg,
7378
"timestamp": new Date().getTime()
7479
});
@@ -80,11 +85,14 @@ const call = (req, res, url, params, format) => {
8085
"version": settings.info.version,
8186
"jokes":
8287
{
83-
"totalCount": (!jsl.isEmpty(parseJokes.jokeCount) ? parseJokes.jokeCount : 0),
88+
"totalCount": totalJokesCount,
8489
"categories": {"category": [settings.jokes.possible.anyCategoryName, ...settings.jokes.possible.categories]},
8590
"flags": {"flag": settings.jokes.possible.flags},
86-
"submissionURL": settings.jokes.jokeSubmissionURL
91+
"types": {"type": settings.jokes.possible.types},
92+
"submissionURL": settings.jokes.jokeSubmissionURL,
93+
"idRange": [ 0, --totalJokesCount ]
8794
},
95+
"formats": {"format": settings.jokes.possible.formats},
8896
"info": settings.info.infoMsg,
8997
"timestamp": new Date().getTime()
9098
});
@@ -93,4 +101,4 @@ const call = (req, res, url, params, format) => {
93101
httpServer.pipeString(res, responseText, parseURL.getMimeTypeFromFileFormatString(format));
94102
};
95103

96-
module.exports = { meta, call };
104+
module.exports = { meta, call };

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sv443/jokeapi",
3-
"version": "2.1.4",
3+
"version": "2.1.5",
44
"description": "A RESTful API that serves jokes from many categories while also offering a lot of filtering methods",
55
"main": "JokeAPI.js",
66
"homepage": "https://sv443.net/jokeapi/v2",
@@ -56,6 +56,8 @@
5656
"json-to-pretty-yaml": "^1.2.2",
5757
"mysql": "^2.18.1",
5858
"node-wrap": "^0.2.0",
59+
"promise-all-sequential": "^1.0.0",
60+
"rate-limiter-flexible": "^2.1.7",
5961
"request-ip": "^2.1.3",
6062
"snyk": "^1.321.0",
6163
"svjsl": "^1.9.4",

0 commit comments

Comments
 (0)