-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { Router } from 'express'; | ||
import getRandomWaifu from '../../../controllers/v4/images/waifu.js'; | ||
import createRateLimiter from '../../../middlewares/rateLimit.js'; | ||
import authorize from '../../../middlewares/authorize.js'; | ||
import incrementData from '../../../middlewares/database/add.js'; | ||
import updateData from '../../../middlewares/database/update.js'; | ||
import deleteData from '../../../middlewares/database/delete.js'; | ||
|
||
const router = Router(); | ||
|
||
router | ||
.route('/') | ||
/** | ||
* @api {get} v4/waifu Get a Random Waifu | ||
* @apiDescription Retrieve a random Waifu. | ||
* @apiName getRandomWaifu | ||
* @apiGroup images | ||
* @apiPermission user | ||
* | ||
* @apiHeader {String} Authorization User's access token. | ||
* | ||
* @apiSuccess {Object[]} users List of users. | ||
* | ||
* @apiError (Unauthorized 401) Unauthorized Only authenticated users can access the data. | ||
* @apiError (Forbidden 403) Forbidden Only users can access the data. | ||
* @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. | ||
* @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. | ||
* | ||
* @function createRateLimit | ||
* @description Creates a rate limiter middleware to control the frequency of requests. | ||
* @returns {function} Express middleware function that handles rate limiting. | ||
* | ||
*/ | ||
.get(authorize(config.roles.USER), createRateLimiter(), getRandomWaifu) | ||
/** | ||
* @api {post} v4/waifu Increment Waifu Data | ||
* @apiDescription Increment data related to Waifus (only accessible by database moderators). | ||
* @apiName IncrementWaifuData | ||
* @apiGroup images | ||
* @apiPermission database_moderator | ||
* | ||
* @apiHeader {String} Authorization Database Moderator's access token. | ||
* | ||
* @apiSuccess {Object} result Result of the data incrementation. | ||
* | ||
* @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. | ||
* @apiError (Forbidden 403) Forbidden Only users can access the data. | ||
* @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. | ||
* @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. | ||
* | ||
* @function createRateLimit | ||
* @description Creates a rate limiter middleware to control the frequency of requests. | ||
* @returns {function} Express middleware function that handles rate limiting. | ||
* | ||
*/ | ||
.post(authorize(config.roles.DB_MOD), createRateLimiter(), incrementData('Waifu')); | ||
|
||
router | ||
.route('/:id') | ||
/** | ||
* @api {patch} v4/waifu/:id Update Waifu Data | ||
* @apiDescription Update data related to Waifus with a specific ID (only accessible by database moderators). | ||
* @apiName UpdateWaifuData | ||
* @apiGroup Waifu | ||
* @apiPermission database_moderator | ||
* | ||
* @apiHeader {String} Authorization database moderator access token. | ||
* | ||
* @apiSuccess {Object} result Result of the data update. | ||
* | ||
* @apiError (Unauthorized 401) Unauthorized Only authenticated database moderator can access the data. | ||
* @apiError (Forbidden 403) Forbidden Only users can access the data. | ||
* @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. | ||
* @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. | ||
* | ||
* @function createRateLimit | ||
* @description Creates a rate limiter middleware to control the frequency of requests. | ||
* @returns {function} Express middleware function that handles rate limiting. | ||
*/ | ||
.patch(authorize(config.roles.DB_MOD), createRateLimiter(), updateData('Waifu')) | ||
/** | ||
* @api {delete} v4/waifu/:id Delete Waifu Data | ||
* @apiDescription Delete data related to Waifu with a specific ID (only accessible by admins). | ||
* @apiName DeleteWaifuData | ||
* @apiGroup Waifu | ||
* @apiPermission admin | ||
* | ||
* @apiHeader {String} Authorization Admin's access token. | ||
* | ||
* @apiSuccess {Object} result Result of the data deletion. | ||
* | ||
* @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. | ||
* @apiError (Forbidden 403) Forbidden Only users can access the data. | ||
* @apiError (Too Many Requests 429) TooManyRequests The client has exceeded the allowed number of requests within the time window. | ||
* @apiError (Internal Server Error 500) InternalServerError An error occurred while processing the rate limit. | ||
* | ||
* @function createRateLimit | ||
* @description Creates a rate limiter middleware to control the frequency of requests. | ||
* @returns {function} Express middleware function that handles rate limiting. | ||
*/ | ||
.delete(authorize(config.roles.ADMIN), createRateLimiter(), deleteData('Waifu')); | ||
// Export the router | ||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters