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'); });