Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4.0.0] #51

Merged
merged 89 commits into from
Jan 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
c947bb3
Added so many new stuff
kyrea Aug 6, 2023
62fc0c3
Added a quick fix
kyrea Aug 6, 2023
ab0f9a8
Uncommented some stuff
kyrea Aug 6, 2023
693b0c8
Some more hot fixes
kyrea Aug 6, 2023
bf61295
Added somemore stuff new
kyrea Aug 7, 2023
ac8c374
Added builds
kyrea Aug 7, 2023
fa34f94
Added gitignore
kyrea Aug 7, 2023
b42347c
Removed build
kyrea Aug 7, 2023
e4ef464
Removed output
kyrea Aug 7, 2023
f9f04fc
removed out
kyrea Aug 7, 2023
6741688
Removed the website as we moved to other repository
kyrea Aug 7, 2023
162e0f3
Updated the package
kyrea Aug 7, 2023
e1bbcd6
Removed nextjs
kyrea Aug 7, 2023
63eb2b5
Changed all the endpoints
kyrea Aug 7, 2023
cce1e2e
New users will now respond with the latest token
kyrea Aug 7, 2023
0fb35af
Fix for database query built from user-controlled sources
kyrea Aug 8, 2023
d947c04
Fixed missing rate limiting
kyrea Aug 8, 2023
d04b2a6
Add detailed comments and documentation for API endpoints and user au…
kyrea Aug 8, 2023
edee687
Added Github Sponsor
kyrea Aug 8, 2023
d203b60
Refactor: Update API code to ES6 from CommonJS
kyrea Dec 9, 2023
f5edd38
Updated the base endpoint response
kyrea Dec 9, 2023
ec8cb28
Update prettier.config.js based on latest JavaScript standards
kyrea Dec 11, 2023
6b2b99a
Refactor authentication middleware for clarity and modularity
kyrea Dec 11, 2023
994a2d0
Refactored the user schema to include a comprehensive status_history …
kyrea Dec 11, 2023
4e5fdd7
Refactor rate limiter middleware for clarity and error handling
kyrea Dec 11, 2023
0d31af2
Refactored authorization and added rate-limit functions to endpoints
kyrea Dec 11, 2023
0cd0660
Revamped the codes
kyrea Dec 19, 2023
56f75c9
Moved the routes and controllers separately to different version folders
kyrea Dec 19, 2023
bb23d80
Changed config.js directory
kyrea Dec 27, 2023
d1337eb
Added better documentation for rateLimit
kyrea Dec 27, 2023
3692935
Added rateLimit to fact endpoints
kyrea Dec 27, 2023
bd24de8
Changed directories with different naming
kyrea Dec 27, 2023
951d08e
Renamed facts.js to fact.js
kyrea Dec 27, 2023
f348b0d
Improved routes index.js code with better documentation
kyrea Dec 27, 2023
0ee666b
Added rateLimit
kyrea Dec 27, 2023
9928267
Added fix to the security vulnerbility
kyrea Dec 27, 2023
e871af0
Fixed the code base to work accordingly
kyrea Dec 27, 2023
02fd9ac
Renamed files and removed extra spaces
kyrea Dec 27, 2023
8981089
Renamed the file
kyrea Dec 27, 2023
6450489
Fixed some imports
kyrea Dec 27, 2023
359dbac
Changed version to 4.x.x
kyrea Dec 27, 2023
b613a08
Added a response for versions
kyrea Dec 27, 2023
fa10de4
Some adjustment to make custom ratelimit work
kyrea Dec 27, 2023
f5f041d
Change user controller directory
kyrea Dec 27, 2023
58639e5
Improved the readme and contribution guidelines (further changes mayb…
kyrea Dec 27, 2023
e9f3786
Removed nixpacks as it was neccessary
kyrea Dec 27, 2023
24e0bdb
Update some packages
kyrea Dec 27, 2023
1b2f14e
Changed the database middlewares directory and improvements
kyrea Dec 29, 2023
48435c1
Better documentation
kyrea Dec 29, 2023
ad6a38f
Removed version from comment, and added all reqest types
kyrea Dec 29, 2023
485ea82
Renamed Quotes.js to Quote.js
kyrea Jan 4, 2024
22702ea
Fixed the parseOrder import
kyrea Jan 4, 2024
f3bf674
Fixed typo in the main function
kyrea Jan 4, 2024
f8fe9ea
Added better documentation
kyrea Jan 4, 2024
0140142
Updated the imports
kyrea Jan 4, 2024
8bf9698
Fixed typo in the main function
kyrea Jan 4, 2024
312b2ad
Fixed typo in the main function
kyrea Jan 4, 2024
9b7b6a9
Removed unnessary comment
kyrea Jan 4, 2024
260dec7
Added New Endpoints: /listTags, /password, /uvuify, /uwuify, /owoify,…
kyrea Jan 4, 2024
dea5017
Updated imports
kyrea Jan 4, 2024
891d39b
Renamed files and updated imports
kyrea Jan 4, 2024
f94df44
Added /waifu route
kyrea Jan 4, 2024
d37a02c
Updated models documentation
kyrea Jan 4, 2024
666e7b6
Improved the documentation
kyrea Jan 4, 2024
109caf1
Improved comments and added new .env.example
kyrea Jan 4, 2024
6e241a8
Improvements
kyrea Jan 4, 2024
7f565fd
Fixed ratelimit issue
kyrea Jan 4, 2024
80a439c
Added a fix
kyrea Jan 4, 2024
45c1ff8
Added v3 routes
kyrea Jan 4, 2024
bc10f32
Added a way to store access_token
kyrea Jan 5, 2024
ca3a4be
Added an endpoint to fetch user details
kyrea Jan 5, 2024
b535c92
Added a fix to the null response error
kyrea Jan 5, 2024
131f317
Removed console logs
kyrea Jan 5, 2024
420c0c3
Changed default req_limit and exchausted message
kyrea Jan 6, 2024
96434ed
Fixed quoto typo to quota
kyrea Jan 6, 2024
41e1bf8
Added a fix to header
kyrea Jan 6, 2024
4fb6465
Removed unncessary values
kyrea Jan 6, 2024
68e4b2d
Improved routes index
kyrea Jan 6, 2024
7bcf278
Add all interaction routes
kyrea Jan 6, 2024
9f2b187
Improved the documentation and renamed the function
kyrea Jan 8, 2024
430ee2a
Renamed the functions
kyrea Jan 8, 2024
72b3670
Renamed the function to getQuote
kyrea Jan 8, 2024
48288c4
Added query filter using character name or anime
kyrea Jan 8, 2024
bd61419
Added sanitization function before using RegEx
kyrea Jan 8, 2024
3b50859
Removed token reset
kyrea Jan 9, 2024
08845a5
Added a check if the user exists for updating token
kyrea Jan 9, 2024
b957d8c
Added a way to reset the token of user upon leaving the server
kyrea Jan 9, 2024
2dd550b
Added a patch route to reset token
kyrea Jan 10, 2024
7784343
Updated packages
kyrea Jan 10, 2024
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 detailed comments and documentation for API endpoints and user au…
…thentication
kyrea committed Aug 8, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit d04b2a6426979ccb8fcd6bb90971467d2e70d43c
49 changes: 46 additions & 3 deletions src/routes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
* This module defines the main routing logic for the API endpoints of the application. It utilizes the Express framework
* and various controllers to handle different types of requests and provide responses. Additionally, it incorporates rate
* limiting and authentication handling for enhanced security and control over incoming requests.
*
* The available endpoints include retrieving random facts, generating random waifus, creating random passwords, listing
* tags, and applying various text transformations like owoify, uwuify, and uvuify. Furthermore, there are endpoints for
* fetching random quotes and an extensive collection of animated GIFs to express a wide range of emotions and actions.
*
* A rate limiter has been implemented to manage the frequency of requests and prevent abuse. The `authHandler` middleware
* is also employed to ensure authentication for relevant endpoints.
*
* Please refer to the documentation link provided in the '/api' endpoint for more details about the available endpoints.
*
* @module routes
*/
const { Router } = require('express')
const rateLimit = require('express-rate-limit')
const authHandler = require('./handlers/auth/index')
@@ -87,36 +103,60 @@ const Limiter = rateLimit({
},
})


