commit b7d9b4f104c8236bef1ac148b37d8fdeddcc883f Author: TheRedXD Date: Tue Mar 14 21:57:14 2023 +0200 funny init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a820a04 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +yarn.lock +node_modules +package-lock.json +yarn-error.log +uploads +*.env \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..9562acd --- /dev/null +++ b/index.js @@ -0,0 +1,82 @@ +import express from 'express'; +import fs from 'fs'; +import multer from "multer"; +import path from 'path'; +import crypto from 'crypto'; +import blueutilities from 'blueutilities'; + +const __dirname = path.resolve(); + +const app = express(); +app.use(multer().single("file")) +// body-parser +// app.use(express.raw({limit: '100mb',type: 'application/octet-stream'})); +// app.use(express.urlencoded({ extended: false })); +// app.use(express.urlencoded({extended: false, limit: '5mb'})); + +if(!fs.existsSync('uploads')) { + fs.mkdirSync('uploads'); +} + +app.get("/", (req, res) => { + res.send("helo") +}) +app.get('/:name', (req, res) => { + if(req.headers['user-agent'].toLowerCase().includes("discord")) { + res.header("facts", "tencent is crab").redirect("/i/" + req.params.name); // discord trolling + // (redirects discord to the full image url) + } + if(blueutilities.random.numBetween(0, 100) == 68) { + res.send("Among"); + } + res.send(` + + `); +}); + +app.post('/upload', (req, res) => { + // save file with a randomized name and send back the name to the client + // so that the client can use the name to retrieve the file + let fileName; + while(!fileName || fs.existsSync(path.join(__dirname, 'uploads', fileName))) { + fileName = crypto.randomBytes(16).toString("hex") + ".png"; + } + const filePath = path.join(__dirname, 'uploads', fileName); + + const fileData = req.file.buffer; // try now + + fs.writeFile(filePath, fileData, (err) => { + if (err) { + console.log(err); + res.status(500).send('error'); + return; + } + + res.send({ + success: true, + fileName: fileName, + fullURL: `${req.protocol}://${req.headers.host}/${fileName}` + }); + }); +}); +app.use('i', express.static(path.join(__dirname, "uploads"))) + +app.use((req, res, next) => { + res.status(418).send("418 crab not found"); +}); + +app.listen(3000, () => { + console.log('stupid uploader is run'); +}); \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..fc99be6 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "dependencies": { + "blueutilities": "^1.2.2", + "express": "^4.18.2", + "multer": "^1.4.5-lts.1" + }, + "name": "image_uploader", + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "type": "module" +}