Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Max2408 authored May 2, 2021
0 parents commit 68c19ee
Show file tree
Hide file tree
Showing 29 changed files with 1,599 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Src/Controllers/Animals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
exports.cat = async(req, res, next) => {
try{
const data = require('../Data/Animals/Cat.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
image : randomData.image,
fact: randomData.fact
})
}catch(error){
res.status(500).json({
"error": error
})
}


}

exports.dog = async(req, res, next) => {
try{
const data = require('../Data/Animals/Dog.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
image : randomData.image,
fact: randomData.fact
})
}catch(error){
res.status(500).json({
"error": error
})
}

}

exports.panda = async(req, res, next) => {
try{
const data = require('../Data/Animals/Panda.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
image : randomData.image,
fact: randomData.fact
})
}catch(error){
res.status(500).json({
"error": error
})
}

}
106 changes: 106 additions & 0 deletions Src/Controllers/Images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
const { Canvas } = require('canvas-constructor')
const canvas = require('canvas')

exports.delete = async(req, res, next) => {
try{
const bg = await canvas.loadImage('https://cdn.max2408.ml/assets/api/delete.png')

if(!req.query.image){
res.status(400).json({
"error" : true,
"code": 400,
"message": "no image was provide."
})
return next();
}

let pngChecker = req.query.image.endsWith('.png')
let jpgChecker = req.query.image.endsWith('.jpg')

if(req.query.image.endsWith('.png') === true){
let logo = await canvas.loadImage(req.query.image)

let image = new Canvas(550, 267)
.printImage(bg, 0, 0, 550, 267)
.printImage(logo, 95 , 105 , 135 , 135)
.toBuffer();

res.set({'Content-Type': 'image/png'})
res.send(image)
}else if(req.query.image.endsWith('.jpg') === true){
let logo = await canvas.loadImage(req.query.image)

let image = new Canvas(550, 267)
.printImage(bg, 0, 0, 550, 267)
.printImage(logo, 95 , 105 , 135 , 135)
.toBuffer();

res.set({'Content-Type': 'image/png'})
res.send(image)
}else{
res.status(400).json({
"error" : true,
"code": 400,
"message": "only jpg or png type of images are allowed."
})
return next();
}
}catch(error){
console.log(error)
res.status(500).json({
"error": error
})
}
}

exports.ad = async(req, res, next) => {
try{
const bg = await canvas.loadImage('https://cdn.max2408.ml/assets/api/ad.png')

if(!req.query.image){
res.status(400).json({
"error" : true,
"code": 400,
"message": "no image was provide."
})
return next();
}

let pngChecker = req.query.image.endsWith('.png')
let jpgChecker = req.query.image.endsWith('.jpg')

if(req.query.image.endsWith('.png') === true){
let logo = await canvas.loadImage(req.query.image)

let image = new Canvas(550, 474)
.printImage(logo, 150 , 75 , 230 , 230)
.printImage(bg, 0, 0, 550, 474)
.toBuffer();

res.set({'Content-Type': 'image/png'})
res.send(image)
}else if(req.query.image.endsWith('.jpg') === true){
let logo = await canvas.loadImage(req.query.image)

let image = new Canvas(550, 474)
.printImage(logo, 150 , 75 , 230 , 230)
.printImage(bg, 0, 0, 550, 474)
.toBuffer();

res.set({'Content-Type': 'image/png'})
res.send(image)
}else{
res.status(400).json({
"error" : true,
"code": 400,
"message": "only jpg or png type of images are allowed."
})
return next();
}
}catch(error){
console.log(error)
res.status(500).json({
"error": error
})
}
}
87 changes: 87 additions & 0 deletions Src/Controllers/Meme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
exports.meirl = async(req, res, next) => {
try{
const data = require('../Data/Memes/meirl.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
title: randomData.title,
url: randomData.url,
category: randomData.category
})
}catch(error){
res.status(500).json({
"error": error
})
}
}

exports.minion = async(req, res, next) => {
try{
const data = require('../Data/Memes/minion.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
title: randomData.title,
url: randomData.url,
category: randomData.category
})
}catch(error){
res.status(500).json({
"error": error
})
}
}


exports.dank = async(req, res, next) => {
try{
const data = require('../Data/Memes/dank.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
title: randomData.title,
url: randomData.url,
category: randomData.category
})
}catch(error){
res.status(500).json({
"error": error
})
}
}


exports.allmeme = async(req, res, next) => {
try{
const data1 = require('../Data/Memes/minion.json')
const data2 = require('../Data/Memes/meirl.json')
const data3 = require('../Data/Memes/dank.json')

let randomData1 = data1[Math.floor(Math.random() * data1.length)]

let randomData2 = data2[Math.floor(Math.random() * data2.length)]

let randomData3 = data3[Math.floor(Math.random() * data3.length)]

let possible = ['data1' , 'data2' , 'data3']

let resultPossible = possible[Math.floor(Math.random() * possible.length)]

let output

if(resultPossible === 'data1'){
output = randomData1
}else if(resultPossible === 'data2'){
output = randomData2
}else if(resultPossible === 'data3'){
output = randomData3
}

res.status(200).json({
title: output.title,
url: output.url,
category: output.category
})
}catch(error){
res.status(500).json({
"error": error
})
}
}
147 changes: 147 additions & 0 deletions Src/Controllers/Others.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
function randomStr(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}

exports.joke = async(req, res, next) => {
try{
const data = require('../data/joke.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
joke : randomData.joke,
type: randomData.type
})
}catch(error){
res.status(500).json({
"error": error
})
}
}

exports.insults = async(req, res, next) => {
try{
const data = require('../data/insults.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
insult : randomData.insult,
})
}catch(error){
res.status(500).json({
"error": error
})
}
}

exports.truth = async(req, res, next) => {
try{
const data = require('../data/Truth.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
truth : randomData.truth,
})
}catch(error){
res.status(500).json({
"error": error
})
}
}

exports.dare = async(req, res, next) => {
try{
const data = require('../data/Dare.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
dare : randomData.dare,
})
}catch(error){
res.status(500).json({
"error": error
})
}
}

exports.quotes = async(req, res, next) => {
try{
const data = require('../data/quote.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
quote : randomData.quote,
type: randomData.type,
author: randomData.author
})
}catch(error){
res.status(500).json({
"error": error
})
}
}

exports.uselessweb = async(req, res, next) => {
try{
const data = require('../data/uselessweb.json')
let randomData = data[Math.floor(Math.random() * data.length)]
res.status(200).json({
url : randomData.url
})
}catch(error){
res.status(500).json({
"error": error
})
}
}


exports.number = async(req, res, next) => {
try{
let randomNumber = Math.floor(Math.random() * 9999999)
res.status(200).json({
"number" : randomNumber
})
}catch(error){
res.status(500).json({
"error": error
})
}
}

exports.password = async(req, res, next) => {
try{
if(!req.query.length){
res.status(400).json({
"error" : true,
"code": 400,
"message": "length of the password wasn't specified."
})
return next();
}

var regExp = /[a-zA-Z]/g;
var string = req.query.length

if(regExp.test(string)){
res.status(400).json({
"error" : true,
"code": 400,
"message": "length query must be a number."
})
return next();
} else {
let password = randomStr(req.query.length)
res.status(200).json({
"password" : password,
"length": req.query.length,
"note" : "These passwords are never stored and are generated randomly"
})
}
}catch(error){
console.log(error)
res.status(500).json({
"error": error
})
}
}
Loading

0 comments on commit 68c19ee

Please sign in to comment.