Skip to content

Commit

Permalink
Merge fsh-org/fastify
Browse files Browse the repository at this point in the history
Fastify
  • Loading branch information
inventionpro authored Dec 15, 2024
2 parents 96f29b3 + 4a6549e commit 11ac985
Show file tree
Hide file tree
Showing 58 changed files with 1,903 additions and 1,087 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Replit
.replit
old.replit
replit.nix

# Logs
logs
*.log
Expand Down
25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Open Fsh 1.0
Released: 09/09/24 (dd/mm/yy)\
Authored: Fsh org\
You can find the original license at https://github.com/fsh-org/Open-Fsh-license

## Disclaimer
This is not a open source license as of version 1.9 of the [open source definition](https://opensource.org/osd), it is a source-available license.

## 1. Modification / Derivations
You may fork, copy, modify, and or change any part of the licensed material provided, all changed aspects shall fall under the same license.

## 2. Distribution
You may distribute the licensed material, you must not monetize the distributed licensed material.

## 3. Use
You may use the licensed material for any purposes, you must not monetize use of the licensed material but may monetize your material.
- You can't: Free softwere but pay to use the licensed material.
- You can: Free softwere and free usage of license material.
- You can: Paid softwere but licensed material at no additional cost.

## 4. Credit
You must credit the original authors with the name or online name and a link to the the source visible in clear easy to read text next to the parts used or in a general credits page.

## 5. Warranty
The licensed material is distributed "AS IS", without warranty of any kind or type, in no event shall the authors be liable for any claim, damages or other caused or related to the oicensed material.
6 changes: 3 additions & 3 deletions apis/ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {

async execute(req, res) {
if (!req.body || !req.body.length) {
res.error('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 @@ -27,8 +27,8 @@ module.exports = {
})
})
})
.catch(err => {
res.error('Could not generate')
.catch(() => {
res.error('Could not generate', 500);
return;
})
}
Expand Down
10 changes: 2 additions & 8 deletions apis/animal.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
// No option :(
if (!req.query["animal"]) {
let opt = ["Cat", "Dog", "Fox", "Duck", "Frog", "Bunny", "Fish", "Alpaca", "Bird"].sort();
res.send(`Avaible animals:<br>- ${opt.join("<br>- ")}`);
res.type('text/html').send(`Avaible animals:<br>- ${opt.join("<br>- ")}`);
return;
}
// Yes option :)
Expand Down Expand Up @@ -52,14 +52,8 @@ module.exports = {
})
break;
case 'frog':
let uu = Math.floor(Math.random() * 54 + 1);
if (uu.length == 1) {
uu = "000" + uu
} else {
uu = "00" + uu
}
res.json({
image: 'http://allaboutfrogs.org/funstuff/random/'+uu+'.jpg'
image: `http://allaboutfrogs.org/funstuff/random/${String(Math.floor(Math.random() * 54 + 1)).padStart(4, '0')}.jpg`
})
break;
case 'bunny':
Expand Down
27 changes: 14 additions & 13 deletions apis/ascii.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,31 @@ module.exports = {
type: 'get',
params: [],
category: "image",

async execute(req, res) {
if (!req.body || !req.body.length) {
res.error('You must pass a image in the request body')
res.error('You must pass a image in the request body');
return;
}

let image = sharp(req.body);

let { width, height } = await image
.metadata()
.catch(err => {
res.error('Could not read')
.catch(() => {
res.error('Could not read');
return;
});

let w = width;
let h = height;
let f = 6;
if ((w*h) > 1000000) {
f = Math.ceil(1 / (1000000 / (w*h)))*6;
let f = 1;
let s = 8;
if ((w*h) > 20000) {
f = Math.sqrt(20000 / (w*h));
}
w = Math.floor(width/f);
h = Math.floor(height/f);
w = Math.floor(w*f);
h = Math.floor(h*f);

let { data } = await image
.resize(w, h, { fit: 'fill' })
Expand All @@ -40,14 +41,14 @@ module.exports = {
const chars = '@%#*+=-:. ';
const charMult = chars.length - 1;

let asciiArt = `<svg xmlns="http://www.w3.org/2000/svg" width="${w*f}" height="${(h-1)*f}"><rect width="100%" height="100%" fill="#fff"/>`;
let asciiArt = `<svg xmlns="http://www.w3.org/2000/svg" width="${w*s}" height="${(h-1)*s}"><rect width="100%" height="100%" fill="#fff"/>`;
for (let y = 0; y < h; y++) {
for (let x = 0; x < w; x++) {
let idx = (y * w + x) * 3;

let brightness = (data[idx] + data[idx + 1] + data[idx + 2]) / 3;

asciiArt += `<text x="${x*f}" y="${y*f}" font-family="monospace" font-size="${f*1.5}" fill="black">${chars[Math.floor(brightness / 255 * charMult)]}</text>`;
asciiArt += `<text x="${x*s}" y="${y*s}" font-family="Arial" font-size="${s*1.2}" fill="black">${chars[Math.floor(brightness / 255 * charMult)]}</text>`;
}
}
asciiArt += '</svg>';
Expand All @@ -60,8 +61,8 @@ module.exports = {
image: 'data:image/png;base64,' + outputBuffer.toString('base64')
})
})
.catch(err => {
res.error('Could not generate')
.catch(() => {
res.error('Could not generate', 500);
return;
});
}
Expand Down
8 changes: 4 additions & 4 deletions apis/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
let id = req.query['id'];

if (!id || !ytdl.validateID(id)) {
res.error('Invalid id')
res.error('Invalid id');
return;
}

Expand All @@ -45,11 +45,11 @@ module.exports = {
download: `https://api.fsh.plus/download/audio/${id}.mp3`
})
})
.on('error', (error) => {
res.error('Could not download')
.on('error', () => {
res.error('Could not download', 500);
});
} catch (err) {
res.error('Could not download')
res.error('Could not download', 500);
}
}
}
6 changes: 3 additions & 3 deletions apis/bi.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {

async execute(req, res) {
if (!req.body || !req.body.length) {
res.error('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,8 +31,8 @@ module.exports = {
})
})
})
.catch(err => {
res.error('Could not generate')
.catch(() => {
res.error('Could not generate', 500);
return;
})
}
Expand Down
6 changes: 3 additions & 3 deletions apis/biden.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ module.exports = {

async execute(req, res) {
if (!req.query['text']) {
res.error('You must pass a image in the request body')
res.error('You must include text');
return;
}
let text = req.query['text'];
let svg = `<svg style="width: 555px; height: 120px;"><text y="41" font-family="Arial" font-size="12px" fill="#000"><tspan x="60" dy="0px">${text.split('\\n').join('</tspan><tspan x="60" dy="10px">')}</tspan></text></svg>`;

sharp('effects/biden.png')
.composite([{
input: Buffer.from(svg),
Expand All @@ -32,7 +32,7 @@ module.exports = {
image: 'data:image/png;base64,' + outputBuffer.toString('base64')
})
})
.catch(err => {
.catch(() => {
res.error('Could not generate')
return;
})
Expand Down
10 changes: 5 additions & 5 deletions apis/blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ module.exports = {

async execute(req, res) {
if (!req.body || !req.body.length) {
res.error('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.error('Force too big')
res.error('Force too big');
return;
}
if (Number(req.query['force']) < 1) {
res.error('Force too small')
res.error('Force too small');
return;
}
sharp(req.body)
Expand All @@ -34,8 +34,8 @@ module.exports = {
image: 'data:image/png;base64,' + outputBuffer.toString('base64')
})
})
.catch(err => {
res.error('Could not generate')
.catch(() => {
res.error('Could not generate', 500);
return;
})
}
Expand Down
7 changes: 3 additions & 4 deletions apis/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ module.exports = {
cache = dat
}
let hex = req.query['hex'];
if ([3,4].includes(hex.length)) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + (hex[3]||'') + (hex[3]||'')
}
if (!hex) {
var keys = Object.keys(cache);
hex = keys[ keys.length * Math.random() << 0];
} else if ([3,4].includes(hex.length)) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2] + (hex[3]??'') + (hex[3]??'')
}
res.json({
hex: '#'+hex,
name: cache[hex.slice(0,6)] || 'Unknown',
name: cache[hex.slice(0,6)] ?? 'Unknown',
preview: 'https://api.fsh.plus/colour?hex='+hex
})
}
Expand Down
17 changes: 13 additions & 4 deletions apis/colorify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ module.exports = {

async execute(req, res) {
if (!req.query['hex']) {
res.error('You must include a hex param (no #)')
res.error('You must include a hex param (no #)');
return;
}
if (!req.body || !req.body.length) {
res.error('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 @@ -33,6 +33,7 @@ module.exports = {
background: req.query['hex'] ? '#'+req.query['hex'] : '#f00'
}
})
.png()
.toBuffer()
.then(buff => {
sharp(req.body)
Expand All @@ -45,10 +46,18 @@ module.exports = {
image: 'data:image/png;base64,' + outputBuffer.toString('base64')
})
})
.catch(() => {
res.error('Could not generate', 500);
return;
})
})
.catch(() => {
res.error('Could not create color layer', 500);
return;
})
})
.catch(err => {
res.error('Could not generate')
.catch(() => {
res.error('Could not read image', 500);
return;
})
}
Expand Down
3 changes: 1 addition & 2 deletions apis/colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ module.exports = {
.jpeg()
.toBuffer()
.then(data => {
res.set('Content-Type', 'image/jpeg');
res.send(data);
res.type('image/jpeg').send(data);
})
} catch(err) {
res.error('Could not generate')
Expand Down
6 changes: 3 additions & 3 deletions apis/communism.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {

async execute(req, res) {
if (!req.body || !req.body.length) {
res.error('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,8 +31,8 @@ module.exports = {
})
})
})
.catch(err => {
res.error('Could not generate')
.catch(() => {
res.error('Could not generate', 500);
return;
})
}
Expand Down
10 changes: 5 additions & 5 deletions apis/deepfry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {

async execute(req, res) {
if (!req.body || !req.body.length) {
res.error('You must pass a image in the request body')
res.error('You must pass a image in the request body');
return;
}

Expand Down Expand Up @@ -44,13 +44,13 @@ module.exports = {
image: 'data:image/png;base64,' + outputBuffer.toString('base64')
})
})
.catch(err => {
res.error('Could not generate')
.catch(() => {
res.error('Could not generate', 500);
return;
})
})
.catch(err => {
res.error('Could not generate')
.catch(() => {
res.error('Could not generate', 500);
return;
})
})
Expand Down
Loading

0 comments on commit 11ac985

Please sign in to comment.