Wrote the stuff

main
transbitch 2023-09-09 01:11:03 -04:00
parent 0d25fe117a
commit f9bc223ee1
9 changed files with 6851 additions and 0 deletions

5
.firebaserc 100644
View File

@ -0,0 +1,5 @@
{
"projects": {
"default": "megamind-ip-grabber"
}
}

16
README.md 100644
View File

@ -0,0 +1,16 @@
# Megamind says your IP!
## As seen on rDrama
make your own funni grabber!
setup:
```
cd functions
npm i
```
to deploy:
```
cd functions
tsc
firebase deploy
```

14
firebase.json 100644
View File

@ -0,0 +1,14 @@
{
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
]
}

9
functions/.gitignore vendored 100644
View File

@ -0,0 +1,9 @@
# Compiled JavaScript files
lib/**/*.js
lib/**/*.js.map
# TypeScript v1 declaration files
typings/
# Node.js dependency directory
node_modules/

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

6735
functions/package-lock.json generated 100644

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
{
"name": "functions",
"scripts": {
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "lib/index.js",
"dependencies": {
"canvas-gif": "^1.0.3",
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.3.1"
},
"devDependencies": {
"firebase-functions-test": "^3.1.0",
"typescript": "^4.9.0"
},
"private": true
}

View File

@ -0,0 +1,30 @@
import {onRequest} from "firebase-functions/v2/https";
import {readFile} from 'fs/promises';
import canvasGif from 'canvas-gif';
const megamindGif = readFile('megamind.gif');
export const megamind = onRequest({ cors: true }, async (request, response) => {
const ip = request.ip;
const res = await fetch('http://ip-api.com/json/' + ip);
const { city, country } = await res.json();
// Test info (localhost doesn't have ip obv)
/*
const ip = '0.0.0.0';
const city = 'FakeCity';
const country = 'FakeCountry';
*/
const gif = await canvasGif(await megamindGif, (ctx, width, height, totalFrames, currFrame) => {
if (currFrame >= 10) {
ctx.font = 'bold 40px sans-serif';
ctx.fillStyle = 'white';
ctx.fillText(ip, 20, height - 60);
ctx.fillText(`${city}, ${country}`, 20, height - 20);
}
}, { fps: 30 });
response.contentType('gif');
response.send(gif);
});

View File

@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
},
"compileOnSave": true,
"include": [
"src"
]
}