Skip to content

Commit

Permalink
Merge pull request #22 from AiriAPI/staging
Browse files Browse the repository at this point in the history
Added new baka endpoint and bumped the version
  • Loading branch information
kyrea authored Dec 6, 2021
2 parents 17d168b + d2e1022 commit d851e01
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "airi",
"version": "1.2.8",
"version": "1.3.8",
"description": "Random API Serving Anime stuff",
"author": "Aeryk",
"private": true,
Expand Down
28 changes: 28 additions & 0 deletions src/controllers/gifs/randomBaka.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const createError = require('http-errors')
const requestIp = require('request-ip')
const moment = require('moment')
const Baka = require('../../models/schemas/Baka')

// Get random Anime Baka
module.exports = async function getRandomBaka(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)
console.log(
`${req.method} | ${moment(Date.now()).format()} ${requestIp.getClientIp(
req
)} to ${req.path} - ${JSON.stringify(req.query)}`
)
} catch (error) {
return next(error)
}
}
2 changes: 2 additions & 0 deletions src/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const Smug = require('./schemas/Smug')
const Think = require('./schemas/Think')
const Thumbsup = require('./schemas/Thumbsup')
const Tickle = require('./schemas/Tickle')
const Baka = require('./schemas/Baka')

module.exports = {
Tags,
Expand Down Expand Up @@ -136,4 +137,5 @@ module.exports = {
Think,
Thumbsup,
Tickle,
Baka,
}
8 changes: 8 additions & 0 deletions src/models/schemas/Baka.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { Schema, model } = require('mongoose')

const BakaSchema = new Schema({
_id: { type: Number },
url: { type: String, required: true },
})

module.exports = model('Baka', BakaSchema)
2 changes: 2 additions & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const randomLove = require('./controllers/gifs/randomLove')
const randomLurk = require('./controllers/gifs/randomLurk')
const randomNervous = require('./controllers/gifs/randomNervous')
const randomNom = require('./controllers/gifs/randomNom')
const randomBaka = require('./controllers/gifs/randomBaka')

const router = Router()

Expand Down Expand Up @@ -163,5 +164,6 @@ router.get('/api/love', Limiter, authHandler, randomLove)
router.get('/api/lurk', Limiter, authHandler, randomLurk)
router.get('/api/nervous', Limiter, authHandler, randomNervous)
router.get('/api/nom', Limiter, authHandler, randomNom)
router.get('/api/baka', Limiter, authHandler, randomBaka)

module.exports = router

0 comments on commit d851e01

Please sign in to comment.