This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import express, { NextFunction } from "express";
|
||||
import { getLogin, getTrusted } from "../auth";
|
||||
import { getLogin } from "../auth";
|
||||
import { parseToken } from "../utils";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
@@ -34,16 +34,11 @@ function generateUrl() {
|
||||
*/
|
||||
function getEasterEggImage(req: any, res: any, next: NextFunction) {
|
||||
const login = getLogin(parseToken(req));
|
||||
const trusted = getTrusted(parseToken(req));
|
||||
try {
|
||||
// TODO vrátit!
|
||||
// if (trusted) {
|
||||
if (true) {
|
||||
if (login in easterEggs) {
|
||||
const imagePath = easterEggs[login][Math.floor(Math.random() * easterEggs[login].length)].path;
|
||||
res.sendFile(path.join(__dirname, IMAGES_PATH, imagePath));
|
||||
return;
|
||||
}
|
||||
if (login in easterEggs) {
|
||||
const imagePath = easterEggs[login][Math.floor(Math.random() * easterEggs[login].length)].path;
|
||||
res.sendFile(path.join(__dirname, IMAGES_PATH, imagePath));
|
||||
return;
|
||||
}
|
||||
res.sendStatus(404);
|
||||
} catch (e: any) { next(e) }
|
||||
@@ -124,7 +119,7 @@ let easterEggs: EasterEggsJson;
|
||||
if (fs.existsSync(EASTER_EGGS_JSON_PATH)) {
|
||||
const content = fs.readFileSync(EASTER_EGGS_JSON_PATH, 'utf-8');
|
||||
easterEggs = JSON.parse(content);
|
||||
for (const [key, eggs] of Object.entries(easterEggs)) {
|
||||
for (const [_, eggs] of Object.entries(easterEggs)) {
|
||||
for (const easterEgg of eggs) {
|
||||
const url = generateUrl();
|
||||
easterEgg.url = url;
|
||||
@@ -138,16 +133,11 @@ if (fs.existsSync(EASTER_EGGS_JSON_PATH)) {
|
||||
// Získání náhodného easter eggu pro přihlášeného uživatele
|
||||
router.get("/", async (req, res, next) => {
|
||||
const login = getLogin(parseToken(req));
|
||||
const trusted = getTrusted(parseToken(req));
|
||||
try {
|
||||
// TODO vrátit!
|
||||
// if (trusted) {
|
||||
if (true) {
|
||||
if (easterEggs && login in easterEggs) {
|
||||
const randomEasterEgg = easterEggs[login][Math.floor(Math.random() * easterEggs[login].length)];
|
||||
const { path, startOffset, endOffset, ...strippedEasterEgg } = randomEasterEgg; // Path klient k ničemu nepotřebuje a nemá ho znát
|
||||
return res.status(200).json({ ...strippedEasterEgg, ...getRandomPosition(startOffset, endOffset) });
|
||||
}
|
||||
if (easterEggs && login in easterEggs) {
|
||||
const randomEasterEgg = easterEggs[login][Math.floor(Math.random() * easterEggs[login].length)];
|
||||
const { path, startOffset, endOffset, ...strippedEasterEgg } = randomEasterEgg; // Path klient k ničemu nepotřebuje a nemá ho znát
|
||||
return res.status(200).json({ ...strippedEasterEgg, ...getRandomPosition(startOffset, endOffset) });
|
||||
}
|
||||
return res.status(200).send();
|
||||
} catch (e: any) { next(e) }
|
||||
|
||||
Reference in New Issue
Block a user