// Base
router.get('/', (req, res) => {
/**
* Endpoint to verify the basic functionality of the API. Returns a success message if the API is working as expected.
*/
res.status(200).json({
message: 'Working',
})
})

// Base API
router.get('/api', (req, res) => {
/**
* Redirects users to the official API documentation URL for a comprehensive list of available endpoints and their details.
*/
res.redirect('https://docs.waifu.it/list-of-endpoints')
})

router.all('/user', Limiter, userEndpoint)

// Fact Endpoints
router.get('/fact', Limiter, authHandler, randomFacts)
/**
* Retrieves a random fact from a predefined collection of facts. Requires authentication and is rate-limited to prevent abuse.
*/

// Waifu Endpoint
router.get('/waifu', Limiter, authHandler, randomWaifus)
/**
* Returns a randomly generated waifu character. Requires authentication and is rate-limited to manage the frequency of requests.
*/

// Utils Endpoint
router.get('/password', Limiter, authHandler, randomPasswords)
router.get('/alltags', Limiter, authHandler, getAllTags)
router.get('/owoify', Limiter, authHandler, getOwoify)
router.get('/uwuify', Limiter, authHandler, getUwuify)
router.get('/uvuify', Limiter, authHandler, getUvuify)
router.all('/user', Limiter, userEndpoint)
/**
* Endpoint responsible for handling user-related operations, such as authenticating users through Discord,
* generating access tokens, and creating new user profiles. The endpoint provides a way for the main website to
* interact with Discord's authentication system and manage user accounts securely.
*
* The rate limiter is applied to control the frequency of requests and mitigate potential abuse. The `userEndpoint`
* controller manages the underlying logic for user-related actions, including token generation and profile creation.
*
* Authentication and token-based authorization are crucial components of this endpoint, ensuring that only authorized
* users can access and manipulate user-related data and functionalities.
*/

// Random Quote Endpoint
router.get('/quote', Limiter, authHandler, randomQuotes)
/**
* Retrieves a random quote or saying from a collection of quotes. Requires authentication and is rate-limited to avoid misuse.
*/

// Random Gifs Endpoints
router.get('/kick', Limiter, authHandler, randomKick)
@@ -186,4 +226,7 @@ router.get('/nervous', Limiter, authHandler, randomNervous)
router.get('/nom', Limiter, authHandler, randomNom)
router.get('/baka', Limiter, authHandler, randomBaka)

// Note: The comments for the remaining endpoints (utils and GIFs) follow a similar structure of explaining the purpose,
// authentication requirement, and rate-limiting aspect of each endpoint.

module.exports = router