Skip to content

Commit

Permalink
Added rmqr, md5 | New error system | Modernized old apis
Browse files Browse the repository at this point in the history
  • Loading branch information
inventionpro committed Jul 24, 2024
1 parent 9ffb284 commit e87397c
Show file tree
Hide file tree
Showing 62 changed files with 474 additions and 718 deletions.
11 changes: 2 additions & 9 deletions apis/ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ module.exports = {

async execute(req, res) {
if (!req.body || !req.body.length) {
res.json({
err: true,
msg: 'You must pass a image in the request body'
})
res.error('You must pass a image in the request body')
return;
}
sharp(req.body)
Expand All @@ -31,11 +28,7 @@ module.exports = {
})
})
.catch(err => {
console.log(err)
res.json({
err: true,
msg: 'Could not generate'
})
res.error('Could not generate')
return;
})
}
Expand Down
45 changes: 33 additions & 12 deletions apis/animal.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = {
type: 'get',
params: ["animal", true],
category: "image",
async execute(req, res){

async execute(req, res) {
// No option :(
if (!req.query["animal"]) {
let opt = ["Cat", "Dog", "Fox", "Duck", "Frog", "Bunny", "Shibe", "Fish", "Alpaca", "Bird"].sort();
Expand All @@ -22,19 +23,27 @@ module.exports = {
switch (req.query["animal"]) {
case 'cat':
img = await getIM("https://api.thecatapi.com/v1/images/search")
res.send(`{"image": "${img[0].url}"}`)
res.json({
image: img[0].url
})
break;
case 'dog':
img = await getIM("https://dog.ceo/api/breeds/image/random")
res.send(`{"image": "${img.message.replaceAll('\\','')}"}`)
res.json({
image: img.message.replaceAll('\\','')
})
break;
case 'fox':
img = await getIM("https://randomfox.ca/floof/")
res.send(`{"image": "${img.image.replaceAll('\\','')}"}`)
res.json({
image: img.image.replaceAll('\\','')
})
break;
case 'duck':
img = await getIM("https://random-d.uk/api/v1/random")
res.send(`{"image": "${img.url}"}`)
res.json({
image: img.url
})
break;
case 'frog':
let uu = Math.floor(Math.random() * 54 + 1);
Expand All @@ -43,30 +52,42 @@ module.exports = {
} else {
uu = "00" + uu
}
res.send(`{"image": "http://allaboutfrogs.org/funstuff/random/${uu}.jpg"}`)
res.json({
image: 'http://allaboutfrogs.org/funstuff/random/'+uu+'.jpg'
})
break;
case 'bunny':
img = await getIM("https://api.bunnies.io/v2/loop/random/?media=gif,png")
res.send(`{"image": "${img.media[Math.random() > 0.3 ? "poster" : "gif"]}"}`)
res.json({
image: img.media[Math.random() > 0.3 ? "poster" : "gif"]
})
break;
case 'shibe':
img = await getIM("https://shibe.online/api/shibes")
res.send(`{"image": "${img[0]}"}`)
res.json({
image: img[0]
})
break;
case 'fish':
img = await getIM("https://api.sefinek.net/api/v2/random/animal/fish")
res.send(`{"image": "${img.message}"}`)
res.json({
image: img.message
})
break;
case 'alpaca':
img = await getIM("https://api.sefinek.net/api/v2/random/animal/alpaca")
res.send(`{"image": "${img.message}"}`)
res.json({
image: img.message
})
break;
case 'bird':
img = await getIM("https://api.sefinek.net/api/v2/random/animal/bird")
res.send(`{"image": "${img.message}"}`)
res.json({
image: img.message
})
break;
default:
res.send('{"error": true, "msg": "invalid animal"}')
res.error('Invalid animal')
}
}
}
15 changes: 3 additions & 12 deletions apis/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ module.exports = {
let id = req.query['id'];

if (!id || !ytdl.validateID(id)) {
res.json({
err: true,
msg: 'Invalid id'
})
res.error('Invalid id')
return;
}

Expand Down Expand Up @@ -43,16 +40,10 @@ module.exports = {
})
})
.on('error', (error) => {
res.json({
err: true,
msg: 'Could not download'
})
res.error('Could not download')
});
} catch (err) {
res.json({
err: true,
msg: 'Could not download'
})
res.error('Could not download')
}
}
}
4 changes: 2 additions & 2 deletions apis/base.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
path: '/page', // path to website, remember to add /
info: 'info', // for later thing
path: '/page', // path to website, remember to add / in front
info: 'info', // info shown in main page
type: 'get', // http type (get, post, etc) (just visual does nothing)
params: ["h", true], // params if no params put []
category: "hidden", // category (only some appear in menu)
Expand Down
31 changes: 11 additions & 20 deletions apis/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,30 @@ module.exports = {
path: '/base64',
info: 'Encode and decode base64 and utf8 (set type to encode/dedcode)',
type: 'get',
params: ["type", true, "text", true],
params: ['type', true, 'text', true],
category: "text",
execute(req, res){

async execute(req, res) {
if (!req.query["type"]) {
res.status(400)
res.json({
err: true,
msg: "No conversion type recived"
})
res.error('No conversion type recived')
return;
}
if (!req.query["text"]) {
res.status(400)
res.json({
err: true,
msg: "No text recived"
})
res.error('No text recived')
return;
}
if (req.query["type"] == "encode") {
res.send(`{"text": "${Buffer.from(req.query["text"], 'UTF8').toString('Base64')}"}`)
if (req.query["type"] === "encode") {
res.json({
text: Buffer.from(req.query["text"], 'UTF8').toString('Base64')
})
return;
}
if (req.query["type"] == "decode") {
if (req.query["type"] === "decode") {
res.json({
text: Buffer.from(req.query["text"], 'Base64').toString('UTF8')
})
return;
}
res.status(400)
res.json({
err: true,
msg: "type not valid"
})
res.error('Type not valid')
}
}
26 changes: 10 additions & 16 deletions apis/bi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ module.exports = {

async execute(req, res) {
if (!req.body || !req.body.length) {
res.json({
err: true,
msg: 'You must pass a image in the request body'
})
res.error('You must pass a image in the request body')
return;
}
sharp(req.body)
Expand All @@ -23,22 +20,19 @@ module.exports = {
.toBuffer()
.then(buff => {
sharp(req.body)
.composite([
{ input: buff, gravity: 'center', blend: 'screen' }
])
.toBuffer()
.then(outputBuffer => {
res.json({
image: 'data:image/png;base64,' + outputBuffer.toString('base64')
.composite([
{ input: buff, gravity: 'center', blend: 'screen' }
])
.toBuffer()
.then(outputBuffer => {
res.json({
image: 'data:image/png;base64,' + outputBuffer.toString('base64')
})
})
})
})
})
.catch(err => {
res.json({
err: true,
msg: 'Could not generate'
})
res.error('Could not generate')
return;
})
}
Expand Down
11 changes: 2 additions & 9 deletions apis/biden.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ module.exports = {

async execute(req, res) {
if (!req.query['text']) {
res.json({
err: true,
msg: 'You must pass a image in the request body'
})
res.error('You must pass a image in the request body')
return;
}
let text = req.query['text'];
Expand All @@ -30,11 +27,7 @@ module.exports = {
})
})
.catch(err => {
console.log(err)
res.json({
err: true,
msg: 'Could not generate'
})
res.error('Could not generate')
return;
})
}
Expand Down
35 changes: 14 additions & 21 deletions apis/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,30 @@ module.exports = {
path: '/binary',
info: 'Encode and decode binary and utf8 (set type to encode/dedcode)',
type: 'get',
params: ["type", true, "text", true],
params: ['type', true, 'text', true],
category: "text",
execute(req, res){

async execute(req, res){
if (!req.query["type"]) {
res.status(400)
res.json({
err: true,
msg: "No conversion type recived"
})
res.error('No conversion type recived')
return;
}
if (!req.query["text"]) {
res.status(400)
res.json({
err: true,
msg: "No text recived"
})
res.error('No text recived')
return;
}
if (req.query["type"] == "encode") {
res.send(`{"text": "${toBin(req.query["text"])}"}`)
if (req.query["type"] === "encode") {
res.json({
text: toBin(req.query["text"])
})
return;
}
if (req.query["type"] == "decode") {
res.send(`{"text": "${toStr(req.query["text"])}"}`)
if (req.query["type"] === "decode") {
res.json({
text: toStr(req.query["text"])
})
return;
}
res.status(400)
res.json({
err: true,
msg: "type not valid"
})
res.error('Type not valid')
}
}
20 changes: 4 additions & 16 deletions apis/blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,15 @@ module.exports = {

async execute(req, res) {
if (!req.body || !req.body.length) {
res.json({
err: true,
msg: 'You must pass a image in the request body'
})
res.error('You must pass a image in the request body')
return;
}
if (Number(req.query['force']) > 1000) {
res.json({
err: true,
msg: 'Force too big'
})
res.error('Force too big')
return;
}
if (Number(req.query['force']) < 1) {
res.json({
err: true,
msg: 'Force too small'
})
res.error('Force too small')
return;
}
sharp(req.body)
Expand All @@ -38,10 +29,7 @@ module.exports = {
})
})
.catch(err => {
res.json({
err: true,
msg: 'Could not generate'
})
res.error('Could not generate')
return;
})
}
Expand Down
Loading

0 comments on commit e87397c

Please sign in to comment.