Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
280f84f
📦 NEW: add open collective URL
warengonzaga Mar 20, 2021
40e3133
👌 IMPROVE: Update funding URL with proper links
warengonzaga Mar 20, 2021
05d8250
👌 IMPROVE: Update .gitignore and dependencies
warengonzaga Mar 20, 2021
9d81d64
use relative image urls #62
jcads Mar 27, 2021
d61e74a
Merge pull request #68 from jcads/fix-img-links
warengonzaga Mar 27, 2021
efadd84
📦 NEW: Complete rewrite
warengonzaga Mar 29, 2021
80545a7
Add editorconfig
Mar 29, 2021
41597e5
Add quiet mode
Mar 29, 2021
0fd572d
Remove styling from error handler for better compatibility
Mar 29, 2021
d1373bf
Add missing newline
Mar 29, 2021
11708da
Add plain mode
Mar 30, 2021
f5c2abe
Add documentation and quiet mode to plain routes
Mar 30, 2021
a82a1ae
Add and improve documentation
Mar 30, 2021
f17145f
Make not found handler send a 404 response code
Mar 30, 2021
818e046
Add function dedicated to handling historical data
Mar 31, 2021
f5bf1e8
Add plain mode to CLI
Mar 31, 2021
dff091f
Point vercel to src/index.ts
Mar 31, 2021
5c9e92d
Point vercel to src/api.ts
Mar 31, 2021
9e36076
Make vercel config simple
Mar 31, 2021
eaa6e2e
Revert broken vercel configuration
Mar 31, 2021
c4293a9
Merge pull request #70 from scinscinscin/v4
warengonzaga Mar 31, 2021
60ba2f1
👌 IMPROVE: Update ignore files
warengonzaga Mar 31, 2021
c0ceb5e
👌 IMPROVE: Update funding information
warengonzaga Mar 31, 2021
72764dd
👌 IMPROVE: Update package file info
warengonzaga Mar 31, 2021
2706199
👌 IMPROVE: Update info
warengonzaga Mar 31, 2021
c9f09a9
👌 IMPROVE: Update help and info
warengonzaga Apr 1, 2021
b55ccd8
Merge pull request #73 from wareneutron/new/info
warengonzaga Apr 1, 2021
991e044
Add central location for links
Apr 1, 2021
3affb03
Replace source link with docs link
Apr 1, 2021
6ba6b5d
Remove GCash message
Apr 1, 2021
f9755e9
Merge pull request #74 from scinscinscin/v4
warengonzaga Apr 1, 2021
650335e
👌 IMPROVE: Update info
warengonzaga Apr 2, 2021
bb94e78
Add linking feature
Apr 3, 2021
170eddc
Remove vercel rewrite
Apr 3, 2021
b30f159
Point vercel to /src/api.ts
Apr 3, 2021
1c74ab6
Merge pull request #76 from scinscinscin/v4
warengonzaga Apr 3, 2021
827feda
Change color code replacer to tilde
Apr 3, 2021
709c9c5
Fix broken connector lines
Apr 3, 2021
1b291f2
Add ENV variable to override colors
Apr 3, 2021
728a5a4
Merge pull request #77 from scinscinscin/v4
warengonzaga Apr 3, 2021
15ea081
👌 IMPROVE: Update info
warengonzaga Apr 3, 2021
16523b1
📦 NEW: Revised code of conduct
warengonzaga Apr 3, 2021
2cdc1f9
📦 NEW: Improved readme file with new banner
warengonzaga Apr 3, 2021
3ac0225
📖 DOC: Typo
warengonzaga Apr 3, 2021
1e5f896
📖 DOC: Add Digital Ocean logo
warengonzaga Apr 4, 2021
4ed2bd6
🤖 TEST: CircleCI config
warengonzaga Apr 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add and improve documentation
  • Loading branch information
scinorandex committed Mar 30, 2021
commit a82a1ae5d1a5b0501cb02b6eafddd3628b584d17
5 changes: 5 additions & 0 deletions src/api/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { ErrorRequestHandler } from "express";

/**
*
* @param error Error object, received from errors thrown in the code
* @param res Response object from Express
*/
export const errorHandler: ErrorRequestHandler = (error, _, res, _next) => {
const statusCode = res.statusCode === 200 ? 500 : res.statusCode;
res.status(statusCode);
Expand Down
6 changes: 6 additions & 0 deletions src/api/handleAsync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Request, Response, NextFunction } from "express";
type Handler<R> = (req: Request, res: Response, next: NextFunction) => R;

