Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

Commit

Permalink
Added public key creation, restyled img page to match uploader, added…
Browse files Browse the repository at this point in the history
… logging bc anyone can make a key now lol
  • Loading branch information
big cock committed Aug 20, 2023
1 parent 7f3f524 commit 1bf0618
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
uploads
node_modules
keys.json
upload-log.json
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use strict";

interface Config {
port: number;
dirs: string[];
keys: string[];
}

const config: Config = {
port: 8080,
dirs: ["suicidey", "pp", "kms", "fbi", "cia", "666", "777"],
keys: ["fuckurmom"],
};

export default config;
1 change: 1 addition & 0 deletions src/keys.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
51 changes: 41 additions & 10 deletions src/pages/img.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script
Expand All @@ -10,10 +11,7 @@
integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns"
crossorigin="anonymous"
></script>
<link
rel="stylesheet"
href="https://cdn.upload.systems/assets/css/argon.css"
/>

<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="/api/content/raw/<%=name%>" />
<meta name="twitter:image:src" content="/api/content/raw/<%=name%>" />
Expand All @@ -40,6 +38,44 @@
margin-top: 10%;
background: #04010a;
}
body.bg-dark {
background-color: #04010a !important;
}
.row.mt-5.no-gutters {
margin-top: 5% !important;
}
.col-md-6.mx-2 {
width: 75vw !important;
margin: 0 auto !important;
}
.text-center.bg-dark.mb-4 {
background-color: #04010a !important;
margin-bottom: 4% !important;
}
.card-body {
padding: 1.25rem !important;
}
h1 {
font-size: 2.5rem !important;
}
img {
max-height: 75vh !important;
width: auto !important;
max-width: 100% !important;
border-radius: 0.25rem !important;
}
a[style="text-decoration: none; color: #5865f2"] {
text-decoration: none !important;
color: #5865f2 !important;
}
</style>
<body class="bg-dark">
<div class="row mt-5 no-gutters">
Expand All @@ -59,14 +95,9 @@
<img
src="/api/content/raw/<%=name%>"
alt="Click here to download/open the file."
style="
max-height: 75vh;
width: auto;
max-width: 100%;
border-radius: 0.25rem;
"
/>
</a>
<br />
<center>
<a
style="text-decoration: none; color: #5865f2"
Expand Down
48 changes: 31 additions & 17 deletions src/pages/uploader.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,26 @@
<p id="key-button" style="font-size: 0.9em">Login →</p>

<p style="margin-top: 30px; color: grey">
If you would like to request an API key, join our
If you would like to request an API key,
<a
style="color: grey; text-decoration: none"
href="https://tritan.gg/http"
>Discord</a
style="color: grey; text-decoration: none; cursor: pointer"
id="request-key-link"
>click here</a
>.
</p>
</div>

<div id="dropzone" style="display: none">Drop an image here to upload.</div>

<div id="link"></div>

