From 56f75c97318604f6dafd746984f5e4a278f286ef Mon Sep 17 00:00:00 2001 From: kyrea Date: Tue, 19 Dec 2023 23:30:19 +0530 Subject: [PATCH] Moved the routes and controllers separately to different version folders --- src/controllers/v3/facts/randomFacts.js | 58 +++++ src/controllers/{ => v3}/gifs/randomAngry.js | 4 +- src/controllers/{ => v3}/gifs/randomBaka.js | 4 +- src/controllers/{ => v3}/gifs/randomBite.js | 4 +- src/controllers/{ => v3}/gifs/randomBlush.js | 4 +- src/controllers/{ => v3}/gifs/randomBonk.js | 4 +- src/controllers/{ => v3}/gifs/randomBored.js | 4 +- src/controllers/{ => v3}/gifs/randomBully.js | 4 +- src/controllers/{ => v3}/gifs/randomBye.js | 4 +- src/controllers/{ => v3}/gifs/randomChase.js | 4 +- src/controllers/{ => v3}/gifs/randomCheer.js | 4 +- src/controllers/{ => v3}/gifs/randomCringe.js | 4 +- src/controllers/{ => v3}/gifs/randomCry.js | 4 +- src/controllers/{ => v3}/gifs/randomCuddle.js | 4 +- src/controllers/{ => v3}/gifs/randomDab.js | 4 +- src/controllers/{ => v3}/gifs/randomDance.js | 4 +- src/controllers/{ => v3}/gifs/randomDie.js | 4 +- .../{ => v3}/gifs/randomDisgust.js | 4 +- .../{ => v3}/gifs/randomFacepalm.js | 4 +- src/controllers/{ => v3}/gifs/randomFeed.js | 4 +- src/controllers/{ => v3}/gifs/randomGlomp.js | 4 +- src/controllers/{ => v3}/gifs/randomHappy.js | 4 +- src/controllers/{ => v3}/gifs/randomHi.js | 4 +- .../{ => v3}/gifs/randomHighfive.js | 4 +- src/controllers/{ => v3}/gifs/randomHold.js | 4 +- src/controllers/{ => v3}/gifs/randomHug.js | 4 +- src/controllers/{ => v3}/gifs/randomKick.js | 4 +- src/controllers/{ => v3}/gifs/randomKill.js | 4 +- src/controllers/{ => v3}/gifs/randomKissu.js | 4 +- src/controllers/{ => v3}/gifs/randomLaugh.js | 4 +- src/controllers/{ => v3}/gifs/randomLick.js | 4 +- src/controllers/{ => v3}/gifs/randomLove.js | 4 +- src/controllers/{ => v3}/gifs/randomLurk.js | 4 +- .../{ => v3}/gifs/randomMidfing.js | 4 +- .../{ => v3}/gifs/randomNervous.js | 4 +- src/controllers/{ => v3}/gifs/randomNom.js | 4 +- src/controllers/{ => v3}/gifs/randomNope.js | 4 +- src/controllers/{ => v3}/gifs/randomNuzzle.js | 4 +- src/controllers/{ => v3}/gifs/randomPanic.js | 4 +- src/controllers/{ => v3}/gifs/randomPat.js | 4 +- src/controllers/{ => v3}/gifs/randomPeck.js | 4 +- src/controllers/{ => v3}/gifs/randomPoke.js | 4 +- src/controllers/{ => v3}/gifs/randomPout.js | 4 +- src/controllers/{ => v3}/gifs/randomPunch.js | 4 +- src/controllers/{ => v3}/gifs/randomRun.js | 4 +- src/controllers/{ => v3}/gifs/randomSad.js | 4 +- src/controllers/{ => v3}/gifs/randomShoot.js | 4 +- src/controllers/{ => v3}/gifs/randomShrug.js | 4 +- src/controllers/{ => v3}/gifs/randomSip.js | 4 +- src/controllers/{ => v3}/gifs/randomSlap.js | 4 +- src/controllers/{ => v3}/gifs/randomSleepy.js | 4 +- src/controllers/{ => v3}/gifs/randomSmile.js | 4 +- src/controllers/{ => v3}/gifs/randomSmug.js | 4 +- src/controllers/{ => v3}/gifs/randomStab.js | 4 +- src/controllers/{ => v3}/gifs/randomStare.js | 4 +- .../{ => v3}/gifs/randomSuicide.js | 4 +- src/controllers/{ => v3}/gifs/randomTease.js | 4 +- src/controllers/{ => v3}/gifs/randomThink.js | 4 +- .../{ => v3}/gifs/randomThumbsup.js | 4 +- src/controllers/{ => v3}/gifs/randomTickle.js | 4 +- .../{ => v3}/gifs/randomTriggered.js | 4 +- src/controllers/{ => v3}/gifs/randomWag.js | 4 +- src/controllers/{ => v3}/gifs/randomWave.js | 4 +- src/controllers/{ => v3}/gifs/randomWink.js | 4 +- src/controllers/{ => v3}/gifs/randomYes.js | 4 +- .../{ => v3}/quotes/randomQuotes.js | 4 +- src/controllers/v3/utils/listTags.js | 58 +++++ src/controllers/{ => v3}/utils/owoify.js | 2 +- .../{ => v3}/utils/randomPassword.js | 2 +- src/controllers/v3/utils/user.js | 83 +++++++ src/controllers/{ => v3}/utils/uvuify.js | 2 +- src/controllers/{ => v3}/utils/uwuify.js | 2 +- .../{ => v3}/waifus/randomWaifus.js | 4 +- src/controllers/{ => v4}/facts/randomFacts.js | 8 +- src/controllers/v4/gifs/randomAngry.js | 31 +++ src/controllers/v4/gifs/randomBaka.js | 31 +++ src/controllers/v4/gifs/randomBite.js | 31 +++ src/controllers/v4/gifs/randomBlush.js | 31 +++ src/controllers/v4/gifs/randomBonk.js | 31 +++ src/controllers/v4/gifs/randomBored.js | 31 +++ src/controllers/v4/gifs/randomBully.js | 31 +++ src/controllers/v4/gifs/randomBye.js | 31 +++ src/controllers/v4/gifs/randomChase.js | 31 +++ src/controllers/v4/gifs/randomCheer.js | 31 +++ src/controllers/v4/gifs/randomCringe.js | 31 +++ src/controllers/v4/gifs/randomCry.js | 31 +++ src/controllers/v4/gifs/randomCuddle.js | 31 +++ src/controllers/v4/gifs/randomDab.js | 31 +++ src/controllers/v4/gifs/randomDance.js | 31 +++ src/controllers/v4/gifs/randomDie.js | 31 +++ src/controllers/v4/gifs/randomDisgust.js | 31 +++ src/controllers/v4/gifs/randomFacepalm.js | 31 +++ src/controllers/v4/gifs/randomFeed.js | 31 +++ src/controllers/v4/gifs/randomGlomp.js | 31 +++ src/controllers/v4/gifs/randomHappy.js | 31 +++ src/controllers/v4/gifs/randomHi.js | 31 +++ src/controllers/v4/gifs/randomHighfive.js | 31 +++ src/controllers/v4/gifs/randomHold.js | 31 +++ src/controllers/v4/gifs/randomHug.js | 31 +++ src/controllers/v4/gifs/randomKick.js | 31 +++ src/controllers/v4/gifs/randomKill.js | 31 +++ src/controllers/v4/gifs/randomKissu.js | 31 +++ src/controllers/v4/gifs/randomLaugh.js | 31 +++ src/controllers/v4/gifs/randomLick.js | 31 +++ src/controllers/v4/gifs/randomLove.js | 31 +++ src/controllers/v4/gifs/randomLurk.js | 31 +++ src/controllers/v4/gifs/randomMidfing.js | 31 +++ src/controllers/v4/gifs/randomNervous.js | 31 +++ src/controllers/v4/gifs/randomNom.js | 31 +++ src/controllers/v4/gifs/randomNope.js | 31 +++ src/controllers/v4/gifs/randomNuzzle.js | 31 +++ src/controllers/v4/gifs/randomPanic.js | 31 +++ src/controllers/v4/gifs/randomPat.js | 31 +++ src/controllers/v4/gifs/randomPeck.js | 31 +++ src/controllers/v4/gifs/randomPoke.js | 31 +++ src/controllers/v4/gifs/randomPout.js | 31 +++ src/controllers/v4/gifs/randomPunch.js | 31 +++ src/controllers/v4/gifs/randomRun.js | 31 +++ src/controllers/v4/gifs/randomSad.js | 31 +++ src/controllers/v4/gifs/randomShoot.js | 31 +++ src/controllers/v4/gifs/randomShrug.js | 31 +++ src/controllers/v4/gifs/randomSip.js | 31 +++ src/controllers/v4/gifs/randomSlap.js | 31 +++ src/controllers/v4/gifs/randomSleepy.js | 31 +++ src/controllers/v4/gifs/randomSmile.js | 31 +++ src/controllers/v4/gifs/randomSmug.js | 31 +++ src/controllers/v4/gifs/randomStab.js | 31 +++ src/controllers/v4/gifs/randomStare.js | 31 +++ src/controllers/v4/gifs/randomSuicide.js | 31 +++ src/controllers/v4/gifs/randomTease.js | 31 +++ src/controllers/v4/gifs/randomThink.js | 31 +++ src/controllers/v4/gifs/randomThumbsup.js | 31 +++ src/controllers/v4/gifs/randomTickle.js | 31 +++ src/controllers/v4/gifs/randomTriggered.js | 31 +++ src/controllers/v4/gifs/randomWag.js | 31 +++ src/controllers/v4/gifs/randomWave.js | 31 +++ src/controllers/v4/gifs/randomWink.js | 31 +++ src/controllers/v4/gifs/randomYes.js | 31 +++ src/controllers/v4/quotes/randomQuotes.js | 49 ++++ src/controllers/{ => v4}/utils/listTags.js | 6 +- src/controllers/v4/utils/owoify.js | 41 ++++ src/controllers/v4/utils/randomPassword.js | 44 ++++ src/controllers/{ => v4}/utils/user.js | 4 +- src/controllers/v4/utils/uvuify.js | 30 +++ src/controllers/v4/utils/uwuify.js | 30 +++ src/controllers/v4/waifus/randomWaifus.js | 28 +++ .../authorize.js} | 17 +- .../errors/index.js => middlewares/errors.js} | 6 +- .../logger/ip.js => middlewares/logger.js} | 2 +- src/{handlers => middlewares}/rateLimit.js | 2 +- src/models/schemas/{Facts.js => Fact.js} | 0 src/models/schemas/{Users.js => User.js} | 4 +- src/models/schemas/Yesh.js | 2 +- src/modules/config/config.js | 50 ++++ src/modules/database/add.js | 34 +++ src/modules/database/delete.js | 34 +++ src/modules/database/update.js | 42 ++++ src/{utils => modules}/generateToken.js | 0 src/{utils => modules}/lengthFilter.js | 0 src/{utils => modules}/parseOrder.js | 0 src/{utils => modules}/tagsFilter.js | 0 src/routes.js | 223 ------------------ src/routes/v3/index.js | 223 ++++++++++++++++++ src/routes/v4/index.js | 11 + src/routes/v4/textUtilities/facts.js | 45 ++++ 165 files changed, 3008 insertions(+), 382 deletions(-) create mode 100644 src/controllers/v3/facts/randomFacts.js rename src/controllers/{ => v3}/gifs/randomAngry.js (86%) rename src/controllers/{ => v3}/gifs/randomBaka.js (86%) rename src/controllers/{ => v3}/gifs/randomBite.js (86%) rename src/controllers/{ => v3}/gifs/randomBlush.js (86%) rename src/controllers/{ => v3}/gifs/randomBonk.js (86%) rename src/controllers/{ => v3}/gifs/randomBored.js (86%) rename src/controllers/{ => v3}/gifs/randomBully.js (86%) rename src/controllers/{ => v3}/gifs/randomBye.js (87%) rename src/controllers/{ => v3}/gifs/randomChase.js (86%) rename src/controllers/{ => v3}/gifs/randomCheer.js (86%) rename src/controllers/{ => v3}/gifs/randomCringe.js (86%) rename src/controllers/{ => v3}/gifs/randomCry.js (87%) rename src/controllers/{ => v3}/gifs/randomCuddle.js (86%) rename src/controllers/{ => v3}/gifs/randomDab.js (87%) rename src/controllers/{ => v3}/gifs/randomDance.js (86%) rename src/controllers/{ => v3}/gifs/randomDie.js (87%) rename src/controllers/{ => v3}/gifs/randomDisgust.js (86%) rename src/controllers/{ => v3}/gifs/randomFacepalm.js (86%) rename src/controllers/{ => v3}/gifs/randomFeed.js (86%) rename src/controllers/{ => v3}/gifs/randomGlomp.js (86%) rename src/controllers/{ => v3}/gifs/randomHappy.js (86%) rename src/controllers/{ => v3}/gifs/randomHi.js (87%) rename src/controllers/{ => v3}/gifs/randomHighfive.js (86%) rename src/controllers/{ => v3}/gifs/randomHold.js (86%) rename src/controllers/{ => v3}/gifs/randomHug.js (87%) rename src/controllers/{ => v3}/gifs/randomKick.js (86%) rename src/controllers/{ => v3}/gifs/randomKill.js (86%) rename src/controllers/{ => v3}/gifs/randomKissu.js (86%) rename src/controllers/{ => v3}/gifs/randomLaugh.js (86%) rename src/controllers/{ => v3}/gifs/randomLick.js (86%) rename src/controllers/{ => v3}/gifs/randomLove.js (86%) rename src/controllers/{ => v3}/gifs/randomLurk.js (86%) rename src/controllers/{ => v3}/gifs/randomMidfing.js (86%) rename src/controllers/{ => v3}/gifs/randomNervous.js (86%) rename src/controllers/{ => v3}/gifs/randomNom.js (87%) rename src/controllers/{ => v3}/gifs/randomNope.js (86%) rename src/controllers/{ => v3}/gifs/randomNuzzle.js (86%) rename src/controllers/{ => v3}/gifs/randomPanic.js (86%) rename src/controllers/{ => v3}/gifs/randomPat.js (87%) rename src/controllers/{ => v3}/gifs/randomPeck.js (86%) rename src/controllers/{ => v3}/gifs/randomPoke.js (86%) rename src/controllers/{ => v3}/gifs/randomPout.js (86%) rename src/controllers/{ => v3}/gifs/randomPunch.js (86%) rename src/controllers/{ => v3}/gifs/randomRun.js (87%) rename src/controllers/{ => v3}/gifs/randomSad.js (87%) rename src/controllers/{ => v3}/gifs/randomShoot.js (86%) rename src/controllers/{ => v3}/gifs/randomShrug.js (86%) rename src/controllers/{ => v3}/gifs/randomSip.js (87%) rename src/controllers/{ => v3}/gifs/randomSlap.js (86%) rename src/controllers/{ => v3}/gifs/randomSleepy.js (86%) rename src/controllers/{ => v3}/gifs/randomSmile.js (86%) rename src/controllers/{ => v3}/gifs/randomSmug.js (86%) rename src/controllers/{ => v3}/gifs/randomStab.js (86%) rename src/controllers/{ => v3}/gifs/randomStare.js (86%) rename src/controllers/{ => v3}/gifs/randomSuicide.js (86%) rename src/controllers/{ => v3}/gifs/randomTease.js (86%) rename src/controllers/{ => v3}/gifs/randomThink.js (86%) rename src/controllers/{ => v3}/gifs/randomThumbsup.js (86%) rename src/controllers/{ => v3}/gifs/randomTickle.js (86%) rename src/controllers/{ => v3}/gifs/randomTriggered.js (86%) rename src/controllers/{ => v3}/gifs/randomWag.js (87%) rename src/controllers/{ => v3}/gifs/randomWave.js (86%) rename src/controllers/{ => v3}/gifs/randomWink.js (86%) rename src/controllers/{ => v3}/gifs/randomYes.js (86%) rename src/controllers/{ => v3}/quotes/randomQuotes.js (93%) create mode 100644 src/controllers/v3/utils/listTags.js rename src/controllers/{ => v3}/utils/owoify.js (95%) rename src/controllers/{ => v3}/utils/randomPassword.js (95%) create mode 100644 src/controllers/v3/utils/user.js rename src/controllers/{ => v3}/utils/uvuify.js (91%) rename src/controllers/{ => v3}/utils/uwuify.js (91%) rename src/controllers/{ => v3}/waifus/randomWaifus.js (84%) rename src/controllers/{ => v4}/facts/randomFacts.js (88%) create mode 100644 src/controllers/v4/gifs/randomAngry.js create mode 100644 src/controllers/v4/gifs/randomBaka.js create mode 100644 src/controllers/v4/gifs/randomBite.js create mode 100644 src/controllers/v4/gifs/randomBlush.js create mode 100644 src/controllers/v4/gifs/randomBonk.js create mode 100644 src/controllers/v4/gifs/randomBored.js create mode 100644 src/controllers/v4/gifs/randomBully.js create mode 100644 src/controllers/v4/gifs/randomBye.js create mode 100644 src/controllers/v4/gifs/randomChase.js create mode 100644 src/controllers/v4/gifs/randomCheer.js create mode 100644 src/controllers/v4/gifs/randomCringe.js create mode 100644 src/controllers/v4/gifs/randomCry.js create mode 100644 src/controllers/v4/gifs/randomCuddle.js create mode 100644 src/controllers/v4/gifs/randomDab.js create mode 100644 src/controllers/v4/gifs/randomDance.js create mode 100644 src/controllers/v4/gifs/randomDie.js create mode 100644 src/controllers/v4/gifs/randomDisgust.js create mode 100644 src/controllers/v4/gifs/randomFacepalm.js create mode 100644 src/controllers/v4/gifs/randomFeed.js create mode 100644 src/controllers/v4/gifs/randomGlomp.js create mode 100644 src/controllers/v4/gifs/randomHappy.js create mode 100644 src/controllers/v4/gifs/randomHi.js create mode 100644 src/controllers/v4/gifs/randomHighfive.js create mode 100644 src/controllers/v4/gifs/randomHold.js create mode 100644 src/controllers/v4/gifs/randomHug.js create mode 100644 src/controllers/v4/gifs/randomKick.js create mode 100644 src/controllers/v4/gifs/randomKill.js create mode 100644 src/controllers/v4/gifs/randomKissu.js create mode 100644 src/controllers/v4/gifs/randomLaugh.js create mode 100644 src/controllers/v4/gifs/randomLick.js create mode 100644 src/controllers/v4/gifs/randomLove.js create mode 100644 src/controllers/v4/gifs/randomLurk.js create mode 100644 src/controllers/v4/gifs/randomMidfing.js create mode 100644 src/controllers/v4/gifs/randomNervous.js create mode 100644 src/controllers/v4/gifs/randomNom.js create mode 100644 src/controllers/v4/gifs/randomNope.js create mode 100644 src/controllers/v4/gifs/randomNuzzle.js create mode 100644 src/controllers/v4/gifs/randomPanic.js create mode 100644 src/controllers/v4/gifs/randomPat.js create mode 100644 src/controllers/v4/gifs/randomPeck.js create mode 100644 src/controllers/v4/gifs/randomPoke.js create mode 100644 src/controllers/v4/gifs/randomPout.js create mode 100644 src/controllers/v4/gifs/randomPunch.js create mode 100644 src/controllers/v4/gifs/randomRun.js create mode 100644 src/controllers/v4/gifs/randomSad.js create mode 100644 src/controllers/v4/gifs/randomShoot.js create mode 100644 src/controllers/v4/gifs/randomShrug.js create mode 100644 src/controllers/v4/gifs/randomSip.js create mode 100644 src/controllers/v4/gifs/randomSlap.js create mode 100644 src/controllers/v4/gifs/randomSleepy.js create mode 100644 src/controllers/v4/gifs/randomSmile.js create mode 100644 src/controllers/v4/gifs/randomSmug.js create mode 100644 src/controllers/v4/gifs/randomStab.js create mode 100644 src/controllers/v4/gifs/randomStare.js create mode 100644 src/controllers/v4/gifs/randomSuicide.js create mode 100644 src/controllers/v4/gifs/randomTease.js create mode 100644 src/controllers/v4/gifs/randomThink.js create mode 100644 src/controllers/v4/gifs/randomThumbsup.js create mode 100644 src/controllers/v4/gifs/randomTickle.js create mode 100644 src/controllers/v4/gifs/randomTriggered.js create mode 100644 src/controllers/v4/gifs/randomWag.js create mode 100644 src/controllers/v4/gifs/randomWave.js create mode 100644 src/controllers/v4/gifs/randomWink.js create mode 100644 src/controllers/v4/gifs/randomYes.js create mode 100644 src/controllers/v4/quotes/randomQuotes.js rename src/controllers/{ => v4}/utils/listTags.js (90%) create mode 100644 src/controllers/v4/utils/owoify.js create mode 100644 src/controllers/v4/utils/randomPassword.js rename src/controllers/{ => v4}/utils/user.js (95%) create mode 100644 src/controllers/v4/utils/uvuify.js create mode 100644 src/controllers/v4/utils/uwuify.js create mode 100644 src/controllers/v4/waifus/randomWaifus.js rename src/{handlers/handleAuthentication.js => middlewares/authorize.js} (82%) rename src/{handlers/errors/index.js => middlewares/errors.js} (76%) rename src/{handlers/logger/ip.js => middlewares/logger.js} (93%) rename src/{handlers => middlewares}/rateLimit.js (95%) rename src/models/schemas/{Facts.js => Fact.js} (100%) rename src/models/schemas/{Users.js => User.js} (86%) create mode 100644 src/modules/config/config.js create mode 100644 src/modules/database/add.js create mode 100644 src/modules/database/delete.js create mode 100644 src/modules/database/update.js rename src/{utils => modules}/generateToken.js (100%) rename src/{utils => modules}/lengthFilter.js (100%) rename src/{utils => modules}/parseOrder.js (100%) rename src/{utils => modules}/tagsFilter.js (100%) delete mode 100644 src/routes.js create mode 100644 src/routes/v3/index.js create mode 100644 src/routes/v4/index.js create mode 100644 src/routes/v4/textUtilities/facts.js diff --git a/src/controllers/v3/facts/randomFacts.js b/src/controllers/v3/facts/randomFacts.js new file mode 100644 index 0000000..b64a767 --- /dev/null +++ b/src/controllers/v3/facts/randomFacts.js @@ -0,0 +1,58 @@ +import createError from 'http-errors'; +import Facts from '../../../models/schemas/Fact.js'; +import tagsFilter from '../../../modules/tagsFilter.js'; +import lengthFilter from '../../../modules/lengthFilter.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets a random anime fact with optional length and tags filters and updates system statistics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getRandomFact = async (req, res, next) => { + try { + const { minLength, maxLength, tags } = req.query; + + // Create a filter object based on the optional length and tags parameters + const filter = {}; + + // Apply length filter (if minLength or maxLength is provided) + if (minLength || maxLength) { + filter.length = lengthFilter(minLength, maxLength); + } + + // Apply tags filter (if tags are provided) + if (tags) { + filter.tags = tagsFilter(tags); + } + + // Aggregate to match the filter, select a random fact, and project excluding version field + const [result] = await Facts.aggregate([ + { $match: filter }, // Apply filters (if any) + { $sample: { size: 1 } }, // Select a random document from the results + { $project: { __v: 0 } }, + ]); + + // If no fact is found, return a 404 error + if (!result) { + return next(createError(404, 'Could not find any matching fact')); + } + + // Respond with the random fact + res.status(200).json(result); + + // Update system statistics for facts + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { facts: 1 } }); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomFact; \ No newline at end of file diff --git a/src/controllers/gifs/randomAngry.js b/src/controllers/v3/gifs/randomAngry.js similarity index 86% rename from src/controllers/gifs/randomAngry.js rename to src/controllers/v3/gifs/randomAngry.js index 9d9bd1f..6156cb9 100644 --- a/src/controllers/gifs/randomAngry.js +++ b/src/controllers/v3/gifs/randomAngry.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Angry from '../../models/schemas/Angry.js'; -import Stats from '../../models/schemas/Stat.js'; +import Angry from '../../../models/schemas/Angry.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Angry const getRandomAngry = async (req, res, next) => { diff --git a/src/controllers/gifs/randomBaka.js b/src/controllers/v3/gifs/randomBaka.js similarity index 86% rename from src/controllers/gifs/randomBaka.js rename to src/controllers/v3/gifs/randomBaka.js index e09b778..746b3b6 100644 --- a/src/controllers/gifs/randomBaka.js +++ b/src/controllers/v3/gifs/randomBaka.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Baka from '../../models/schemas/Baka.js'; -import Stats from '../../models/schemas/Stat.js'; +import Baka from '../../../models/schemas/Baka.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Baka const getRandomBaka = async (req, res, next) => { diff --git a/src/controllers/gifs/randomBite.js b/src/controllers/v3/gifs/randomBite.js similarity index 86% rename from src/controllers/gifs/randomBite.js rename to src/controllers/v3/gifs/randomBite.js index 1be27f3..ddf9bf1 100644 --- a/src/controllers/gifs/randomBite.js +++ b/src/controllers/v3/gifs/randomBite.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Bite from '../../models/schemas/Bite.js'; -import Stats from '../../models/schemas/Stat.js'; +import Bite from '../../../models/schemas/Bite.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bite const getRandomBite = async (req, res, next) => { diff --git a/src/controllers/gifs/randomBlush.js b/src/controllers/v3/gifs/randomBlush.js similarity index 86% rename from src/controllers/gifs/randomBlush.js rename to src/controllers/v3/gifs/randomBlush.js index 1525a41..1a90820 100644 --- a/src/controllers/gifs/randomBlush.js +++ b/src/controllers/v3/gifs/randomBlush.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Blush from '../../models/schemas/Blush.js'; -import Stats from '../../models/schemas/Stat.js'; +import Blush from '../../../models/schemas/Blush.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Blush const getRandomBlush = async (req, res, next) => { diff --git a/src/controllers/gifs/randomBonk.js b/src/controllers/v3/gifs/randomBonk.js similarity index 86% rename from src/controllers/gifs/randomBonk.js rename to src/controllers/v3/gifs/randomBonk.js index 61509da..c559823 100644 --- a/src/controllers/gifs/randomBonk.js +++ b/src/controllers/v3/gifs/randomBonk.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Bonk from '../../models/schemas/Bonk.js'; -import Stats from '../../models/schemas/Stat.js'; +import Bonk from '../../../models/schemas/Bonk.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bonk const getRandomBonk = async (req, res, next) => { diff --git a/src/controllers/gifs/randomBored.js b/src/controllers/v3/gifs/randomBored.js similarity index 86% rename from src/controllers/gifs/randomBored.js rename to src/controllers/v3/gifs/randomBored.js index 3cf093a..2caedfb 100644 --- a/src/controllers/gifs/randomBored.js +++ b/src/controllers/v3/gifs/randomBored.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Bored from '../../models/schemas/Bored.js'; -import Stats from '../../models/schemas/Stat.js'; +import Bored from '../../../models/schemas/Bored.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bored const getRandomBored = async (req, res, next) => { diff --git a/src/controllers/gifs/randomBully.js b/src/controllers/v3/gifs/randomBully.js similarity index 86% rename from src/controllers/gifs/randomBully.js rename to src/controllers/v3/gifs/randomBully.js index 38fac4d..ede6578 100644 --- a/src/controllers/gifs/randomBully.js +++ b/src/controllers/v3/gifs/randomBully.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Bully from '../../models/schemas/Bully.js'; -import Stats from '../../models/schemas/Stat.js'; +import Bully from '../../../models/schemas/Bully.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bully const getRandomBully = async (req, res, next) => { diff --git a/src/controllers/gifs/randomBye.js b/src/controllers/v3/gifs/randomBye.js similarity index 87% rename from src/controllers/gifs/randomBye.js rename to src/controllers/v3/gifs/randomBye.js index 9087e7b..873468b 100644 --- a/src/controllers/gifs/randomBye.js +++ b/src/controllers/v3/gifs/randomBye.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Bye from '../../models/schemas/Bye.js'; -import Stats from '../../models/schemas/Stat.js'; +import Bye from '../../../models/schemas/Bye.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Bye const getRandomBye = async (req, res, next) => { diff --git a/src/controllers/gifs/randomChase.js b/src/controllers/v3/gifs/randomChase.js similarity index 86% rename from src/controllers/gifs/randomChase.js rename to src/controllers/v3/gifs/randomChase.js index 75a2aa4..a16f38b 100644 --- a/src/controllers/gifs/randomChase.js +++ b/src/controllers/v3/gifs/randomChase.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Chase from '../../models/schemas/Chase.js'; -import Stats from '../../models/schemas/Stat.js'; +import Chase from '../../../models/schemas/Chase.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Chase const getRandomChase = async (req, res, next) => { diff --git a/src/controllers/gifs/randomCheer.js b/src/controllers/v3/gifs/randomCheer.js similarity index 86% rename from src/controllers/gifs/randomCheer.js rename to src/controllers/v3/gifs/randomCheer.js index 3aed3ff..21447b8 100644 --- a/src/controllers/gifs/randomCheer.js +++ b/src/controllers/v3/gifs/randomCheer.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Cheer from '../../models/schemas/Cheer.js'; -import Stats from '../../models/schemas/Stat.js'; +import Cheer from '../../../models/schemas/Cheer.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Cheer const getRandomCheer = async (req, res, next) => { diff --git a/src/controllers/gifs/randomCringe.js b/src/controllers/v3/gifs/randomCringe.js similarity index 86% rename from src/controllers/gifs/randomCringe.js rename to src/controllers/v3/gifs/randomCringe.js index 3f6009e..3551842 100644 --- a/src/controllers/gifs/randomCringe.js +++ b/src/controllers/v3/gifs/randomCringe.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Cringe from '../../models/schemas/Cringe.js'; -import Stats from '../../models/schemas/Stat.js'; +import Cringe from '../../../models/schemas/Cringe.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Cringe const getRandomCringe = async (req, res, next) => { diff --git a/src/controllers/gifs/randomCry.js b/src/controllers/v3/gifs/randomCry.js similarity index 87% rename from src/controllers/gifs/randomCry.js rename to src/controllers/v3/gifs/randomCry.js index c259c71..80d80e5 100644 --- a/src/controllers/gifs/randomCry.js +++ b/src/controllers/v3/gifs/randomCry.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Cry from '../../models/schemas/Cry.js'; -import Stats from '../../models/schemas/Stat.js'; +import Cry from '../../../models/schemas/Cry.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Cry const getRandomCry = async (req, res, next) => { diff --git a/src/controllers/gifs/randomCuddle.js b/src/controllers/v3/gifs/randomCuddle.js similarity index 86% rename from src/controllers/gifs/randomCuddle.js rename to src/controllers/v3/gifs/randomCuddle.js index 7c7035e..f5f5314 100644 --- a/src/controllers/gifs/randomCuddle.js +++ b/src/controllers/v3/gifs/randomCuddle.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Cuddle from '../../models/schemas/Cuddle.js'; -import Stats from '../../models/schemas/Stat.js'; +import Cuddle from '../../../models/schemas/Cuddle.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Cuddle const getRandomCuddle = async (req, res, next) => { diff --git a/src/controllers/gifs/randomDab.js b/src/controllers/v3/gifs/randomDab.js similarity index 87% rename from src/controllers/gifs/randomDab.js rename to src/controllers/v3/gifs/randomDab.js index 3ce2df2..d95f2df 100644 --- a/src/controllers/gifs/randomDab.js +++ b/src/controllers/v3/gifs/randomDab.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Dab from '../../models/schemas/Dab.js'; -import Stats from '../../models/schemas/Stat.js'; +import Dab from '../../../models/schemas/Dab.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Dab const getRandomDab = async (req, res, next) => { diff --git a/src/controllers/gifs/randomDance.js b/src/controllers/v3/gifs/randomDance.js similarity index 86% rename from src/controllers/gifs/randomDance.js rename to src/controllers/v3/gifs/randomDance.js index 0ac4d11..922e5e3 100644 --- a/src/controllers/gifs/randomDance.js +++ b/src/controllers/v3/gifs/randomDance.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Dance from '../../models/schemas/Dance.js'; -import Stats from '../../models/schemas/Stat.js'; +import Dance from '../../../models/schemas/Dance.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Dance const getRandomDance = async (req, res, next) => { diff --git a/src/controllers/gifs/randomDie.js b/src/controllers/v3/gifs/randomDie.js similarity index 87% rename from src/controllers/gifs/randomDie.js rename to src/controllers/v3/gifs/randomDie.js index 0b3a7e7..da8936c 100644 --- a/src/controllers/gifs/randomDie.js +++ b/src/controllers/v3/gifs/randomDie.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Die from '../../models/schemas/Die.js'; -import Stats from '../../models/schemas/Stat.js'; +import Die from '../../../models/schemas/Die.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Die const getRandomDie = async (req, res, next) => { diff --git a/src/controllers/gifs/randomDisgust.js b/src/controllers/v3/gifs/randomDisgust.js similarity index 86% rename from src/controllers/gifs/randomDisgust.js rename to src/controllers/v3/gifs/randomDisgust.js index ecdfeaa..f52edbe 100644 --- a/src/controllers/gifs/randomDisgust.js +++ b/src/controllers/v3/gifs/randomDisgust.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Disgust from '../../models/schemas/Disgust.js'; -import Stats from '../../models/schemas/Stat.js'; +import Disgust from '../../../models/schemas/Disgust.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Disgust const getRandomDisgust = async (req, res, next) => { diff --git a/src/controllers/gifs/randomFacepalm.js b/src/controllers/v3/gifs/randomFacepalm.js similarity index 86% rename from src/controllers/gifs/randomFacepalm.js rename to src/controllers/v3/gifs/randomFacepalm.js index 50a1efe..4d1751b 100644 --- a/src/controllers/gifs/randomFacepalm.js +++ b/src/controllers/v3/gifs/randomFacepalm.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Facepalm from '../../models/schemas/Facepalm.js'; -import Stats from '../../models/schemas/Stat.js'; +import Facepalm from '../../../models/schemas/Facepalm.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Facepalm const getRandomFacepalm = async (req, res, next) => { diff --git a/src/controllers/gifs/randomFeed.js b/src/controllers/v3/gifs/randomFeed.js similarity index 86% rename from src/controllers/gifs/randomFeed.js rename to src/controllers/v3/gifs/randomFeed.js index 3c74951..930e163 100644 --- a/src/controllers/gifs/randomFeed.js +++ b/src/controllers/v3/gifs/randomFeed.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Feed from '../../models/schemas/Feed.js'; -import Stats from '../../models/schemas/Stat.js'; +import Feed from '../../../models/schemas/Feed.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Feed const getRandomFeed = async (req, res, next) => { diff --git a/src/controllers/gifs/randomGlomp.js b/src/controllers/v3/gifs/randomGlomp.js similarity index 86% rename from src/controllers/gifs/randomGlomp.js rename to src/controllers/v3/gifs/randomGlomp.js index 5d1e43c..2fd4029 100644 --- a/src/controllers/gifs/randomGlomp.js +++ b/src/controllers/v3/gifs/randomGlomp.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Glomp from '../../models/schemas/Glomp.js'; -import Stats from '../../models/schemas/Stat.js'; +import Glomp from '../../../models/schemas/Glomp.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Glomp const getRandomGlomp = async (req, res, next) => { diff --git a/src/controllers/gifs/randomHappy.js b/src/controllers/v3/gifs/randomHappy.js similarity index 86% rename from src/controllers/gifs/randomHappy.js rename to src/controllers/v3/gifs/randomHappy.js index 22bff31..59de724 100644 --- a/src/controllers/gifs/randomHappy.js +++ b/src/controllers/v3/gifs/randomHappy.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Happy from '../../models/schemas/Happy.js'; -import Stats from '../../models/schemas/Stat.js'; +import Happy from '../../../models/schemas/Happy.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Happy const getRandomHappy = async (req, res, next) => { diff --git a/src/controllers/gifs/randomHi.js b/src/controllers/v3/gifs/randomHi.js similarity index 87% rename from src/controllers/gifs/randomHi.js rename to src/controllers/v3/gifs/randomHi.js index d56e856..d2614d7 100644 --- a/src/controllers/gifs/randomHi.js +++ b/src/controllers/v3/gifs/randomHi.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Hi from '../../models/schemas/Hi.js'; -import Stats from '../../models/schemas/Stat.js'; +import Hi from '../../../models/schemas/Hi.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Hi const getRandomHi = async (req, res, next) => { diff --git a/src/controllers/gifs/randomHighfive.js b/src/controllers/v3/gifs/randomHighfive.js similarity index 86% rename from src/controllers/gifs/randomHighfive.js rename to src/controllers/v3/gifs/randomHighfive.js index c94a980..c290116 100644 --- a/src/controllers/gifs/randomHighfive.js +++ b/src/controllers/v3/gifs/randomHighfive.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Highfive from '../../models/schemas/Highfive.js'; -import Stats from '../../models/schemas/Stat.js'; +import Highfive from '../../../models/schemas/Highfive.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Highfive const getRandomHighfive = async (req, res, next) => { diff --git a/src/controllers/gifs/randomHold.js b/src/controllers/v3/gifs/randomHold.js similarity index 86% rename from src/controllers/gifs/randomHold.js rename to src/controllers/v3/gifs/randomHold.js index eb47464..9640b64 100644 --- a/src/controllers/gifs/randomHold.js +++ b/src/controllers/v3/gifs/randomHold.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Hold from '../../models/schemas/Hold.js'; -import Stats from '../../models/schemas/Stat.js'; +import Hold from '../../../models/schemas/Hold.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Hold const getRandomHold = async (req, res, next) => { diff --git a/src/controllers/gifs/randomHug.js b/src/controllers/v3/gifs/randomHug.js similarity index 87% rename from src/controllers/gifs/randomHug.js rename to src/controllers/v3/gifs/randomHug.js index 317e0fe..8d3432f 100644 --- a/src/controllers/gifs/randomHug.js +++ b/src/controllers/v3/gifs/randomHug.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Hug from '../../models/schemas/Hug.js'; -import Stats from '../../models/schemas/Stat.js'; +import Hug from '../../../models/schemas/Hug.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Hug const getRandomHug = async (req, res, next) => { diff --git a/src/controllers/gifs/randomKick.js b/src/controllers/v3/gifs/randomKick.js similarity index 86% rename from src/controllers/gifs/randomKick.js rename to src/controllers/v3/gifs/randomKick.js index fb79661..b24d888 100644 --- a/src/controllers/gifs/randomKick.js +++ b/src/controllers/v3/gifs/randomKick.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Kick from '../../models/schemas/Kick.js'; -import Stats from '../../models/schemas/Stat.js'; +import Kick from '../../../models/schemas/Kick.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Kick const getRandomKick = async (req, res, next) => { diff --git a/src/controllers/gifs/randomKill.js b/src/controllers/v3/gifs/randomKill.js similarity index 86% rename from src/controllers/gifs/randomKill.js rename to src/controllers/v3/gifs/randomKill.js index a017684..7186102 100644 --- a/src/controllers/gifs/randomKill.js +++ b/src/controllers/v3/gifs/randomKill.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Kill from '../../models/schemas/Kill.js'; -import Stats from '../../models/schemas/Stat.js'; +import Kill from '../../../models/schemas/Kill.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Kill const getRandomKill = async (req, res, next) => { diff --git a/src/controllers/gifs/randomKissu.js b/src/controllers/v3/gifs/randomKissu.js similarity index 86% rename from src/controllers/gifs/randomKissu.js rename to src/controllers/v3/gifs/randomKissu.js index b40508c..a13ce66 100644 --- a/src/controllers/gifs/randomKissu.js +++ b/src/controllers/v3/gifs/randomKissu.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Kissu from '../../models/schemas/Kissu.js'; -import Stats from '../../models/schemas/Stat.js'; +import Kissu from '../../../models/schemas/Kissu.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Kissu const getRandomKissu = async (req, res, next) => { diff --git a/src/controllers/gifs/randomLaugh.js b/src/controllers/v3/gifs/randomLaugh.js similarity index 86% rename from src/controllers/gifs/randomLaugh.js rename to src/controllers/v3/gifs/randomLaugh.js index 20b03e9..7450f79 100644 --- a/src/controllers/gifs/randomLaugh.js +++ b/src/controllers/v3/gifs/randomLaugh.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Laugh from '../../models/schemas/Laugh.js'; -import Stats from '../../models/schemas/Stat.js'; +import Laugh from '../../../models/schemas/Laugh.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Laugh const getRandomLaugh = async (req, res, next) => { diff --git a/src/controllers/gifs/randomLick.js b/src/controllers/v3/gifs/randomLick.js similarity index 86% rename from src/controllers/gifs/randomLick.js rename to src/controllers/v3/gifs/randomLick.js index 1df6133..df87eb8 100644 --- a/src/controllers/gifs/randomLick.js +++ b/src/controllers/v3/gifs/randomLick.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Lick from '../../models/schemas/Lick.js'; -import Stats from '../../models/schemas/Stat.js'; +import Lick from '../../../models/schemas/Lick.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Lick const getRandomLick = async (req, res, next) => { diff --git a/src/controllers/gifs/randomLove.js b/src/controllers/v3/gifs/randomLove.js similarity index 86% rename from src/controllers/gifs/randomLove.js rename to src/controllers/v3/gifs/randomLove.js index f4b5f66..a0699e5 100644 --- a/src/controllers/gifs/randomLove.js +++ b/src/controllers/v3/gifs/randomLove.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Love from '../../models/schemas/Love.js'; -import Stats from '../../models/schemas/Stat.js'; +import Love from '../../../models/schemas/Love.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Love const getRandomLove = async (req, res, next) => { diff --git a/src/controllers/gifs/randomLurk.js b/src/controllers/v3/gifs/randomLurk.js similarity index 86% rename from src/controllers/gifs/randomLurk.js rename to src/controllers/v3/gifs/randomLurk.js index d5c1146..74e36f7 100644 --- a/src/controllers/gifs/randomLurk.js +++ b/src/controllers/v3/gifs/randomLurk.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Lurk from '../../models/schemas/Lurk.js'; -import Stats from '../../models/schemas/Stat.js'; +import Lurk from '../../../models/schemas/Lurk.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Lurk const getRandomLurk = async (req, res, next) => { diff --git a/src/controllers/gifs/randomMidfing.js b/src/controllers/v3/gifs/randomMidfing.js similarity index 86% rename from src/controllers/gifs/randomMidfing.js rename to src/controllers/v3/gifs/randomMidfing.js index c14d719..6290752 100644 --- a/src/controllers/gifs/randomMidfing.js +++ b/src/controllers/v3/gifs/randomMidfing.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Midfing from '../../models/schemas/Midfing.js'; -import Stats from '../../models/schemas/Stat.js'; +import Midfing from '../../../models/schemas/Midfing.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Midfing const getRandomMidfing = async (req, res, next) => { diff --git a/src/controllers/gifs/randomNervous.js b/src/controllers/v3/gifs/randomNervous.js similarity index 86% rename from src/controllers/gifs/randomNervous.js rename to src/controllers/v3/gifs/randomNervous.js index d461f7d..5a2616b 100644 --- a/src/controllers/gifs/randomNervous.js +++ b/src/controllers/v3/gifs/randomNervous.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Nervous from '../../models/schemas/Nervous.js'; -import Stats from '../../models/schemas/Stat.js'; +import Nervous from '../../../models/schemas/Nervous.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Nervous const getRandomNervous = async (req, res, next) => { diff --git a/src/controllers/gifs/randomNom.js b/src/controllers/v3/gifs/randomNom.js similarity index 87% rename from src/controllers/gifs/randomNom.js rename to src/controllers/v3/gifs/randomNom.js index 454408f..00f9b20 100644 --- a/src/controllers/gifs/randomNom.js +++ b/src/controllers/v3/gifs/randomNom.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Nom from '../../models/schemas/Nom.js'; -import Stats from '../../models/schemas/Stat.js'; +import Nom from '../../../models/schemas/Nom.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Nom const getRandomNom = async (req, res, next) => { diff --git a/src/controllers/gifs/randomNope.js b/src/controllers/v3/gifs/randomNope.js similarity index 86% rename from src/controllers/gifs/randomNope.js rename to src/controllers/v3/gifs/randomNope.js index 8b451ef..348aa18 100644 --- a/src/controllers/gifs/randomNope.js +++ b/src/controllers/v3/gifs/randomNope.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Nope from '../../models/schemas/Nope.js'; -import Stats from '../../models/schemas/Stat.js'; +import Nope from '../../../models/schemas/Nope.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Nope const getRandomNope = async (req, res, next) => { diff --git a/src/controllers/gifs/randomNuzzle.js b/src/controllers/v3/gifs/randomNuzzle.js similarity index 86% rename from src/controllers/gifs/randomNuzzle.js rename to src/controllers/v3/gifs/randomNuzzle.js index d00db1f..38e1f7b 100644 --- a/src/controllers/gifs/randomNuzzle.js +++ b/src/controllers/v3/gifs/randomNuzzle.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Nuzzle from '../../models/schemas/Nuzzle.js'; -import Stats from '../../models/schemas/Stat.js'; +import Nuzzle from '../../../models/schemas/Nuzzle.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Nuzzle const getRandomNuzzle = async (req, res, next) => { diff --git a/src/controllers/gifs/randomPanic.js b/src/controllers/v3/gifs/randomPanic.js similarity index 86% rename from src/controllers/gifs/randomPanic.js rename to src/controllers/v3/gifs/randomPanic.js index 115942a..abf97e0 100644 --- a/src/controllers/gifs/randomPanic.js +++ b/src/controllers/v3/gifs/randomPanic.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Panic from '../../models/schemas/Panic.js'; -import Stats from '../../models/schemas/Stat.js'; +import Panic from '../../../models/schemas/Panic.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Panic const getRandomPanic = async (req, res, next) => { diff --git a/src/controllers/gifs/randomPat.js b/src/controllers/v3/gifs/randomPat.js similarity index 87% rename from src/controllers/gifs/randomPat.js rename to src/controllers/v3/gifs/randomPat.js index 57c3d2e..bd683d9 100644 --- a/src/controllers/gifs/randomPat.js +++ b/src/controllers/v3/gifs/randomPat.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Pat from '../../models/schemas/Pat.js'; -import Stats from '../../models/schemas/Stat.js'; +import Pat from '../../../models/schemas/Pat.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Pat const getRandomPat = async (req, res, next) => { diff --git a/src/controllers/gifs/randomPeck.js b/src/controllers/v3/gifs/randomPeck.js similarity index 86% rename from src/controllers/gifs/randomPeck.js rename to src/controllers/v3/gifs/randomPeck.js index 40e06aa..fb96e43 100644 --- a/src/controllers/gifs/randomPeck.js +++ b/src/controllers/v3/gifs/randomPeck.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Peck from '../../models/schemas/Peck.js'; -import Stats from '../../models/schemas/Stat.js'; +import Peck from '../../../models/schemas/Peck.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Peck const getRandomPeck = async (req, res, next) => { diff --git a/src/controllers/gifs/randomPoke.js b/src/controllers/v3/gifs/randomPoke.js similarity index 86% rename from src/controllers/gifs/randomPoke.js rename to src/controllers/v3/gifs/randomPoke.js index eeaf1cd..4b2c428 100644 --- a/src/controllers/gifs/randomPoke.js +++ b/src/controllers/v3/gifs/randomPoke.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Poke from '../../models/schemas/Poke.js'; -import Stats from '../../models/schemas/Stat.js'; +import Poke from '../../../models/schemas/Poke.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Poke const getRandomPoke = async (req, res, next) => { diff --git a/src/controllers/gifs/randomPout.js b/src/controllers/v3/gifs/randomPout.js similarity index 86% rename from src/controllers/gifs/randomPout.js rename to src/controllers/v3/gifs/randomPout.js index 162ae2d..dc45330 100644 --- a/src/controllers/gifs/randomPout.js +++ b/src/controllers/v3/gifs/randomPout.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Pout from '../../models/schemas/Pout.js'; -import Stats from '../../models/schemas/Stat.js'; +import Pout from '../../../models/schemas/Pout.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Pout const getRandomPout = async (req, res, next) => { diff --git a/src/controllers/gifs/randomPunch.js b/src/controllers/v3/gifs/randomPunch.js similarity index 86% rename from src/controllers/gifs/randomPunch.js rename to src/controllers/v3/gifs/randomPunch.js index fcb2174..dd35b84 100644 --- a/src/controllers/gifs/randomPunch.js +++ b/src/controllers/v3/gifs/randomPunch.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Punch from '../../models/schemas/Punch.js'; -import Stats from '../../models/schemas/Stat.js'; +import Punch from '../../../models/schemas/Punch.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Punch const getRandomPunch = async (req, res, next) => { diff --git a/src/controllers/gifs/randomRun.js b/src/controllers/v3/gifs/randomRun.js similarity index 87% rename from src/controllers/gifs/randomRun.js rename to src/controllers/v3/gifs/randomRun.js index 2203104..061d36f 100644 --- a/src/controllers/gifs/randomRun.js +++ b/src/controllers/v3/gifs/randomRun.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Run from '../../models/schemas/Run.js'; -import Stats from '../../models/schemas/Stat.js'; +import Run from '../../../models/schemas/Run.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Run const getRandomRun = async (req, res, next) => { diff --git a/src/controllers/gifs/randomSad.js b/src/controllers/v3/gifs/randomSad.js similarity index 87% rename from src/controllers/gifs/randomSad.js rename to src/controllers/v3/gifs/randomSad.js index c23f407..0af254d 100644 --- a/src/controllers/gifs/randomSad.js +++ b/src/controllers/v3/gifs/randomSad.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Sad from '../../models/schemas/Sad.js'; -import Stats from '../../models/schemas/Stat.js'; +import Sad from '../../../models/schemas/Sad.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Sad const getRandomSad = async (req, res, next) => { diff --git a/src/controllers/gifs/randomShoot.js b/src/controllers/v3/gifs/randomShoot.js similarity index 86% rename from src/controllers/gifs/randomShoot.js rename to src/controllers/v3/gifs/randomShoot.js index c41c592..cdc8a1b 100644 --- a/src/controllers/gifs/randomShoot.js +++ b/src/controllers/v3/gifs/randomShoot.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Shoot from '../../models/schemas/Shoot.js'; -import Stats from '../../models/schemas/Stat.js'; +import Shoot from '../../../models/schemas/Shoot.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Shoot const getRandomShoot = async (req, res, next) => { diff --git a/src/controllers/gifs/randomShrug.js b/src/controllers/v3/gifs/randomShrug.js similarity index 86% rename from src/controllers/gifs/randomShrug.js rename to src/controllers/v3/gifs/randomShrug.js index b795f7c..9755221 100644 --- a/src/controllers/gifs/randomShrug.js +++ b/src/controllers/v3/gifs/randomShrug.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Shrug from '../../models/schemas/Shrug.js'; -import Stats from '../../models/schemas/Stat.js'; +import Shrug from '../../../models/schemas/Shrug.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Shrug const getRandomShrug = async (req, res, next) => { diff --git a/src/controllers/gifs/randomSip.js b/src/controllers/v3/gifs/randomSip.js similarity index 87% rename from src/controllers/gifs/randomSip.js rename to src/controllers/v3/gifs/randomSip.js index d2fe08a..37fcea4 100644 --- a/src/controllers/gifs/randomSip.js +++ b/src/controllers/v3/gifs/randomSip.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Sip from '../../models/schemas/Sip.js'; -import Stats from '../../models/schemas/Stat.js'; +import Sip from '../../../models/schemas/Sip.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Sip const getRandomSip = async (req, res, next) => { diff --git a/src/controllers/gifs/randomSlap.js b/src/controllers/v3/gifs/randomSlap.js similarity index 86% rename from src/controllers/gifs/randomSlap.js rename to src/controllers/v3/gifs/randomSlap.js index f118d16..89fb3e5 100644 --- a/src/controllers/gifs/randomSlap.js +++ b/src/controllers/v3/gifs/randomSlap.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Slap from '../../models/schemas/Slap.js'; -import Stats from '../../models/schemas/Stat.js'; +import Slap from '../../../models/schemas/Slap.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Slap const getRandomSlap = async (req, res, next) => { diff --git a/src/controllers/gifs/randomSleepy.js b/src/controllers/v3/gifs/randomSleepy.js similarity index 86% rename from src/controllers/gifs/randomSleepy.js rename to src/controllers/v3/gifs/randomSleepy.js index 8902c72..a408099 100644 --- a/src/controllers/gifs/randomSleepy.js +++ b/src/controllers/v3/gifs/randomSleepy.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Sleepy from '../../models/schemas/Sleepy.js'; -import Stats from '../../models/schemas/Stat.js'; +import Sleepy from '../../../models/schemas/Sleepy.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Sleepy const getRandomSleepy = async (req, res, next) => { diff --git a/src/controllers/gifs/randomSmile.js b/src/controllers/v3/gifs/randomSmile.js similarity index 86% rename from src/controllers/gifs/randomSmile.js rename to src/controllers/v3/gifs/randomSmile.js index 01f289f..54983e2 100644 --- a/src/controllers/gifs/randomSmile.js +++ b/src/controllers/v3/gifs/randomSmile.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Smile from '../../models/schemas/Smile.js'; -import Stats from '../../models/schemas/Stat.js'; +import Smile from '../../../models/schemas/Smile.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Smile const getRandomSmile = async (req, res, next) => { diff --git a/src/controllers/gifs/randomSmug.js b/src/controllers/v3/gifs/randomSmug.js similarity index 86% rename from src/controllers/gifs/randomSmug.js rename to src/controllers/v3/gifs/randomSmug.js index e1ff3d9..8861730 100644 --- a/src/controllers/gifs/randomSmug.js +++ b/src/controllers/v3/gifs/randomSmug.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Smug from '../../models/schemas/Smug.js'; -import Stats from '../../models/schemas/Stat.js'; +import Smug from '../../../models/schemas/Smug.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Smug const getRandomSmug = async (req, res, next) => { diff --git a/src/controllers/gifs/randomStab.js b/src/controllers/v3/gifs/randomStab.js similarity index 86% rename from src/controllers/gifs/randomStab.js rename to src/controllers/v3/gifs/randomStab.js index c97993f..3b0ce94 100644 --- a/src/controllers/gifs/randomStab.js +++ b/src/controllers/v3/gifs/randomStab.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Stab from '../../models/schemas/Stab.js'; -import Stats from '../../models/schemas/Stat.js'; +import Stab from '../../../models/schemas/Stab.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Stab const getRandomStab = async (req, res, next) => { diff --git a/src/controllers/gifs/randomStare.js b/src/controllers/v3/gifs/randomStare.js similarity index 86% rename from src/controllers/gifs/randomStare.js rename to src/controllers/v3/gifs/randomStare.js index 0ef1ab7..b1c2979 100644 --- a/src/controllers/gifs/randomStare.js +++ b/src/controllers/v3/gifs/randomStare.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Stare from '../../models/schemas/Stare.js'; -import Stats from '../../models/schemas/Stat.js'; +import Stare from '../../../models/schemas/Stare.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Stare const getRandomStare = async (req, res, next) => { diff --git a/src/controllers/gifs/randomSuicide.js b/src/controllers/v3/gifs/randomSuicide.js similarity index 86% rename from src/controllers/gifs/randomSuicide.js rename to src/controllers/v3/gifs/randomSuicide.js index 44d7254..f3d355c 100644 --- a/src/controllers/gifs/randomSuicide.js +++ b/src/controllers/v3/gifs/randomSuicide.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Suicide from '../../models/schemas/Suicide.js'; -import Stats from '../../models/schemas/Stat.js'; +import Suicide from '../../../models/schemas/Suicide.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Suicide const getRandomSuicide = async (req, res, next) => { diff --git a/src/controllers/gifs/randomTease.js b/src/controllers/v3/gifs/randomTease.js similarity index 86% rename from src/controllers/gifs/randomTease.js rename to src/controllers/v3/gifs/randomTease.js index 2fcac09..5698856 100644 --- a/src/controllers/gifs/randomTease.js +++ b/src/controllers/v3/gifs/randomTease.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Tease from '../../models/schemas/Tease.js'; -import Stats from '../../models/schemas/Stat.js'; +import Tease from '../../../models/schemas/Tease.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Tease const getRandomTease = async (req, res, next) => { diff --git a/src/controllers/gifs/randomThink.js b/src/controllers/v3/gifs/randomThink.js similarity index 86% rename from src/controllers/gifs/randomThink.js rename to src/controllers/v3/gifs/randomThink.js index 53b937f..0afad57 100644 --- a/src/controllers/gifs/randomThink.js +++ b/src/controllers/v3/gifs/randomThink.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Think from '../../models/schemas/Think.js'; -import Stats from '../../models/schemas/Stat.js'; +import Think from '../../../models/schemas/Think.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Think const getRandomThink = async (req, res, next) => { diff --git a/src/controllers/gifs/randomThumbsup.js b/src/controllers/v3/gifs/randomThumbsup.js similarity index 86% rename from src/controllers/gifs/randomThumbsup.js rename to src/controllers/v3/gifs/randomThumbsup.js index b8ba139..6a2d1bd 100644 --- a/src/controllers/gifs/randomThumbsup.js +++ b/src/controllers/v3/gifs/randomThumbsup.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Thumbsup from '../../models/schemas/Thumbsup.js'; -import Stats from '../../models/schemas/Stat.js'; +import Thumbsup from '../../../models/schemas/Thumbsup.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Thumbsup const getRandomThumbsup = async (req, res, next) => { diff --git a/src/controllers/gifs/randomTickle.js b/src/controllers/v3/gifs/randomTickle.js similarity index 86% rename from src/controllers/gifs/randomTickle.js rename to src/controllers/v3/gifs/randomTickle.js index dfe579f..06e4bd2 100644 --- a/src/controllers/gifs/randomTickle.js +++ b/src/controllers/v3/gifs/randomTickle.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Tickle from '../../models/schemas/Tickle.js'; -import Stats from '../../models/schemas/Stat.js'; +import Tickle from '../../../models/schemas/Tickle.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Tickle const getRandomTickle = async (req, res, next) => { diff --git a/src/controllers/gifs/randomTriggered.js b/src/controllers/v3/gifs/randomTriggered.js similarity index 86% rename from src/controllers/gifs/randomTriggered.js rename to src/controllers/v3/gifs/randomTriggered.js index a3d3579..bfbc35e 100644 --- a/src/controllers/gifs/randomTriggered.js +++ b/src/controllers/v3/gifs/randomTriggered.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Triggered from '../../models/schemas/Triggered.js'; -import Stats from '../../models/schemas/Stat.js'; +import Triggered from '../../../models/schemas/Triggered.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Triggered const getRandomTriggered = async (req, res, next) => { diff --git a/src/controllers/gifs/randomWag.js b/src/controllers/v3/gifs/randomWag.js similarity index 87% rename from src/controllers/gifs/randomWag.js rename to src/controllers/v3/gifs/randomWag.js index 51d0e66..88ad360 100644 --- a/src/controllers/gifs/randomWag.js +++ b/src/controllers/v3/gifs/randomWag.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Wag from '../../models/schemas/Wag.js'; -import Stats from '../../models/schemas/Stat.js'; +import Wag from '../../../models/schemas/Wag.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Wag const getRandomWag = async (req, res, next) => { diff --git a/src/controllers/gifs/randomWave.js b/src/controllers/v3/gifs/randomWave.js similarity index 86% rename from src/controllers/gifs/randomWave.js rename to src/controllers/v3/gifs/randomWave.js index eeb04e2..195dfb1 100644 --- a/src/controllers/gifs/randomWave.js +++ b/src/controllers/v3/gifs/randomWave.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Wave from '../../models/schemas/Wave.js'; -import Stats from '../../models/schemas/Stat.js'; +import Wave from '../../../models/schemas/Wave.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Wave const getRandomWave = async (req, res, next) => { diff --git a/src/controllers/gifs/randomWink.js b/src/controllers/v3/gifs/randomWink.js similarity index 86% rename from src/controllers/gifs/randomWink.js rename to src/controllers/v3/gifs/randomWink.js index 5bde7bc..fb03a57 100644 --- a/src/controllers/gifs/randomWink.js +++ b/src/controllers/v3/gifs/randomWink.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Wink from '../../models/schemas/Wink.js'; -import Stats from '../../models/schemas/Stat.js'; +import Wink from '../../../models/schemas/Wink.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Wink const getRandomWink = async (req, res, next) => { diff --git a/src/controllers/gifs/randomYes.js b/src/controllers/v3/gifs/randomYes.js similarity index 86% rename from src/controllers/gifs/randomYes.js rename to src/controllers/v3/gifs/randomYes.js index 5d73426..1408489 100644 --- a/src/controllers/gifs/randomYes.js +++ b/src/controllers/v3/gifs/randomYes.js @@ -1,7 +1,7 @@ import createError from 'http-errors'; -import Yesh from '../../models/schemas/Yesh.js'; -import Stats from '../../models/schemas/Stat.js'; +import Yesh from '../../../models/schemas/Yesh.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get random Anime Yes const getRandomYes = async (req, res, next) => { diff --git a/src/controllers/quotes/randomQuotes.js b/src/controllers/v3/quotes/randomQuotes.js similarity index 93% rename from src/controllers/quotes/randomQuotes.js rename to src/controllers/v3/quotes/randomQuotes.js index adf068f..76cd20d 100644 --- a/src/controllers/quotes/randomQuotes.js +++ b/src/controllers/v3/quotes/randomQuotes.js @@ -1,6 +1,6 @@ import createError from 'http-errors'; -import Quotes from '../../models/schemas/Quotes.js'; -import Stats from '../../models/schemas/Stat.js'; +import Quotes from '../../../models/schemas/Quotes.js'; +import Stats from '../../../models/schemas/Stat.js'; /** * Gets a random anime quote with optional character filter and updates system statistics. diff --git a/src/controllers/v3/utils/listTags.js b/src/controllers/v3/utils/listTags.js new file mode 100644 index 0000000..f7b15c1 --- /dev/null +++ b/src/controllers/v3/utils/listTags.js @@ -0,0 +1,58 @@ +import Tags from '../../../models/schemas/Tags.js'; +import parseOrder from '../../../modules/parseOrder.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Lists tags with optional sorting and updates system statistics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const listTags = async (req, res, next) => { + try { + let { sortBy, sortOrder } = req.query; + + // Supported parameter values + const Values = { sortBy: ['name', 'usedCount'] }; + // The default sort order depends on the `sortBy` field + const defaultSortOrder = { name: 1, usedCount: -1 }; + + // Validate and set sortBy and sortOrder + sortBy = Values.sortBy.includes(sortBy) ? sortBy : 'name'; + sortOrder = parseOrder(sortOrder) || defaultSortOrder[sortBy] || 1; + + // Aggregate tags, including the count of associated facts, and sort the results + const results = await Tags.aggregate([ + { + $lookup: { + from: 'facts', + localField: 'name', + foreignField: 'tags', + as: 'usedCount', + }, + }, + { $addFields: { usedCount: { $size: '$usedCount' } } }, + { $sort: { [sortBy]: sortOrder } }, + { $project: { __v: 0 } }, + ]); + + // Respond with the sorted tags + res.json(results); + + // Update system statistics for tags + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { tags: 1 } } + ); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default listTags; diff --git a/src/controllers/utils/owoify.js b/src/controllers/v3/utils/owoify.js similarity index 95% rename from src/controllers/utils/owoify.js rename to src/controllers/v3/utils/owoify.js index 74dd638..beb1fa0 100644 --- a/src/controllers/utils/owoify.js +++ b/src/controllers/v3/utils/owoify.js @@ -1,6 +1,6 @@ import createError from 'http-errors'; import owoify from 'owoify-js'; -import Stats from '../../models/schemas/Stat.js'; +import Stats from '../../../models/schemas/Stat.js'; /** * Gets the Owofied version of the provided text and updates system statistics. diff --git a/src/controllers/utils/randomPassword.js b/src/controllers/v3/utils/randomPassword.js similarity index 95% rename from src/controllers/utils/randomPassword.js rename to src/controllers/v3/utils/randomPassword.js index 5d662d0..fe65922 100644 --- a/src/controllers/utils/randomPassword.js +++ b/src/controllers/v3/utils/randomPassword.js @@ -1,5 +1,5 @@ import pass from 'generate-password'; -import Stats from '../../models/schemas/Stat.js'; +import Stats from '../../../models/schemas/Stat.js'; /** * Generates a random password with specified characteristics. diff --git a/src/controllers/v3/utils/user.js b/src/controllers/v3/utils/user.js new file mode 100644 index 0000000..29b065a --- /dev/null +++ b/src/controllers/v3/utils/user.js @@ -0,0 +1,83 @@ +import crypto from 'crypto'; +import Users from '../../../models/schemas/User.js'; +import generateToken from '../../../modules/generateToken.js'; + +/** + * Handles user-related operations based on the HTTP method. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const userEndpoint = async (req, res, next) => { + try { + const { body, headers, method } = req; + const { key } = headers; + + // Check for valid access key in headers + if (!key || key !== process.env.ACCESS_KEY) { + return res.status(401).json({ + message: 'Unauthorized', + }); + } + + if (method === 'POST') { + const { token, id } = body; + + // Check for required fields in the request body + if (!token || !id) { + return res.status(400).json({ + message: 'Token and User ID are required in the request body', + }); + } + + // Update user's token in the database + await Users.updateOne( + { _id: { $eq: id } }, + { $set: { token: token } }, + { upsert: true } // Create the document if it doesn't exist + ); + + return res.status(200).json({ + message: 'Token updated successfully', + }); + } else if (method === 'GET') { + const { id, email } = headers; + + // Check for required User ID in the headers + if (!id) { + return res.status(400).json({ + message: 'User ID missing in the request body', + }); + } + + // Fetch user details based on the provided user ID + const user = await Users.findOne({ _id: { $eq: id } }); + + if (!user) { + // If user not found, create a new user with the provided ID and token + const newUser = { + _id: id, + email: email, + password: crypto.randomBytes(22).toString('base64'), + token: generateToken(id, process.env.HMAC_KEY), + // Add other fields in the "newUser" object based on your schema + }; + + await Users.create(newUser); + + return res.status(201).json(newUser.token); + } + + return res.status(200).json(user.token); + } else { + return res.status(405).json({ + message: 'Method Not Allowed', + }); + } + } catch (error) { + return next(error); + } +}; + +export default userEndpoint; diff --git a/src/controllers/utils/uvuify.js b/src/controllers/v3/utils/uvuify.js similarity index 91% rename from src/controllers/utils/uvuify.js rename to src/controllers/v3/utils/uvuify.js index 3d4175a..e22dee0 100644 --- a/src/controllers/utils/uvuify.js +++ b/src/controllers/v3/utils/uvuify.js @@ -1,6 +1,6 @@ import createError from 'http-errors'; import uwuify from 'owoify-js'; -import Stats from '../../models/schemas/Stat.js'; +import Stats from '../../../models/schemas/Stat.js'; const getOwofiyText = async (req, res, next) => { try { diff --git a/src/controllers/utils/uwuify.js b/src/controllers/v3/utils/uwuify.js similarity index 91% rename from src/controllers/utils/uwuify.js rename to src/controllers/v3/utils/uwuify.js index cb69fba..02b2f2e 100644 --- a/src/controllers/utils/uwuify.js +++ b/src/controllers/v3/utils/uwuify.js @@ -1,6 +1,6 @@ import createError from 'http-errors'; import uvuify from 'owoify-js'; -import Stats from '../../models/schemas/Stat.js'; +import Stats from '../../../models/schemas/Stat.js'; const getOwofiyText = async (req, res, next) => { try { diff --git a/src/controllers/waifus/randomWaifus.js b/src/controllers/v3/waifus/randomWaifus.js similarity index 84% rename from src/controllers/waifus/randomWaifus.js rename to src/controllers/v3/waifus/randomWaifus.js index a6817d5..6617651 100644 --- a/src/controllers/waifus/randomWaifus.js +++ b/src/controllers/v3/waifus/randomWaifus.js @@ -1,5 +1,5 @@ -import Waifus from '../../models/schemas/Waifus.js'; -import Stats from '../../models/schemas/Stat.js'; +import Waifus from '../../../models/schemas/Waifus.js'; +import Stats from '../../../models/schemas/Stat.js'; // Get a random waifu const getRandomWaifu = async (req, res, next) => { diff --git a/src/controllers/facts/randomFacts.js b/src/controllers/v4/facts/randomFacts.js similarity index 88% rename from src/controllers/facts/randomFacts.js rename to src/controllers/v4/facts/randomFacts.js index 6c3da31..f730d47 100644 --- a/src/controllers/facts/randomFacts.js +++ b/src/controllers/v4/facts/randomFacts.js @@ -1,8 +1,8 @@ import createError from 'http-errors'; -import Facts from '../../models/schemas/Facts.js'; -import tagsFilter from '../../utils/tagsFilter.js'; -import lengthFilter from '../../utils/lengthFilter.js'; -import Stats from '../../models/schemas/Stat.js'; +import Facts from '../../../models/schemas/Facts.js'; +import tagsFilter from '../../../utils/tagsFilter.js'; +import lengthFilter from '../../../utils/lengthFilter.js'; +import Stats from '../../../models/schemas/Stat.js'; /** * Gets a random anime fact with optional length and tags filters and updates system statistics. diff --git a/src/controllers/v4/gifs/randomAngry.js b/src/controllers/v4/gifs/randomAngry.js new file mode 100644 index 0000000..6156cb9 --- /dev/null +++ b/src/controllers/v4/gifs/randomAngry.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Angry from '../../../models/schemas/Angry.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Angry +const getRandomAngry = async (req, res, next) => { + try { + const [result] = await Angry.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Angry Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { angry: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomAngry; diff --git a/src/controllers/v4/gifs/randomBaka.js b/src/controllers/v4/gifs/randomBaka.js new file mode 100644 index 0000000..746b3b6 --- /dev/null +++ b/src/controllers/v4/gifs/randomBaka.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Baka from '../../../models/schemas/Baka.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Baka +const getRandomBaka = async (req, res, next) => { + try { + const [result] = await Baka.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Baka Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { baka: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomBaka; diff --git a/src/controllers/v4/gifs/randomBite.js b/src/controllers/v4/gifs/randomBite.js new file mode 100644 index 0000000..ddf9bf1 --- /dev/null +++ b/src/controllers/v4/gifs/randomBite.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Bite from '../../../models/schemas/Bite.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bite +const getRandomBite = async (req, res, next) => { + try { + const [result] = await Bite.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bite Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bite: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomBite; diff --git a/src/controllers/v4/gifs/randomBlush.js b/src/controllers/v4/gifs/randomBlush.js new file mode 100644 index 0000000..1a90820 --- /dev/null +++ b/src/controllers/v4/gifs/randomBlush.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Blush from '../../../models/schemas/Blush.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Blush +const getRandomBlush = async (req, res, next) => { + try { + const [result] = await Blush.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Blush Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { blush: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomBlush; diff --git a/src/controllers/v4/gifs/randomBonk.js b/src/controllers/v4/gifs/randomBonk.js new file mode 100644 index 0000000..c559823 --- /dev/null +++ b/src/controllers/v4/gifs/randomBonk.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Bonk from '../../../models/schemas/Bonk.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bonk +const getRandomBonk = async (req, res, next) => { + try { + const [result] = await Bonk.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bonk Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bonk: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomBonk; diff --git a/src/controllers/v4/gifs/randomBored.js b/src/controllers/v4/gifs/randomBored.js new file mode 100644 index 0000000..2caedfb --- /dev/null +++ b/src/controllers/v4/gifs/randomBored.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Bored from '../../../models/schemas/Bored.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bored +const getRandomBored = async (req, res, next) => { + try { + const [result] = await Bored.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bored Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bored: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomBored; diff --git a/src/controllers/v4/gifs/randomBully.js b/src/controllers/v4/gifs/randomBully.js new file mode 100644 index 0000000..ede6578 --- /dev/null +++ b/src/controllers/v4/gifs/randomBully.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Bully from '../../../models/schemas/Bully.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bully +const getRandomBully = async (req, res, next) => { + try { + const [result] = await Bully.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bully Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bully: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomBully; diff --git a/src/controllers/v4/gifs/randomBye.js b/src/controllers/v4/gifs/randomBye.js new file mode 100644 index 0000000..873468b --- /dev/null +++ b/src/controllers/v4/gifs/randomBye.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Bye from '../../../models/schemas/Bye.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Bye +const getRandomBye = async (req, res, next) => { + try { + const [result] = await Bye.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Bye Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { bye: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomBye; diff --git a/src/controllers/v4/gifs/randomChase.js b/src/controllers/v4/gifs/randomChase.js new file mode 100644 index 0000000..a16f38b --- /dev/null +++ b/src/controllers/v4/gifs/randomChase.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Chase from '../../../models/schemas/Chase.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Chase +const getRandomChase = async (req, res, next) => { + try { + const [result] = await Chase.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Chase Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { chase: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomChase; diff --git a/src/controllers/v4/gifs/randomCheer.js b/src/controllers/v4/gifs/randomCheer.js new file mode 100644 index 0000000..21447b8 --- /dev/null +++ b/src/controllers/v4/gifs/randomCheer.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Cheer from '../../../models/schemas/Cheer.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Cheer +const getRandomCheer = async (req, res, next) => { + try { + const [result] = await Cheer.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Cheer Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cheer: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomCheer; diff --git a/src/controllers/v4/gifs/randomCringe.js b/src/controllers/v4/gifs/randomCringe.js new file mode 100644 index 0000000..3551842 --- /dev/null +++ b/src/controllers/v4/gifs/randomCringe.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Cringe from '../../../models/schemas/Cringe.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Cringe +const getRandomCringe = async (req, res, next) => { + try { + const [result] = await Cringe.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Cringe Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cringe: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomCringe; diff --git a/src/controllers/v4/gifs/randomCry.js b/src/controllers/v4/gifs/randomCry.js new file mode 100644 index 0000000..80d80e5 --- /dev/null +++ b/src/controllers/v4/gifs/randomCry.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Cry from '../../../models/schemas/Cry.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Cry +const getRandomCry = async (req, res, next) => { + try { + const [result] = await Cry.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Cry Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cry: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomCry; diff --git a/src/controllers/v4/gifs/randomCuddle.js b/src/controllers/v4/gifs/randomCuddle.js new file mode 100644 index 0000000..f5f5314 --- /dev/null +++ b/src/controllers/v4/gifs/randomCuddle.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Cuddle from '../../../models/schemas/Cuddle.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Cuddle +const getRandomCuddle = async (req, res, next) => { + try { + const [result] = await Cuddle.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Cuddle Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { cuddle: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomCuddle; diff --git a/src/controllers/v4/gifs/randomDab.js b/src/controllers/v4/gifs/randomDab.js new file mode 100644 index 0000000..d95f2df --- /dev/null +++ b/src/controllers/v4/gifs/randomDab.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Dab from '../../../models/schemas/Dab.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Dab +const getRandomDab = async (req, res, next) => { + try { + const [result] = await Dab.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Dab Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { dab: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomDab; diff --git a/src/controllers/v4/gifs/randomDance.js b/src/controllers/v4/gifs/randomDance.js new file mode 100644 index 0000000..922e5e3 --- /dev/null +++ b/src/controllers/v4/gifs/randomDance.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Dance from '../../../models/schemas/Dance.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Dance +const getRandomDance = async (req, res, next) => { + try { + const [result] = await Dance.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Dance Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { dance: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomDance; diff --git a/src/controllers/v4/gifs/randomDie.js b/src/controllers/v4/gifs/randomDie.js new file mode 100644 index 0000000..da8936c --- /dev/null +++ b/src/controllers/v4/gifs/randomDie.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Die from '../../../models/schemas/Die.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Die +const getRandomDie = async (req, res, next) => { + try { + const [result] = await Die.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Die Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { die: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomDie; diff --git a/src/controllers/v4/gifs/randomDisgust.js b/src/controllers/v4/gifs/randomDisgust.js new file mode 100644 index 0000000..f52edbe --- /dev/null +++ b/src/controllers/v4/gifs/randomDisgust.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Disgust from '../../../models/schemas/Disgust.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Disgust +const getRandomDisgust = async (req, res, next) => { + try { + const [result] = await Disgust.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Disgust Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { disgust: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomDisgust; diff --git a/src/controllers/v4/gifs/randomFacepalm.js b/src/controllers/v4/gifs/randomFacepalm.js new file mode 100644 index 0000000..4d1751b --- /dev/null +++ b/src/controllers/v4/gifs/randomFacepalm.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Facepalm from '../../../models/schemas/Facepalm.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Facepalm +const getRandomFacepalm = async (req, res, next) => { + try { + const [result] = await Facepalm.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Facepalm Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { facepalm: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomFacepalm; diff --git a/src/controllers/v4/gifs/randomFeed.js b/src/controllers/v4/gifs/randomFeed.js new file mode 100644 index 0000000..930e163 --- /dev/null +++ b/src/controllers/v4/gifs/randomFeed.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Feed from '../../../models/schemas/Feed.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Feed +const getRandomFeed = async (req, res, next) => { + try { + const [result] = await Feed.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Feed Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { feed: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomFeed; diff --git a/src/controllers/v4/gifs/randomGlomp.js b/src/controllers/v4/gifs/randomGlomp.js new file mode 100644 index 0000000..2fd4029 --- /dev/null +++ b/src/controllers/v4/gifs/randomGlomp.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Glomp from '../../../models/schemas/Glomp.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Glomp +const getRandomGlomp = async (req, res, next) => { + try { + const [result] = await Glomp.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Glomp Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { glomp: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomGlomp; diff --git a/src/controllers/v4/gifs/randomHappy.js b/src/controllers/v4/gifs/randomHappy.js new file mode 100644 index 0000000..59de724 --- /dev/null +++ b/src/controllers/v4/gifs/randomHappy.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Happy from '../../../models/schemas/Happy.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Happy +const getRandomHappy = async (req, res, next) => { + try { + const [result] = await Happy.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Happy Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { happy: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomHappy; diff --git a/src/controllers/v4/gifs/randomHi.js b/src/controllers/v4/gifs/randomHi.js new file mode 100644 index 0000000..d2614d7 --- /dev/null +++ b/src/controllers/v4/gifs/randomHi.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Hi from '../../../models/schemas/Hi.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Hi +const getRandomHi = async (req, res, next) => { + try { + const [result] = await Hi.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Hi Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hi: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomHi; diff --git a/src/controllers/v4/gifs/randomHighfive.js b/src/controllers/v4/gifs/randomHighfive.js new file mode 100644 index 0000000..c290116 --- /dev/null +++ b/src/controllers/v4/gifs/randomHighfive.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Highfive from '../../../models/schemas/Highfive.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Highfive +const getRandomHighfive = async (req, res, next) => { + try { + const [result] = await Highfive.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Highfive Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { highfive: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomHighfive; diff --git a/src/controllers/v4/gifs/randomHold.js b/src/controllers/v4/gifs/randomHold.js new file mode 100644 index 0000000..9640b64 --- /dev/null +++ b/src/controllers/v4/gifs/randomHold.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Hold from '../../../models/schemas/Hold.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Hold +const getRandomHold = async (req, res, next) => { + try { + const [result] = await Hold.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Hold Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hold: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomHold; diff --git a/src/controllers/v4/gifs/randomHug.js b/src/controllers/v4/gifs/randomHug.js new file mode 100644 index 0000000..8d3432f --- /dev/null +++ b/src/controllers/v4/gifs/randomHug.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Hug from '../../../models/schemas/Hug.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Hug +const getRandomHug = async (req, res, next) => { + try { + const [result] = await Hug.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Hug Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { hug: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomHug; diff --git a/src/controllers/v4/gifs/randomKick.js b/src/controllers/v4/gifs/randomKick.js new file mode 100644 index 0000000..b24d888 --- /dev/null +++ b/src/controllers/v4/gifs/randomKick.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Kick from '../../../models/schemas/Kick.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Kick +const getRandomKick = async (req, res, next) => { + try { + const [result] = await Kick.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Kick Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kick: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomKick; diff --git a/src/controllers/v4/gifs/randomKill.js b/src/controllers/v4/gifs/randomKill.js new file mode 100644 index 0000000..7186102 --- /dev/null +++ b/src/controllers/v4/gifs/randomKill.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Kill from '../../../models/schemas/Kill.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Kill +const getRandomKill = async (req, res, next) => { + try { + const [result] = await Kill.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Kill Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kill: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomKill; diff --git a/src/controllers/v4/gifs/randomKissu.js b/src/controllers/v4/gifs/randomKissu.js new file mode 100644 index 0000000..a13ce66 --- /dev/null +++ b/src/controllers/v4/gifs/randomKissu.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Kissu from '../../../models/schemas/Kissu.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Kissu +const getRandomKissu = async (req, res, next) => { + try { + const [result] = await Kissu.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Kissu Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { kissu: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomKissu; diff --git a/src/controllers/v4/gifs/randomLaugh.js b/src/controllers/v4/gifs/randomLaugh.js new file mode 100644 index 0000000..7450f79 --- /dev/null +++ b/src/controllers/v4/gifs/randomLaugh.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Laugh from '../../../models/schemas/Laugh.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Laugh +const getRandomLaugh = async (req, res, next) => { + try { + const [result] = await Laugh.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Laugh Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { laugh: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomLaugh; diff --git a/src/controllers/v4/gifs/randomLick.js b/src/controllers/v4/gifs/randomLick.js new file mode 100644 index 0000000..df87eb8 --- /dev/null +++ b/src/controllers/v4/gifs/randomLick.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Lick from '../../../models/schemas/Lick.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Lick +const getRandomLick = async (req, res, next) => { + try { + const [result] = await Lick.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Lick Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { lick: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomLick; diff --git a/src/controllers/v4/gifs/randomLove.js b/src/controllers/v4/gifs/randomLove.js new file mode 100644 index 0000000..a0699e5 --- /dev/null +++ b/src/controllers/v4/gifs/randomLove.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Love from '../../../models/schemas/Love.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Love +const getRandomLove = async (req, res, next) => { + try { + const [result] = await Love.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Love Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { love: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomLove; diff --git a/src/controllers/v4/gifs/randomLurk.js b/src/controllers/v4/gifs/randomLurk.js new file mode 100644 index 0000000..74e36f7 --- /dev/null +++ b/src/controllers/v4/gifs/randomLurk.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Lurk from '../../../models/schemas/Lurk.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Lurk +const getRandomLurk = async (req, res, next) => { + try { + const [result] = await Lurk.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Lurk Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { lurk: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomLurk; diff --git a/src/controllers/v4/gifs/randomMidfing.js b/src/controllers/v4/gifs/randomMidfing.js new file mode 100644 index 0000000..6290752 --- /dev/null +++ b/src/controllers/v4/gifs/randomMidfing.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Midfing from '../../../models/schemas/Midfing.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Midfing +const getRandomMidfing = async (req, res, next) => { + try { + const [result] = await Midfing.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Midfing Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { midfing: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomMidfing; diff --git a/src/controllers/v4/gifs/randomNervous.js b/src/controllers/v4/gifs/randomNervous.js new file mode 100644 index 0000000..5a2616b --- /dev/null +++ b/src/controllers/v4/gifs/randomNervous.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Nervous from '../../../models/schemas/Nervous.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Nervous +const getRandomNervous = async (req, res, next) => { + try { + const [result] = await Nervous.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Nervous Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nervous: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomNervous; diff --git a/src/controllers/v4/gifs/randomNom.js b/src/controllers/v4/gifs/randomNom.js new file mode 100644 index 0000000..00f9b20 --- /dev/null +++ b/src/controllers/v4/gifs/randomNom.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Nom from '../../../models/schemas/Nom.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Nom +const getRandomNom = async (req, res, next) => { + try { + const [result] = await Nom.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Nom Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nom: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomNom; diff --git a/src/controllers/v4/gifs/randomNope.js b/src/controllers/v4/gifs/randomNope.js new file mode 100644 index 0000000..348aa18 --- /dev/null +++ b/src/controllers/v4/gifs/randomNope.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Nope from '../../../models/schemas/Nope.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Nope +const getRandomNope = async (req, res, next) => { + try { + const [result] = await Nope.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Nope Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nope: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomNope; diff --git a/src/controllers/v4/gifs/randomNuzzle.js b/src/controllers/v4/gifs/randomNuzzle.js new file mode 100644 index 0000000..38e1f7b --- /dev/null +++ b/src/controllers/v4/gifs/randomNuzzle.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Nuzzle from '../../../models/schemas/Nuzzle.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Nuzzle +const getRandomNuzzle = async (req, res, next) => { + try { + const [result] = await Nuzzle.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Nuzzle Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { nuzzle: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomNuzzle; diff --git a/src/controllers/v4/gifs/randomPanic.js b/src/controllers/v4/gifs/randomPanic.js new file mode 100644 index 0000000..abf97e0 --- /dev/null +++ b/src/controllers/v4/gifs/randomPanic.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Panic from '../../../models/schemas/Panic.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Panic +const getRandomPanic = async (req, res, next) => { + try { + const [result] = await Panic.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Panic Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { panic: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomPanic; diff --git a/src/controllers/v4/gifs/randomPat.js b/src/controllers/v4/gifs/randomPat.js new file mode 100644 index 0000000..bd683d9 --- /dev/null +++ b/src/controllers/v4/gifs/randomPat.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Pat from '../../../models/schemas/Pat.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Pat +const getRandomPat = async (req, res, next) => { + try { + const [result] = await Pat.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Pat Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { pat: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomPat; diff --git a/src/controllers/v4/gifs/randomPeck.js b/src/controllers/v4/gifs/randomPeck.js new file mode 100644 index 0000000..fb96e43 --- /dev/null +++ b/src/controllers/v4/gifs/randomPeck.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Peck from '../../../models/schemas/Peck.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Peck +const getRandomPeck = async (req, res, next) => { + try { + const [result] = await Peck.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Peck Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { peck: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomPeck; diff --git a/src/controllers/v4/gifs/randomPoke.js b/src/controllers/v4/gifs/randomPoke.js new file mode 100644 index 0000000..4b2c428 --- /dev/null +++ b/src/controllers/v4/gifs/randomPoke.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Poke from '../../../models/schemas/Poke.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Poke +const getRandomPoke = async (req, res, next) => { + try { + const [result] = await Poke.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Poke Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { poke: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomPoke; diff --git a/src/controllers/v4/gifs/randomPout.js b/src/controllers/v4/gifs/randomPout.js new file mode 100644 index 0000000..dc45330 --- /dev/null +++ b/src/controllers/v4/gifs/randomPout.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Pout from '../../../models/schemas/Pout.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Pout +const getRandomPout = async (req, res, next) => { + try { + const [result] = await Pout.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Pout Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { pout: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomPout; diff --git a/src/controllers/v4/gifs/randomPunch.js b/src/controllers/v4/gifs/randomPunch.js new file mode 100644 index 0000000..dd35b84 --- /dev/null +++ b/src/controllers/v4/gifs/randomPunch.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Punch from '../../../models/schemas/Punch.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Punch +const getRandomPunch = async (req, res, next) => { + try { + const [result] = await Punch.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Punch Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { punch: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomPunch; diff --git a/src/controllers/v4/gifs/randomRun.js b/src/controllers/v4/gifs/randomRun.js new file mode 100644 index 0000000..061d36f --- /dev/null +++ b/src/controllers/v4/gifs/randomRun.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Run from '../../../models/schemas/Run.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Run +const getRandomRun = async (req, res, next) => { + try { + const [result] = await Run.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Run Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { run: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomRun; diff --git a/src/controllers/v4/gifs/randomSad.js b/src/controllers/v4/gifs/randomSad.js new file mode 100644 index 0000000..0af254d --- /dev/null +++ b/src/controllers/v4/gifs/randomSad.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Sad from '../../../models/schemas/Sad.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Sad +const getRandomSad = async (req, res, next) => { + try { + const [result] = await Sad.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Sad Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sad: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomSad; diff --git a/src/controllers/v4/gifs/randomShoot.js b/src/controllers/v4/gifs/randomShoot.js new file mode 100644 index 0000000..cdc8a1b --- /dev/null +++ b/src/controllers/v4/gifs/randomShoot.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Shoot from '../../../models/schemas/Shoot.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Shoot +const getRandomShoot = async (req, res, next) => { + try { + const [result] = await Shoot.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Shoot Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { shoot: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomShoot; diff --git a/src/controllers/v4/gifs/randomShrug.js b/src/controllers/v4/gifs/randomShrug.js new file mode 100644 index 0000000..9755221 --- /dev/null +++ b/src/controllers/v4/gifs/randomShrug.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Shrug from '../../../models/schemas/Shrug.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Shrug +const getRandomShrug = async (req, res, next) => { + try { + const [result] = await Shrug.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Shrug Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { shrug: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomShrug; diff --git a/src/controllers/v4/gifs/randomSip.js b/src/controllers/v4/gifs/randomSip.js new file mode 100644 index 0000000..37fcea4 --- /dev/null +++ b/src/controllers/v4/gifs/randomSip.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Sip from '../../../models/schemas/Sip.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Sip +const getRandomSip = async (req, res, next) => { + try { + const [result] = await Sip.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Sip Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sip: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomSip; diff --git a/src/controllers/v4/gifs/randomSlap.js b/src/controllers/v4/gifs/randomSlap.js new file mode 100644 index 0000000..89fb3e5 --- /dev/null +++ b/src/controllers/v4/gifs/randomSlap.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Slap from '../../../models/schemas/Slap.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Slap +const getRandomSlap = async (req, res, next) => { + try { + const [result] = await Slap.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Slap Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { slap: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomSlap; diff --git a/src/controllers/v4/gifs/randomSleepy.js b/src/controllers/v4/gifs/randomSleepy.js new file mode 100644 index 0000000..a408099 --- /dev/null +++ b/src/controllers/v4/gifs/randomSleepy.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Sleepy from '../../../models/schemas/Sleepy.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Sleepy +const getRandomSleepy = async (req, res, next) => { + try { + const [result] = await Sleepy.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Sleepy Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { sleepy: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomSleepy; diff --git a/src/controllers/v4/gifs/randomSmile.js b/src/controllers/v4/gifs/randomSmile.js new file mode 100644 index 0000000..54983e2 --- /dev/null +++ b/src/controllers/v4/gifs/randomSmile.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Smile from '../../../models/schemas/Smile.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Smile +const getRandomSmile = async (req, res, next) => { + try { + const [result] = await Smile.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Smile Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { smile: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomSmile; diff --git a/src/controllers/v4/gifs/randomSmug.js b/src/controllers/v4/gifs/randomSmug.js new file mode 100644 index 0000000..8861730 --- /dev/null +++ b/src/controllers/v4/gifs/randomSmug.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Smug from '../../../models/schemas/Smug.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Smug +const getRandomSmug = async (req, res, next) => { + try { + const [result] = await Smug.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Smug Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { smug: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomSmug; diff --git a/src/controllers/v4/gifs/randomStab.js b/src/controllers/v4/gifs/randomStab.js new file mode 100644 index 0000000..3b0ce94 --- /dev/null +++ b/src/controllers/v4/gifs/randomStab.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Stab from '../../../models/schemas/Stab.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Stab +const getRandomStab = async (req, res, next) => { + try { + const [result] = await Stab.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Stab Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { stab: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomStab; diff --git a/src/controllers/v4/gifs/randomStare.js b/src/controllers/v4/gifs/randomStare.js new file mode 100644 index 0000000..b1c2979 --- /dev/null +++ b/src/controllers/v4/gifs/randomStare.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Stare from '../../../models/schemas/Stare.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Stare +const getRandomStare = async (req, res, next) => { + try { + const [result] = await Stare.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Stare Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { stare: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomStare; diff --git a/src/controllers/v4/gifs/randomSuicide.js b/src/controllers/v4/gifs/randomSuicide.js new file mode 100644 index 0000000..f3d355c --- /dev/null +++ b/src/controllers/v4/gifs/randomSuicide.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Suicide from '../../../models/schemas/Suicide.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Suicide +const getRandomSuicide = async (req, res, next) => { + try { + const [result] = await Suicide.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Suicide Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { suicide: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomSuicide; diff --git a/src/controllers/v4/gifs/randomTease.js b/src/controllers/v4/gifs/randomTease.js new file mode 100644 index 0000000..5698856 --- /dev/null +++ b/src/controllers/v4/gifs/randomTease.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Tease from '../../../models/schemas/Tease.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Tease +const getRandomTease = async (req, res, next) => { + try { + const [result] = await Tease.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Tease Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { tease: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomTease; diff --git a/src/controllers/v4/gifs/randomThink.js b/src/controllers/v4/gifs/randomThink.js new file mode 100644 index 0000000..0afad57 --- /dev/null +++ b/src/controllers/v4/gifs/randomThink.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Think from '../../../models/schemas/Think.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Think +const getRandomThink = async (req, res, next) => { + try { + const [result] = await Think.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Think Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { think: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomThink; diff --git a/src/controllers/v4/gifs/randomThumbsup.js b/src/controllers/v4/gifs/randomThumbsup.js new file mode 100644 index 0000000..6a2d1bd --- /dev/null +++ b/src/controllers/v4/gifs/randomThumbsup.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Thumbsup from '../../../models/schemas/Thumbsup.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Thumbsup +const getRandomThumbsup = async (req, res, next) => { + try { + const [result] = await Thumbsup.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Thumbsup Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { thumbsup: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomThumbsup; diff --git a/src/controllers/v4/gifs/randomTickle.js b/src/controllers/v4/gifs/randomTickle.js new file mode 100644 index 0000000..06e4bd2 --- /dev/null +++ b/src/controllers/v4/gifs/randomTickle.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Tickle from '../../../models/schemas/Tickle.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Tickle +const getRandomTickle = async (req, res, next) => { + try { + const [result] = await Tickle.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Tickle Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { tickle: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomTickle; diff --git a/src/controllers/v4/gifs/randomTriggered.js b/src/controllers/v4/gifs/randomTriggered.js new file mode 100644 index 0000000..bfbc35e --- /dev/null +++ b/src/controllers/v4/gifs/randomTriggered.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Triggered from '../../../models/schemas/Triggered.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Triggered +const getRandomTriggered = async (req, res, next) => { + try { + const [result] = await Triggered.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Triggered Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { triggered: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomTriggered; diff --git a/src/controllers/v4/gifs/randomWag.js b/src/controllers/v4/gifs/randomWag.js new file mode 100644 index 0000000..88ad360 --- /dev/null +++ b/src/controllers/v4/gifs/randomWag.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Wag from '../../../models/schemas/Wag.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Wag +const getRandomWag = async (req, res, next) => { + try { + const [result] = await Wag.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Wag Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wag: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomWag; diff --git a/src/controllers/v4/gifs/randomWave.js b/src/controllers/v4/gifs/randomWave.js new file mode 100644 index 0000000..195dfb1 --- /dev/null +++ b/src/controllers/v4/gifs/randomWave.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Wave from '../../../models/schemas/Wave.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Wave +const getRandomWave = async (req, res, next) => { + try { + const [result] = await Wave.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Wave Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wave: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomWave; diff --git a/src/controllers/v4/gifs/randomWink.js b/src/controllers/v4/gifs/randomWink.js new file mode 100644 index 0000000..fb03a57 --- /dev/null +++ b/src/controllers/v4/gifs/randomWink.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Wink from '../../../models/schemas/Wink.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Wink +const getRandomWink = async (req, res, next) => { + try { + const [result] = await Wink.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Wink Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { wink: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomWink; diff --git a/src/controllers/v4/gifs/randomYes.js b/src/controllers/v4/gifs/randomYes.js new file mode 100644 index 0000000..1408489 --- /dev/null +++ b/src/controllers/v4/gifs/randomYes.js @@ -0,0 +1,31 @@ + +import createError from 'http-errors'; +import Yesh from '../../../models/schemas/Yesh.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get random Anime Yes +const getRandomYes = async (req, res, next) => { + try { + const [result] = await Yesh.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0, _id: 0 } }, + ]); + + if (!result) { + return next(createError(404, 'Could not find any Yes Gif')); + } + + res.status(200).json(result); + + await Stats.findOneAndUpdate({ _id: 'systemstats' }, { $inc: { yes: 1 } }); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomYes; diff --git a/src/controllers/v4/quotes/randomQuotes.js b/src/controllers/v4/quotes/randomQuotes.js new file mode 100644 index 0000000..76cd20d --- /dev/null +++ b/src/controllers/v4/quotes/randomQuotes.js @@ -0,0 +1,49 @@ +import createError from 'http-errors'; +import Quotes from '../../../models/schemas/Quotes.js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets a random anime quote with optional character filter and updates system statistics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getRandomQuote = async (req, res, next) => { + try { + const { character } = req.query; + + // Create a filter object based on the optional character parameter + const filter = character ? { author: character } : {}; + + // Aggregate to match the filter, select a random quote, and project excluding version field + const [result] = await Quotes.aggregate([ + { $match: filter }, // Apply filters (if any) + { $sample: { size: 1 } }, // Select a random document from the results + { $project: { __v: 0 } }, + ]); + + // If no quote is found, return a 404 error + if (!result) { + return next(createError(404, 'Could not find any matching Quote')); + } + + // Respond with the random quote + res.status(200).json(result); + + // Update system statistics for quotes + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { quotes: 1 } } + ); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomQuote; diff --git a/src/controllers/utils/listTags.js b/src/controllers/v4/utils/listTags.js similarity index 90% rename from src/controllers/utils/listTags.js rename to src/controllers/v4/utils/listTags.js index 17ea89b..d740344 100644 --- a/src/controllers/utils/listTags.js +++ b/src/controllers/v4/utils/listTags.js @@ -1,6 +1,6 @@ -import Tags from '../../models/schemas/Tags.js'; -import parseOrder from '../../utils/parseOrder.js'; -import Stats from '../../models/schemas/Stat.js'; +import Tags from '../../../models/schemas/Tags.js'; +import parseOrder from '../../../utils/parseOrder.js'; +import Stats from '../../../models/schemas/Stat.js'; /** * Lists tags with optional sorting and updates system statistics. diff --git a/src/controllers/v4/utils/owoify.js b/src/controllers/v4/utils/owoify.js new file mode 100644 index 0000000..beb1fa0 --- /dev/null +++ b/src/controllers/v4/utils/owoify.js @@ -0,0 +1,41 @@ +import createError from 'http-errors'; +import owoify from 'owoify-js'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Gets the Owofied version of the provided text and updates system statistics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getOwofiyText = async (req, res, next) => { + try { + const { text } = req.query; + + // Check for valid text input + if (!text) { + return next(createError(404, 'Invalid text input.')); + } + + // Owofy the text and send the response + res.status(200).json({ + text: owoify(text), + }); + + // Update system statistics for Owofied texts + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { owoify: 1 } } + ); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getOwofiyText; diff --git a/src/controllers/v4/utils/randomPassword.js b/src/controllers/v4/utils/randomPassword.js new file mode 100644 index 0000000..fe65922 --- /dev/null +++ b/src/controllers/v4/utils/randomPassword.js @@ -0,0 +1,44 @@ +import pass from 'generate-password'; +import Stats from '../../../models/schemas/Stat.js'; + +/** + * Generates a random password with specified characteristics. + * + * @param {Object} req - Express request object. + * @param {Object} res - Express response object. + * @param {Function} next - Express next middleware function. + */ +const getRandomPassword = async (req, res, next) => { + try { + const { charLength } = req.query; + + // Generate a random password with specified characteristics + const password = pass.generate({ + length: charLength || 50, + uppercase: true, + numbers: true, + symbols: true, + lowercase: true, + strict: true, + }); + + res.status(200).json({ + pass: password, + }); + + // Update system statistics for generated passwords + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { password: 1 } } + ); + } catch (error) { + // Update system statistics for failed requests + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getRandomPassword; diff --git a/src/controllers/utils/user.js b/src/controllers/v4/utils/user.js similarity index 95% rename from src/controllers/utils/user.js rename to src/controllers/v4/utils/user.js index 4b8765d..0414fe8 100644 --- a/src/controllers/utils/user.js +++ b/src/controllers/v4/utils/user.js @@ -1,6 +1,6 @@ import crypto from 'crypto'; -import Users from '../../models/schemas/Users.js'; -import generateToken from '../../utils/generateToken.js'; +import Users from '../../../models/schemas/User.js'; +import generateToken from '../../../utils/generateToken.js'; /** * Handles user-related operations based on the HTTP method. diff --git a/src/controllers/v4/utils/uvuify.js b/src/controllers/v4/utils/uvuify.js new file mode 100644 index 0000000..e22dee0 --- /dev/null +++ b/src/controllers/v4/utils/uvuify.js @@ -0,0 +1,30 @@ +import createError from 'http-errors'; +import uwuify from 'owoify-js'; +import Stats from '../../../models/schemas/Stat.js'; + +const getOwofiyText = async (req, res, next) => { + try { + const { text } = req.query; + + if (!text) { + return next(createError(404, 'Invalid text input.')); + } + + res.status(200).json({ + text: uwuify(text), + }); + + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { uwuify: 1 } } + ); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + return next(error); + } +}; + +export default getOwofiyText; diff --git a/src/controllers/v4/utils/uwuify.js b/src/controllers/v4/utils/uwuify.js new file mode 100644 index 0000000..02b2f2e --- /dev/null +++ b/src/controllers/v4/utils/uwuify.js @@ -0,0 +1,30 @@ +import createError from 'http-errors'; +import uvuify from 'owoify-js'; +import Stats from '../../../models/schemas/Stat.js'; + +const getOwofiyText = async (req, res, next) => { + try { + const { text } = req.query; + + if (!text) { + throw createError(404, 'Invalid text input.'); + } + + res.status(200).json({ + text: uvuify(text), + }); + + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { uvuify: 1 } } + ); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + next(error); + } +}; + +export default getOwofiyText; diff --git a/src/controllers/v4/waifus/randomWaifus.js b/src/controllers/v4/waifus/randomWaifus.js new file mode 100644 index 0000000..6617651 --- /dev/null +++ b/src/controllers/v4/waifus/randomWaifus.js @@ -0,0 +1,28 @@ +import Waifus from '../../../models/schemas/Waifus.js'; +import Stats from '../../../models/schemas/Stat.js'; + +// Get a random waifu +const getRandomWaifu = async (req, res, next) => { + try { + const [result] = await Waifus.aggregate([ + // Select a random document from the results + { $sample: { size: 1 } }, + { $project: { __v: 0 } }, + ]); + + res.status(200).json(result); + + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { waifus: 1 } } + ); + } catch (error) { + await Stats.findOneAndUpdate( + { _id: 'systemstats' }, + { $inc: { failed_requests: 1 } } + ); + next(error); + } +}; + +export default getRandomWaifu; diff --git a/src/handlers/handleAuthentication.js b/src/middlewares/authorize.js similarity index 82% rename from src/handlers/handleAuthentication.js rename to src/middlewares/authorize.js index e7afa0f..17e1bd7 100644 --- a/src/handlers/handleAuthentication.js +++ b/src/middlewares/authorize.js @@ -1,15 +1,13 @@ import createError from 'http-errors'; -import Users from '../models/schemas/Users.js'; +import Users from '../models/schemas/User.js'; import Stats from '../models/schemas/Stat.js'; /** * Middleware for handling user authentication and request validation. - * @param {Object} req - Express request object. - * @param {Object} res - Express response object. - * @param {Function} next - Express next function. - * @returns {void} - Calls the next middleware or error handler. + * @param {string} requiredRole - The required role to access the endpoint. + * @returns {function} - Express middleware function. */ -const handleAuthentication = async (req, res, next) => { +const authorize = (requiredRole) => async (req, res, next) => { try { // Extract API key from request headers const key = req.headers.authorization; @@ -61,6 +59,11 @@ const handleAuthentication = async (req, res, next) => { ); } + // Check if the user has the required role + if (!userData.roles.includes(requiredRole)) { + return next(createError(403, 'Insufficient privileges to access this endpoint.')); + } + // Increment system stats for successful requests await incrementSystemStats({ endpoints_requests: 1, @@ -85,4 +88,4 @@ const incrementSystemStats = async (stats) => { await Stats.findByIdAndUpdate({ _id: 'systemstats' }, { $inc: stats }); }; -export default handleAuthentication; +export default authorize; diff --git a/src/handlers/errors/index.js b/src/middlewares/errors.js similarity index 76% rename from src/handlers/errors/index.js rename to src/middlewares/errors.js index f165612..373f34e 100644 --- a/src/handlers/errors/index.js +++ b/src/middlewares/errors.js @@ -2,11 +2,11 @@ import createError from 'http-errors'; import chalk from 'chalk'; // Handles 404 errors -export const handler404 = (req, res, next) => { +export const handle404 = (req, res, next) => { next(createError(404, 'The requested resource could not be found')); }; -export const errorsLogger = (error, req, res, next) => { +export const logErrors = (error, req, res, next) => { if (process.env.NODE_ENV === 'development') { /* eslint-disable-next-line no-console */ console.error(chalk.red('[ERROR]'), error.stack); @@ -15,7 +15,7 @@ export const errorsLogger = (error, req, res, next) => { }; // Sends error response to client -export const errorsHandler = (error, req, res, next) => { +export const errorHandler = (error, req, res, next) => { const statusCode = error.status || 500; const statusMessage = error.message || 'Internal server error'; res.status(statusCode).json({ statusCode, statusMessage }); diff --git a/src/handlers/logger/ip.js b/src/middlewares/logger.js similarity index 93% rename from src/handlers/logger/ip.js rename to src/middlewares/logger.js index 3cffe06..4d71b4f 100644 --- a/src/handlers/logger/ip.js +++ b/src/middlewares/logger.js @@ -3,7 +3,7 @@ import { Webhook } from 'discord-webhook-node'; const hook = new Webhook(process.env.DISCORD_WEBHOOK_URL); -export const ipLogger = (req, res, next) => { +export const logIP = (req, res, next) => { const auth = req.headers.auth || 'Null Auth'; const log = `${new Date()} - STATUS=${res.statusCode} - METHOD=${req.method} - IP=${req.ip} | ${requestIp.getClientIp(req)} - URL=${req.originalUrl} - ${auth}\n`; diff --git a/src/handlers/rateLimit.js b/src/middlewares/rateLimit.js similarity index 95% rename from src/handlers/rateLimit.js rename to src/middlewares/rateLimit.js index 5c541e0..99c404d 100644 --- a/src/handlers/rateLimit.js +++ b/src/middlewares/rateLimit.js @@ -1,5 +1,5 @@ import rateLimit from 'express-rate-limit'; -import Users from '../models/schemas/Users.js'; +import Users from '../models/schemas/User.js'; /** * Create and return the rate limiter middleware. diff --git a/src/models/schemas/Facts.js b/src/models/schemas/Fact.js similarity index 100% rename from src/models/schemas/Facts.js rename to src/models/schemas/Fact.js diff --git a/src/models/schemas/Users.js b/src/models/schemas/User.js similarity index 86% rename from src/models/schemas/Users.js rename to src/models/schemas/User.js index db2b99a..5c0204e 100644 --- a/src/models/schemas/Users.js +++ b/src/models/schemas/User.js @@ -14,6 +14,7 @@ import mongoose from 'mongoose'; * @property {boolean} token_reset - Flag indicating whether the user's token needs to be reset. (default: false) * @property {Date} createdAt - Date and time when the user account was created. (default: current date and time) * @property {number} rateLimit - Request rate limit for the user. (default: 20) + * @property {Array} roles - Array of roles assigned to the user. Possible roles: developer, admin, moderator, database_moderator, premium, user. */ const userSchema = new mongoose.Schema({ @@ -37,6 +38,7 @@ const userSchema = new mongoose.Schema({ default: Date.now(), }, rateLimit: { type: Number, default: 20 }, + roles: { type: [String], default: ['user'] }, // Default role is 'user', additional roles can be added as needed }); /** @@ -45,4 +47,4 @@ const userSchema = new mongoose.Schema({ */ const User = mongoose.model('User', userSchema); -export default User; +export default User; \ No newline at end of file diff --git a/src/models/schemas/Yesh.js b/src/models/schemas/Yesh.js index 0904d39..354bc1b 100644 --- a/src/models/schemas/Yesh.js +++ b/src/models/schemas/Yesh.js @@ -3,7 +3,7 @@ const { Schema, model } = mongoose; const YeshSchema = new Schema({ _id: { type: Number }, - url: { type: String, required: true }, + url: { type: String, required: true, unique: true }, }); export default model('Yesh', YeshSchema); diff --git a/src/modules/config/config.js b/src/modules/config/config.js new file mode 100644 index 0000000..d6050f3 --- /dev/null +++ b/src/modules/config/config.js @@ -0,0 +1,50 @@ +// config.js +import dotenv from 'dotenv'; +dotenv.config(); + +const config = { + development: { + database: { + host: process.env.DB_HOST || 'localhost', + username: process.env.DB_USERNAME || 'user', + password: process.env.DB_PASSWORD || 'password', + databaseName: process.env.DB_NAME || 'mydatabase', + }, + server: { + port: process.env.PORT || 3000, + host: process.env.HOST || '127.0.0.1', + }, + roles: { + DEVELOPER: 'developer', + ADMIN: 'admin', + MOD: 'moderator', + DB_MOD: 'database_moderator', + PREMIUM: 'premium', + USER: 'user', + }, + }, + production: { + database: { + host: process.env.DB_HOST || 'production-host', + username: process.env.DB_USERNAME || 'production-user', + password: process.env.DB_PASSWORD || 'production-password', + databaseName: process.env.DB_NAME || 'production-database', + }, + server: { + port: process.env.PORT || 80, + host: process.env.HOST || 'production-hostname', + }, + roles: { + DEVELOPER: 'developer', + ADMIN: 'admin', + MOD: 'moderator', + DB_MOD: 'database_moderator', + PREMIUM: 'premium', + USER: 'user', + }, + }, +}; + +const environment = process.env.NODE_ENV || 'development'; + +global.config = config[environment]; diff --git a/src/modules/database/add.js b/src/modules/database/add.js new file mode 100644 index 0000000..70995a9 --- /dev/null +++ b/src/modules/database/add.js @@ -0,0 +1,34 @@ +const incrementData = schemaName => async (req, res, next) => { + try { + // Dynamically import the schema based on the provided schemaName + const schema = await import(`../../models/schemas/${schemaName}.js`); + + const Data = req.body; + + // Find the document with the highest _id value + const highestIdDocument = await schema.default.findOne({}, {}, { sort: { _id: -1 } }); + + // Calculate the next _id value + const nextItemId = (highestIdDocument && highestIdDocument._id ? highestIdDocument._id : 0) + 1; + + // Create a new document with the incremented _id and other data + const newItem = { _id: nextItemId, ...Data }; // Spread the properties of Data + + // Save the new document + const result = await schema.default.create(newItem); + + res.status(200).json({ + status: '200', + message: 'Data added successfully', + result + }); + } catch (error) { + if (error.code === 11000) { + return res.status(500).json({ error: 'Duplicate key value' }); + } + console.error('Error adding data:', error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +export default incrementData; diff --git a/src/modules/database/delete.js b/src/modules/database/delete.js new file mode 100644 index 0000000..f84f10e --- /dev/null +++ b/src/modules/database/delete.js @@ -0,0 +1,34 @@ +const deleteData = schemaName => async (req, res, next) => { + try { + // Dynamically import the schema based on the provided schemaName + const schema = await import(`../../models/schemas/${schemaName}.js`); + + // Check if _id is provided in the request + const requestedId = req.params.id; // Assuming the id is in the request parameters + + if (!requestedId) { + return res.status(400).json({ error: 'Missing id parameter' }); + } + + // Find the document with the specified _id + const existingItem = await schema.default.findById(requestedId); + + if (!existingItem) { + return res.status(404).json({ error: 'Document not found' }); + } + + // Delete the document + await existingItem.remove(); + + res.status(200).json({ + status: '200', + message: 'Data deleted successfully', + result: existingItem, + }); + } catch (error) { + console.error('Error deleting data:', error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +export default deleteData; diff --git a/src/modules/database/update.js b/src/modules/database/update.js new file mode 100644 index 0000000..9d984de --- /dev/null +++ b/src/modules/database/update.js @@ -0,0 +1,42 @@ +const updateData = schemaName => async (req, res, next) => { + try { + // Dynamically import the schema based on the provided schemaName + const schema = await import(`../../models/schemas/${schemaName}.js`); + + const Data = req.body; + + // Check if _id is provided in the request + const requestedId = req.params.id; // Assuming the id is in the request parameters + + if (!requestedId) { + return res.status(400).json({ error: 'Missing id parameter' }); + } + + // Find the document with the specified _id + const existingItem = await schema.default.findById(requestedId); + + if (!existingItem) { + return res.status(404).json({ error: 'Document not found' }); + } + + // Update the existing document with the new data + Object.assign(existingItem, Data); + + // Save the updated document + const result = await existingItem.save(); + + res.status(200).json({ + status: '200', + message: 'Data updated successfully', + result, + }); + } catch (error) { + if (error.code === 11000) { + return res.status(500).json({ error: 'Duplicate key value' }); + } + console.error('Error updating data:', error); + res.status(500).json({ error: 'Internal Server Error' }); + } +}; + +export default updateData; diff --git a/src/utils/generateToken.js b/src/modules/generateToken.js similarity index 100% rename from src/utils/generateToken.js rename to src/modules/generateToken.js diff --git a/src/utils/lengthFilter.js b/src/modules/lengthFilter.js similarity index 100% rename from src/utils/lengthFilter.js rename to src/modules/lengthFilter.js diff --git a/src/utils/parseOrder.js b/src/modules/parseOrder.js similarity index 100% rename from src/utils/parseOrder.js rename to src/modules/parseOrder.js diff --git a/src/utils/tagsFilter.js b/src/modules/tagsFilter.js similarity index 100% rename from src/utils/tagsFilter.js rename to src/modules/tagsFilter.js diff --git a/src/routes.js b/src/routes.js deleted file mode 100644 index 95161c3..0000000 --- a/src/routes.js +++ /dev/null @@ -1,223 +0,0 @@ -/** - * 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 createRateLimiter() has been implemented to manage the frequency of requests and prevent abuse. The `handleAuthentication` 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 - */ - -import { Router } from 'express'; -import createRateLimiter from './handlers/rateLimit.js'; -import handleAuthentication from './handlers/handleAuthentication.js'; -import randomFacts from './controllers/facts/randomFacts.js'; -import getAllTags from './controllers/utils/listTags.js'; -import getOwoify from './controllers/utils/owoify.js'; -import getUwuify from './controllers/utils/uwuify.js'; -import getUvuify from './controllers/utils/uvuify.js'; -import randomWaifus from './controllers/waifus/randomWaifus.js'; -import randomPasswords from './controllers/utils/randomPassword.js'; -import randomQuotes from './controllers/quotes/randomQuotes.js'; -import randomKick from './controllers/gifs/randomKick.js'; -import randomKill from './controllers/gifs/randomKill.js'; -import randomKissu from './controllers/gifs/randomKissu.js'; -import randomMidfing from './controllers/gifs/randomMidfing.js'; -import randomNuzzle from './controllers/gifs/randomNuzzle.js'; -import randomPunch from './controllers/gifs/randomPunch.js'; -import randomShoot from './controllers/gifs/randomShoot.js'; -import randomSip from './controllers/gifs/randomSip.js'; -import randomSleepy from './controllers/gifs/randomSleepy.js'; -import randomSmile from './controllers/gifs/randomSmile.js'; -import randomStab from './controllers/gifs/randomStab.js'; -import randomStare from './controllers/gifs/randomStare.js'; -import randomSuicide from './controllers/gifs/randomSuicide.js'; -import randomTease from './controllers/gifs/randomTease.js'; -import randomWag from './controllers/gifs/randomWag.js'; -import randomBite from './controllers/gifs/randomBite.js'; -import randomBlush from './controllers/gifs/randomBlush.js'; -import randomBonk from './controllers/gifs/randomBonk.js'; -import randomBored from './controllers/gifs/randomBored.js'; -import randomBully from './controllers/gifs/randomBully.js'; -import randomBye from './controllers/gifs/randomBye.js'; -import randomChase from './controllers/gifs/randomChase.js'; -import randomCheer from './controllers/gifs/randomCheer.js'; -import randomDab from './controllers/gifs/randomDab.js'; -import randomDie from './controllers/gifs/randomDie.js'; -import randomDisgust from './controllers/gifs/randomDisgust.js'; -import randomFeed from './controllers/gifs/randomFeed.js'; -import randomHi from './controllers/gifs/randomHi.js'; -import randomHold from './controllers/gifs/randomHold.js'; -import randomHug from './controllers/gifs/randomHug.js'; -import randomNope from './controllers/gifs/randomNope.js'; -import randomPanic from './controllers/gifs/randomPanic.js'; -import randomPat from './controllers/gifs/randomPat.js'; -import randomPeck from './controllers/gifs/randomPeck.js'; -import randomPoke from './controllers/gifs/randomPoke.js'; -import randomPout from './controllers/gifs/randomPout.js'; -import randomRun from './controllers/gifs/randomRun.js'; -import randomSad from './controllers/gifs/randomSad.js'; -import randomShrug from './controllers/gifs/randomShrug.js'; -import randomSlap from './controllers/gifs/randomSlap.js'; -import randomSmug from './controllers/gifs/randomSmug.js'; -import randomThink from './controllers/gifs/randomThink.js'; -import randomThumbsup from './controllers/gifs/randomThumbsup.js'; -import randomTickle from './controllers/gifs/randomTickle.js'; -import randomTriggered from './controllers/gifs/randomTriggered.js'; -import randomWave from './controllers/gifs/randomWave.js'; -import randomWink from './controllers/gifs/randomWink.js'; -import randomYes from './controllers/gifs/randomYes.js'; -import randomAngry from './controllers/gifs/randomAngry.js'; -import randomCringe from './controllers/gifs/randomCringe.js'; -import randomCry from './controllers/gifs/randomCry.js'; -import randomCuddle from './controllers/gifs/randomCuddle.js'; -import randomDance from './controllers/gifs/randomDance.js'; -import randomFacepalm from './controllers/gifs/randomFacepalm.js'; -import randomGlomp from './controllers/gifs/randomGlomp.js'; -import randomHappy from './controllers/gifs/randomHappy.js'; -import randomHighfive from './controllers/gifs/randomHighfive.js'; -import randomLaugh from './controllers/gifs/randomLaugh.js'; -import randomLick from './controllers/gifs/randomLick.js'; -import randomLove from './controllers/gifs/randomLove.js'; -import randomLurk from './controllers/gifs/randomLurk.js'; -import randomNervous from './controllers/gifs/randomNervous.js'; -import randomNom from './controllers/gifs/randomNom.js'; -import randomBaka from './controllers/gifs/randomBaka.js'; -import userEndpoint from './controllers/utils/user.js'; - -const router = Router(); - -// 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'); -}); - -// Fact Endpoints -router.get('/api/fact', createRateLimiter(), randomFacts); -/** - * Retrieves a random fact from a predefined collection of facts. Requires authentication and is rate-limited to prevent abuse. - */ - -// Waifu Endpoint -router.get('/api/waifu', createRateLimiter(), randomWaifus); -/** - * Returns a randomly generated waifu character. Requires authentication and is rate-limited to manage the frequency of requests. - */ - -// Utils Endpoints -router.get('/api/password', createRateLimiter(), handleAuthentication, randomPasswords); -router.get('/api/alltags', createRateLimiter(), handleAuthentication, getAllTags); -router.get('/api/owoify', createRateLimiter(), handleAuthentication, getOwoify); -router.get('/api/uwuify', createRateLimiter(), handleAuthentication, getUwuify); -router.get('/api/uvuify', createRateLimiter(), handleAuthentication, getUvuify); -router.all('/api/user', createRateLimiter(), 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 ratelimit 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('/api/quote', createRateLimiter(), handleAuthentication, 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('/api/kick', createRateLimiter(), handleAuthentication, randomKick); -router.get('/api/kill', createRateLimiter(), handleAuthentication, randomKill); -router.get('/api/kiss', createRateLimiter(), handleAuthentication, randomKissu); -router.get('/api/midfing', createRateLimiter(), handleAuthentication, randomMidfing); -router.get('/api/nuzzle', createRateLimiter(), handleAuthentication, randomNuzzle); -router.get('/api/punch', createRateLimiter(), handleAuthentication, randomPunch); -router.get('/api/shoot', createRateLimiter(), handleAuthentication, randomShoot); -router.get('/api/sip', createRateLimiter(), handleAuthentication, randomSip); -router.get('/api/sleepy', createRateLimiter(), handleAuthentication, randomSleepy); -router.get('/api/smile', createRateLimiter(), handleAuthentication, randomSmile); -router.get('/api/stab', createRateLimiter(), handleAuthentication, randomStab); -router.get('/api/stare', createRateLimiter(), handleAuthentication, randomStare); -router.get('/api/suicide', createRateLimiter(), handleAuthentication, randomSuicide); -router.get('/api/tease', createRateLimiter(), handleAuthentication, randomTease); -router.get('/api/wag', createRateLimiter(), handleAuthentication, randomWag); -router.get('/api/bite', createRateLimiter(), handleAuthentication, randomBite); -router.get('/api/blush', createRateLimiter(), handleAuthentication, randomBlush); -router.get('/api/bonk', createRateLimiter(), handleAuthentication, randomBonk); -router.get('/api/bored', createRateLimiter(), handleAuthentication, randomBored); -router.get('/api/bully', createRateLimiter(), handleAuthentication, randomBully); -router.get('/api/bye', createRateLimiter(), handleAuthentication, randomBye); -router.get('/api/chase', createRateLimiter(), handleAuthentication, randomChase); -router.get('/api/cheer', createRateLimiter(), handleAuthentication, randomCheer); -router.get('/api/dab', createRateLimiter(), handleAuthentication, randomDab); -router.get('/api/die', createRateLimiter(), handleAuthentication, randomDie); -router.get('/api/disgust', createRateLimiter(), handleAuthentication, randomDisgust); -router.get('/api/feed', createRateLimiter(), handleAuthentication, randomFeed); -router.get('/api/hi', createRateLimiter(), handleAuthentication, randomHi); -router.get('/api/hold', createRateLimiter(), handleAuthentication, randomHold); -router.get('/api/hug', createRateLimiter(), handleAuthentication, randomHug); -router.get('/api/Nope', createRateLimiter(), handleAuthentication, randomNope); -router.get('/api/panic', createRateLimiter(), handleAuthentication, randomPanic); -router.get('/api/pat', createRateLimiter(), handleAuthentication, randomPat); -router.get('/api/peck', createRateLimiter(), handleAuthentication, randomPeck); -router.get('/api/poke', createRateLimiter(), handleAuthentication, randomPoke); -router.get('/api/punch', createRateLimiter(), handleAuthentication, randomPunch); -router.get('/api/pout', createRateLimiter(), handleAuthentication, randomPout); -router.get('/api/run', createRateLimiter(), handleAuthentication, randomRun); -router.get('/api/sad', createRateLimiter(), handleAuthentication, randomSad); -router.get('/api/shrug', createRateLimiter(), handleAuthentication, randomShrug); -router.get('/api/slap', createRateLimiter(), handleAuthentication, randomSlap); -router.get('/api/smug', createRateLimiter(), handleAuthentication, randomSmug); -router.get('/api/think', createRateLimiter(), handleAuthentication, randomThink); -router.get('/api/thumbsup', createRateLimiter(), handleAuthentication, randomThumbsup); -router.get('/api/tickle', createRateLimiter(), handleAuthentication, randomTickle); -router.get('/api/triggered', createRateLimiter(), handleAuthentication, randomTriggered); -router.get('/api/wave', createRateLimiter(), handleAuthentication, randomWave); -router.get('/api/wink', createRateLimiter(), handleAuthentication, randomWink); -router.get('/api/yes', createRateLimiter(), handleAuthentication, randomYes); -router.get('/api/angry', createRateLimiter(), handleAuthentication, randomAngry); -router.get('/api/cringe', createRateLimiter(), handleAuthentication, randomCringe); -router.get('/api/cry', createRateLimiter(), handleAuthentication, randomCry); -router.get('/api/cuddle', createRateLimiter(), handleAuthentication, randomCuddle); -router.get('/api/dance', createRateLimiter(), handleAuthentication, randomDance); -router.get('/api/facepalm', createRateLimiter(), handleAuthentication, randomFacepalm); -router.get('/api/glomp', createRateLimiter(), handleAuthentication, randomGlomp); -router.get('/api/happy', createRateLimiter(), handleAuthentication, randomHappy); -router.get('/api/highfive', createRateLimiter(), handleAuthentication, randomHighfive); -router.get('/api/hug', createRateLimiter(), handleAuthentication, randomHug); -router.get('/api/laugh', createRateLimiter(), handleAuthentication, randomLaugh); -router.get('/api/lick', createRateLimiter(), handleAuthentication, randomLick); -router.get('/api/love', createRateLimiter(), handleAuthentication, randomLove); -router.get('/api/lurk', createRateLimiter(), handleAuthentication, randomLurk); -router.get('/api/nervous', createRateLimiter(), handleAuthentication, randomNervous); -router.get('/api/nom', createRateLimiter(), handleAuthentication, randomNom); -router.get('/api/baka', createRateLimiter(), handleAuthentication, 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. - -export default router; diff --git a/src/routes/v3/index.js b/src/routes/v3/index.js new file mode 100644 index 0000000..1f5e587 --- /dev/null +++ b/src/routes/v3/index.js @@ -0,0 +1,223 @@ +/** + * This module defines the main routing logic for the API endpoints of the application. It utilizes the Express framework + * and various controllers v3/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 createRateLimiter() has been implemented to manage the frequency of requests and prevent abuse. The `authorize(config.roles.USER)` 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 + */ + +import { Router } from 'express'; +import createRateLimiter from '../../middlewares/rateLimit.js'; +import authorize from '../../middlewares/authorize.js'; +import randomFacts from '../../controllers/v3/facts/randomFacts.js'; +import getAllTags from '../../controllers/v3/utils/listTags.js'; +import getOwoify from '../../controllers/v3/utils/owoify.js'; +import getUwuify from '../../controllers/v3/utils/uwuify.js'; +import getUvuify from '../../controllers/v3/utils/uvuify.js'; +import randomWaifus from '../../controllers/v3/waifus/randomWaifus.js'; +import randomPasswords from '../../controllers/v3/utils/randomPassword.js'; +import randomQuotes from '../../controllers/v3/quotes/randomQuotes.js'; +import randomKick from '../../controllers/v3/gifs/randomKick.js'; +import randomKill from '../../controllers/v3/gifs/randomKill.js'; +import randomKissu from '../../controllers/v3/gifs/randomKissu.js'; +import randomMidfing from '../../controllers/v3/gifs/randomMidfing.js'; +import randomNuzzle from '../../controllers/v3/gifs/randomNuzzle.js'; +import randomPunch from '../../controllers/v3/gifs/randomPunch.js'; +import randomShoot from '../../controllers/v3/gifs/randomShoot.js'; +import randomSip from '../../controllers/v3/gifs/randomSip.js'; +import randomSleepy from '../../controllers/v3/gifs/randomSleepy.js'; +import randomSmile from '../../controllers/v3/gifs/randomSmile.js'; +import randomStab from '../../controllers/v3/gifs/randomStab.js'; +import randomStare from '../../controllers/v3/gifs/randomStare.js'; +import randomSuicide from '../../controllers/v3/gifs/randomSuicide.js'; +import randomTease from '../../controllers/v3/gifs/randomTease.js'; +import randomWag from '../../controllers/v3/gifs/randomWag.js'; +import randomBite from '../../controllers/v3/gifs/randomBite.js'; +import randomBlush from '../../controllers/v3/gifs/randomBlush.js'; +import randomBonk from '../../controllers/v3/gifs/randomBonk.js'; +import randomBored from '../../controllers/v3/gifs/randomBored.js'; +import randomBully from '../../controllers/v3/gifs/randomBully.js'; +import randomBye from '../../controllers/v3/gifs/randomBye.js'; +import randomChase from '../../controllers/v3/gifs/randomChase.js'; +import randomCheer from '../../controllers/v3/gifs/randomCheer.js'; +import randomDab from '../../controllers/v3/gifs/randomDab.js'; +import randomDie from '../../controllers/v3/gifs/randomDie.js'; +import randomDisgust from '../../controllers/v3/gifs/randomDisgust.js'; +import randomFeed from '../../controllers/v3/gifs/randomFeed.js'; +import randomHi from '../../controllers/v3/gifs/randomHi.js'; +import randomHold from '../../controllers/v3/gifs/randomHold.js'; +import randomHug from '../../controllers/v3/gifs/randomHug.js'; +import randomNope from '../../controllers/v3/gifs/randomNope.js'; +import randomPanic from '../../controllers/v3/gifs/randomPanic.js'; +import randomPat from '../../controllers/v3/gifs/randomPat.js'; +import randomPeck from '../../controllers/v3/gifs/randomPeck.js'; +import randomPoke from '../../controllers/v3/gifs/randomPoke.js'; +import randomPout from '../../controllers/v3/gifs/randomPout.js'; +import randomRun from '../../controllers/v3/gifs/randomRun.js'; +import randomSad from '../../controllers/v3/gifs/randomSad.js'; +import randomShrug from '../../controllers/v3/gifs/randomShrug.js'; +import randomSlap from '../../controllers/v3/gifs/randomSlap.js'; +import randomSmug from '../../controllers/v3/gifs/randomSmug.js'; +import randomThink from '../../controllers/v3/gifs/randomThink.js'; +import randomThumbsup from '../../controllers/v3/gifs/randomThumbsup.js'; +import randomTickle from '../../controllers/v3/gifs/randomTickle.js'; +import randomTriggered from '../../controllers/v3/gifs/randomTriggered.js'; +import randomWave from '../../controllers/v3/gifs/randomWave.js'; +import randomWink from '../../controllers/v3/gifs/randomWink.js'; +import randomYes from '../../controllers/v3/gifs/randomYes.js'; +import randomAngry from '../../controllers/v3/gifs/randomAngry.js'; +import randomCringe from '../../controllers/v3/gifs/randomCringe.js'; +import randomCry from '../../controllers/v3/gifs/randomCry.js'; +import randomCuddle from '../../controllers/v3/gifs/randomCuddle.js'; +import randomDance from '../../controllers/v3/gifs/randomDance.js'; +import randomFacepalm from '../../controllers/v3/gifs/randomFacepalm.js'; +import randomGlomp from '../../controllers/v3/gifs/randomGlomp.js'; +import randomHappy from '../../controllers/v3/gifs/randomHappy.js'; +import randomHighfive from '../../controllers/v3/gifs/randomHighfive.js'; +import randomLaugh from '../../controllers/v3/gifs/randomLaugh.js'; +import randomLick from '../../controllers/v3/gifs/randomLick.js'; +import randomLove from '../../controllers/v3/gifs/randomLove.js'; +import randomLurk from '../../controllers/v3/gifs/randomLurk.js'; +import randomNervous from '../../controllers/v3/gifs/randomNervous.js'; +import randomNom from '../../controllers/v3/gifs/randomNom.js'; +import randomBaka from '../../controllers/v3/gifs/randomBaka.js'; +import userEndpoint from '../../controllers/v3/utils/user.js'; + +const router = Router(); + +// 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'); +}); + +// Fact Endpoints +router.get('/api/fact', createRateLimiter(), authorize(config.roles.USER), randomFacts); +/** + * Retrieves a random fact from a predefined collection of facts. Requires authentication and is rate-limited to prevent abuse. + */ + +// Waifu Endpoint +router.get('/api/waifu', createRateLimiter(), authorize(config.roles.USER), randomWaifus); +/** + * Returns a randomly generated waifu character. Requires authentication and is rate-limited to manage the frequency of requests. + */ + +// Utils Endpoints +router.get('/api/password', createRateLimiter(), authorize(config.roles.USER), randomPasswords); +router.get('/api/alltags', createRateLimiter(), authorize(config.roles.USER), getAllTags); +router.get('/api/owoify', createRateLimiter(), authorize(config.roles.USER), getOwoify); +router.get('/api/uwuify', createRateLimiter(), authorize(config.roles.USER), getUwuify); +router.get('/api/uvuify', createRateLimiter(), authorize(config.roles.USER), getUvuify); +router.all('/api/user', createRateLimiter(), 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 ratelimit 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('/api/quote', createRateLimiter(), authorize(config.roles.USER), 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('/api/kick', createRateLimiter(), authorize(config.roles.USER), randomKick); +router.get('/api/kill', createRateLimiter(), authorize(config.roles.USER), randomKill); +router.get('/api/kiss', createRateLimiter(), authorize(config.roles.USER), randomKissu); +router.get('/api/midfing', createRateLimiter(), authorize(config.roles.USER), randomMidfing); +router.get('/api/nuzzle', createRateLimiter(), authorize(config.roles.USER), randomNuzzle); +router.get('/api/punch', createRateLimiter(), authorize(config.roles.USER), randomPunch); +router.get('/api/shoot', createRateLimiter(), authorize(config.roles.USER), randomShoot); +router.get('/api/sip', createRateLimiter(), authorize(config.roles.USER), randomSip); +router.get('/api/sleepy', createRateLimiter(), authorize(config.roles.USER), randomSleepy); +router.get('/api/smile', createRateLimiter(), authorize(config.roles.USER), randomSmile); +router.get('/api/stab', createRateLimiter(), authorize(config.roles.USER), randomStab); +router.get('/api/stare', createRateLimiter(), authorize(config.roles.USER), randomStare); +router.get('/api/suicide', createRateLimiter(), authorize(config.roles.USER), randomSuicide); +router.get('/api/tease', createRateLimiter(), authorize(config.roles.USER), randomTease); +router.get('/api/wag', createRateLimiter(), authorize(config.roles.USER), randomWag); +router.get('/api/bite', createRateLimiter(), authorize(config.roles.USER), randomBite); +router.get('/api/blush', createRateLimiter(), authorize(config.roles.USER), randomBlush); +router.get('/api/bonk', createRateLimiter(), authorize(config.roles.USER), randomBonk); +router.get('/api/bored', createRateLimiter(), authorize(config.roles.USER), randomBored); +router.get('/api/bully', createRateLimiter(), authorize(config.roles.USER), randomBully); +router.get('/api/bye', createRateLimiter(), authorize(config.roles.USER), randomBye); +router.get('/api/chase', createRateLimiter(), authorize(config.roles.USER), randomChase); +router.get('/api/cheer', createRateLimiter(), authorize(config.roles.USER), randomCheer); +router.get('/api/dab', createRateLimiter(), authorize(config.roles.USER), randomDab); +router.get('/api/die', createRateLimiter(), authorize(config.roles.USER), randomDie); +router.get('/api/disgust', createRateLimiter(), authorize(config.roles.USER), randomDisgust); +router.get('/api/feed', createRateLimiter(), authorize(config.roles.USER), randomFeed); +router.get('/api/hi', createRateLimiter(), authorize(config.roles.USER), randomHi); +router.get('/api/hold', createRateLimiter(), authorize(config.roles.USER), randomHold); +router.get('/api/hug', createRateLimiter(), authorize(config.roles.USER), randomHug); +router.get('/api/Nope', createRateLimiter(), authorize(config.roles.USER), randomNope); +router.get('/api/panic', createRateLimiter(), authorize(config.roles.USER), randomPanic); +router.get('/api/pat', createRateLimiter(), authorize(config.roles.USER), randomPat); +router.get('/api/peck', createRateLimiter(), authorize(config.roles.USER), randomPeck); +router.get('/api/poke', createRateLimiter(), authorize(config.roles.USER), randomPoke); +router.get('/api/punch', createRateLimiter(), authorize(config.roles.USER), randomPunch); +router.get('/api/pout', createRateLimiter(), authorize(config.roles.USER), randomPout); +router.get('/api/run', createRateLimiter(), authorize(config.roles.USER), randomRun); +router.get('/api/sad', createRateLimiter(), authorize(config.roles.USER), randomSad); +router.get('/api/shrug', createRateLimiter(), authorize(config.roles.USER), randomShrug); +router.get('/api/slap', createRateLimiter(), authorize(config.roles.USER), randomSlap); +router.get('/api/smug', createRateLimiter(), authorize(config.roles.USER), randomSmug); +router.get('/api/think', createRateLimiter(), authorize(config.roles.USER), randomThink); +router.get('/api/thumbsup', createRateLimiter(), authorize(config.roles.USER), randomThumbsup); +router.get('/api/tickle', createRateLimiter(), authorize(config.roles.USER), randomTickle); +router.get('/api/triggered', createRateLimiter(), authorize(config.roles.USER), randomTriggered); +router.get('/api/wave', createRateLimiter(), authorize(config.roles.USER), randomWave); +router.get('/api/wink', createRateLimiter(), authorize(config.roles.USER), randomWink); +router.get('/api/yes', createRateLimiter(), authorize(config.roles.USER), randomYes); +router.get('/api/angry', createRateLimiter(), authorize(config.roles.USER), randomAngry); +router.get('/api/cringe', createRateLimiter(), authorize(config.roles.USER), randomCringe); +router.get('/api/cry', createRateLimiter(), authorize(config.roles.USER), randomCry); +router.get('/api/cuddle', createRateLimiter(), authorize(config.roles.USER), randomCuddle); +router.get('/api/dance', createRateLimiter(), authorize(config.roles.USER), randomDance); +router.get('/api/facepalm', createRateLimiter(), authorize(config.roles.USER), randomFacepalm); +router.get('/api/glomp', createRateLimiter(), authorize(config.roles.USER), randomGlomp); +router.get('/api/happy', createRateLimiter(), authorize(config.roles.USER), randomHappy); +router.get('/api/highfive', createRateLimiter(), authorize(config.roles.USER), randomHighfive); +router.get('/api/hug', createRateLimiter(), authorize(config.roles.USER), randomHug); +router.get('/api/laugh', createRateLimiter(), authorize(config.roles.USER), randomLaugh); +router.get('/api/lick', createRateLimiter(), authorize(config.roles.USER), randomLick); +router.get('/api/love', createRateLimiter(), authorize(config.roles.USER), randomLove); +router.get('/api/lurk', createRateLimiter(), authorize(config.roles.USER), randomLurk); +router.get('/api/nervous', createRateLimiter(), authorize(config.roles.USER), randomNervous); +router.get('/api/nom', createRateLimiter(), authorize(config.roles.USER), randomNom); +router.get('/api/baka', createRateLimiter(), authorize(config.roles.USER), 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. + +export default router; diff --git a/src/routes/v4/index.js b/src/routes/v4/index.js new file mode 100644 index 0000000..fe896ae --- /dev/null +++ b/src/routes/v4/index.js @@ -0,0 +1,11 @@ +import { Router } from 'express'; +import factRoutes from './textUtilities/facts.js'; + +const router = Router(); +/** + * GET v1/docs + */ + +router.use('/fact', factRoutes); + +export default router; diff --git a/src/routes/v4/textUtilities/facts.js b/src/routes/v4/textUtilities/facts.js new file mode 100644 index 0000000..1d6fe8c --- /dev/null +++ b/src/routes/v4/textUtilities/facts.js @@ -0,0 +1,45 @@ +// routes/index.js +import { Router } from 'express'; +import getRandomFact from '../../../controllers/v3/facts/randomFacts.js'; +import authorize from '../../../middlewares/authorize.js'; +import incrementData from '../../../modules/database/add.js'; + +const router = Router(); + +router + .route('/') + /** + * @api {get} v4/fact Get a Random Fact + * @apiDescription Retrieve a random fact. + * @apiVersion 4.0.0 + * @apiName GetRandomFact + * @apiGroup Fact + * @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. + */ + .get(authorize(config.roles.USER), getRandomFact) + /** + * @api {post} v4/fact Increment Fact Data + * @apiDescription Increment data related to facts (only accessible by admins). + * @apiVersion 4.0.0 + * @apiName IncrementFactData + * @apiGroup Fact + * @apiPermission admin + * + * @apiHeader {String} Authorization Admin's access token. + * + * @apiSuccess {Object} result Result of the data incrementation. + * + * @apiError (Unauthorized 401) Unauthorized Only authenticated admins can access the data. + * @apiError (Forbidden 403) Forbidden Only admins can access the data. + */ + .post(authorize(config.roles.ADMIN), incrementData('Fact')); + +// Export the router +export default router; \ No newline at end of file