Skip to content

Commit

Permalink
remove some useless comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMario211 committed Sep 1, 2024
1 parent da7f295 commit 23836fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 78 deletions.
53 changes: 0 additions & 53 deletions server/src/controllers/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,6 @@ const allowedTags = ["Font", "Decoration", "Gameplay", "Art", "Structure", "Cust

const oRouter = Router();

/*
async function rateObject(redisClient: RedisClientType, objectID: string, userID: string, rating: number) {
const ratingKey = `objects:${objectID}:ratings`;
await redisClient.hSet(ratingKey, userID, rating);
}
async function calculateAverageRating(redisClient: RedisClientType, objectID: number): Promise<number> {
const ratingKey = `objects:${objectID}:ratings`;
const ratings = await redisClient.hGetAll(ratingKey);
const totalRatings: number = Object.values(ratings).reduce((acc, rating) => acc + parseInt(rating), 0);
const numberOfRatings = Object.keys(ratings).length;
return numberOfRatings > 0 ? totalRatings / numberOfRatings : 0;
}
async function calculateAverageRating(pool: PoolClient, articleID: number): Promise<number> {
const query = `
SELECT AVG(rating) AS average_rating
FROM ratings
WHERE article_id = $1;
`;
const values = [articleID];
try {
const res = await pool.query(query, values);
const averageRating = parseFloat(res.rows[0].average_rating);
return isNaN(averageRating) ? 0 : averageRating;
} catch (err: any) {
console.error('Error executing query', err.stack);
throw err;
}
}
function dataToObjectData(redisClient: RedisClientType, data: ObjectData): Promise<ObjectData> {
return new Promise((resolve, reject) => {
data.timestamp = new Date(data.timestamp as number);
data.tags = data.tags.toString().split(",");
calculateAverageRating(redisClient, data.id).then(avgRatings => {
data.rating = avgRatings;
resolve(data);
}).catch(reject);
})
}*/

const isAscii: CustomValidator = (value: string) => {
return /^[\x00-\x7F]*$/.test(value); // Checks if all characters are within the ASCII range
};
Expand Down Expand Up @@ -166,16 +123,6 @@ oRouter.post('/objects/upload',
});
}
);
/*
oRouter.post('/:room/upload', validator.body('username').notEmpty().isString(), validator.body('ext').notEmpty().isString(), validator.body('file').notEmpty().isString(), (req, res) => {
const roomID = req.params.room;
if (!roomID) res.sendStatus(400);
const result = validator.validationResult(req);
if (!result.isEmpty()) return res.status(400).json({ errors: result.array() })
uploadImage(req, res, false)
})
})
*/

oRouter.get('/objects/:id', param("id").isNumeric().notEmpty(), (req: Request, res: Response) => {
const result = validationResult(req);
Expand Down
30 changes: 5 additions & 25 deletions server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,19 @@ app.use(express.raw({ limit: '80mb' }));
app.use(morgan('combined'));

app.all("/", (_, res) => {
res.send("hi my name is firee")
res.sendStatus(200)
})
/*
auto ref = CCSprite::create("fanmade3.png"_spr);
//this->addChild(ref);
ref->setOpacity(255 / 4);
ref->setPosition({285, 160});
ref->setScale(1.29F);
*/
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

const simulateLatency = (delay: number) => {
return (req: Request, res: Response, next: NextFunction) => {
setTimeout(() => {
next();
}, delay);
};
};

const limiter = rateLimit({
windowMs: 3 * 60 * 1000, // 15 minutes
limit: 200, // Limit each IP to 100 requests per `window` (here, per 15 minutes).
standardHeaders: 'draft-7', // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header
legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
// store: ... , // Redis, Memcached, etc. See below.
windowMs: 3 * 60 * 1000,
limit: 200,
standardHeaders: 'draft-7',
legacyHeaders: false,
message: { error: "You are ratelimited!" }
})

// Apply the rate limiting middleware to all requests.
app.use(limiter)

//app.use(simulateLatency(100));

app.use(uRouter);
app.use(oRouter);

Expand Down

0 comments on commit 23836fc

Please sign in to comment.