<script>
$(document).ready(function () {
const dropzone = $("#dropzone");
let apiKey = localStorage.getItem("apiKey") || "";
const login = $("#login");
let apiKey = localStorage.getItem("uploader_apiKey") || "";
const domains = [
"https://im.sleepdeprived.wtf",
"https://ur.sleepdeprived.wtf",
Expand All @@ -87,21 +91,34 @@
"https://because.horny.rip",
];
function setApiKey(key) {
apiKey = key;
localStorage.setItem("uploader_apiKey", apiKey);
$("#key-input").val(apiKey);
}
$("#key-input").val(apiKey);
$("#key-button").click(function () {
apiKey = $("#key-input").val();
if (!apiKey) {
const inputKey = $("#key-input").val();
if (!inputKey) {
alert("Please enter an API key.");
return;
}
localStorage.setItem("apiKey", apiKey);
$("#login").hide();
setApiKey(inputKey);
login.hide();
dropzone.show();
});
$("#request-key-link").click(function () {
$.post("/api/create", function (data) {
setApiKey(data.key);
alert(
`Your API key is ${data.key}. It has been copied to your clipboard.`
);
});
});
dropzone.on({
dragover: function () {
dropzone.css("background-color", "#eee");
Expand Down Expand Up @@ -133,11 +150,10 @@
success: function (data) {
const domain =
domains[Math.floor(Math.random() * domains.length)];
const link = domain + data.url;
$("#link")
.html(`<a href="${link}">${link}</a>`)
.addClass("link");
$("#link").append(`<a href="${link}">${link}</a><br>`);
},
error: function (xhr, status, error) {
Expand Down Expand Up @@ -166,9 +182,7 @@
domains[Math.floor(Math.random() * domains.length)];
const link = `${domain}/${data.url}`;
$("#link")
.html(`<a href="${link}">${link}</a>`)
.addClass("link");
$("#link").append(`<a href="${link}">${link}</a><br>`);
},
error: function (xhr, status, error) {
Expand Down
48 changes: 48 additions & 0 deletions src/routes/api/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Router, Request, Response } from "express";
import fs from "fs";

const router = Router();

router.post("/", (req: Request, res: Response) => {
try {
const ip = req.headers["x-forwarded-for"] || req.socket.remoteAddress;
const keys = JSON.parse(fs.readFileSync("keys.json", "utf8"));

const newKey = {
key: generateRandomKey(10),
created_at: new Date().toISOString(),
ip: ip,
};

keys.push(newKey);

fs.writeFileSync("keys.json", JSON.stringify(keys, null, 2));

res.send({
status: 200,
message: "Key created successfully.",
key: newKey.key,
});
} catch (err) {
console.error(`Failed to create key: ${err}`);
res.status(500).send({
status: 500,
message: "Failed to create key.",
error: err,
});
}
});

function generateRandomKey(length: number): string {
const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
let result = "";

for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}

return result;
}

export default router;
32 changes: 26 additions & 6 deletions src/routes/api/upload.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"use strict";

import { Router, type Request, type Response } from "express";
import { Router, Request, Response } from "express";
import path from "path";
import config from "../../config";
import fs from "fs";

interface UploadedFile {
name: string;
Expand All @@ -28,10 +27,12 @@ router.post("/", (req: Request, res: Response) => {
key: string;
};

if (!config.keys.includes(key)) {
const keys = JSON.parse(fs.readFileSync("keys.json", "utf8"));

if (!keys.some((k: { key: string }) => k.key === key)) {
return res.status(403).send({
status: 403,
message: "Invalid token, get fucked dumbass.",
message: "Invalid key retard.",
});
}

Expand All @@ -48,6 +49,7 @@ router.post("/", (req: Request, res: Response) => {
const ext = path.extname(singleSharex.name);
const name = generateRandomName(10);
const dir = config.dirs[Math.floor(Math.random() * config.dirs.length)];
const ip = req.headers["x-forwarded-for"] || req.socket.remoteAddress;

singleSharex.mv(`./uploads/${name}${ext}`, (err: Error | null) => {
if (err) {
Expand All @@ -58,7 +60,25 @@ router.post("/", (req: Request, res: Response) => {
});
}

console.log(`${key} just uploaded ${name + ext}`);
console.log(`${key} just uploaded ${name + ext} from ${ip}.`);

const logEntry = {
ip: ip,
key: key,
fileName: name + ext,
timestamp: new Date().toISOString(),
};

const existingLogs = JSON.parse(
fs.readFileSync("upload-log.json", "utf8")
);

existingLogs.push(logEntry);

fs.writeFileSync(
"upload-log.json",
JSON.stringify(existingLogs, null, 2)
);

res.send({
status: 200,
Expand Down
2 changes: 2 additions & 0 deletions src/routes/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import express, {
} from "express";
import imageRouter from "./index";
import uploadRouter from "./api/upload";
import createKey from "./api/create";

const router: Router = express.Router();

Expand All @@ -18,6 +19,7 @@ router.use("*", (req: Request, res: Response, next: NextFunction) => {

router.use("/", imageRouter);
router.use("/api/upload", uploadRouter);
router.use("/api/create", createKey);

router.use("*", (req: Request, res: Response, error: any) => {
return res.status(error ? 500 : 404).json({
Expand Down
1 change: 1 addition & 0 deletions src/upload-log.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]

0 comments on commit 1bf0618

Please sign in to comment.