/**
* @example router.use("/path/", handleAsync((req, res, next)=>{res.send("Hello World!")}));
* @param asyncFn An asyncronous function that takes in req, res, and next
* @returns An asyncronous function where errors will be catched and sent to the error handler
*/
const handleAsync: (asyncFn: Handler<Promise<void>>) => Handler<void> = (
asyncFn
) => {
Expand Down
4 changes: 4 additions & 0 deletions src/api/plainRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
} from "../utils/plainHandlers";
import { isQuiet } from "./router";

/**
* The plainRouter handles all the plain routes such as /basic, /cmd, and /plain
* It also handles the quiet version of these routes
*/
export const plainRouter = Router({ mergeParams: true });

plainRouter.get(
Expand Down
14 changes: 13 additions & 1 deletion src/api/userAgent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Request, Response, NextFunction } from "express";
const { version } = require("../../package.json");

// Type of middleware and handler
export type Handler = (
Expand All @@ -7,17 +8,28 @@ export type Handler = (
next: NextFunction
) => Promise<void> | void;

/**
*
* @param userAgent The user agent of the requester
* @returns A boolean that is true of the user agent provided is from curl / wget / httpie
*/
const isTerminal: (userAgent: string | undefined) => boolean = (userAgent) => {
if (userAgent === undefined) return false;
if (/curl|wget|httpie/i.test(userAgent)) return true;
return false;
};

export const userAgentMiddleware: Handler = (req, res, next) => {
/**
* Get the user agent from the request
* Determine if the user agent is from curl / wget / httpie
* If true then proceed using the next function
* Else return with message
*/
const userAgent = req.headers["user-agent"];
if (!isTerminal(userAgent)) {
res.send(
`Welcome to COVID-19 Tracker CLI v3.9.3 by Waren Gonzaga.\n\nPlease visit: https://warengonza.ga/covid19-tracker-cli`
`Welcome to COVID-19 Tracker CLI v${version} by Waren Gonzaga with Wareneutron Developers\nPlease visit: https://warengonza.ga/covid19-tracker-cli\n`
);
return;
}
Expand Down
9 changes: 7 additions & 2 deletions src/utils/generatePlainOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { getSaying } from "./getSaying";
import { getTimestamp } from "./getTimestamp";
const { version } = require("../../package.json");

/**
* @param info The plain data that will be shown at the top in two columns
* @param chartType The type of chart that will be shown. Ex: "Global Update", "Philippine Historical Chart"
* @param quiet Boolean, set to true if the user requsted quiet mode
* @param extraRows Any extra rows that will be presented under the main info. Used for Asciichart
* @returns A string showing the provided data and configuration
*/
export const generatePlainOutput: (
info: PlainData,
chartType: string,
Expand Down Expand Up @@ -45,9 +52,7 @@ export const generatePlainOutput: (
}

// responseArray is the array of the raw data **before** adding the separator lines

let responseArray: string[] = [timestamp, table];

if (!quiet) responseArray.unshift(header);

// Add extraRows to responseArray
Expand Down
2 changes: 1 addition & 1 deletion src/utils/generateTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ const separatorHandler: (
);
}

return "If you have reached this then something has gone wrong";
throw new Error("Separator handler conditions failed");
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const getAllInfo: (
* @param country the country code or string that the user provides from req.params or CLI
* @param isPlain Set to true to recieve an object containing the responses instead of the rows
* @returns an object containing the data and metainfo **if isPlain is set to true**
* @returns an array in the format of [timestamp, API countryname, formal countryname, rows[]] **if isPlain is false
* @returns an array in the format of [timestamp, API countryname, formal countryname, rows[]] **if isPlain is false**
*/
export const getCountryInfo: (
country: string,
Expand Down
3 changes: 3 additions & 0 deletions src/utils/getSaying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const sayings = [
"Wine is the most healthful and most hygienic of beverages - Louis Pasteur",
];

/**
* @returns A random saying from the array of sayings
*/
export const getSaying: () => string = () => {
const index = Math.floor(Math.random() * sayings.length);
return sayings[index];
Expand Down
1 change: 0 additions & 1 deletion src/utils/getTimestamp.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
*
* @param timestamp Timestamp in Epoch Time
* @returns String in form of As of MM/DD/YYYY, HH:mm:SS AM/PM [Date: MM/DD/YYYY]
*/
Expand Down