mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-09-25 06:05:52 +02:00
Update express
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { uniq, compact } from 'lodash';
|
||||
import { hex } from 'color-convert';
|
||||
import convert from 'color-convert';
|
||||
import { getDeltaE00, LAB } from 'delta-e';
|
||||
import { repeat } from '../common/utils';
|
||||
import { CM_SIZE } from '../common/constants';
|
||||
@@ -417,7 +417,7 @@ const patterns = [
|
||||
];
|
||||
|
||||
export function hexToLab(c: string): LAB {
|
||||
const [L, A, B] = hex.lab(c);
|
||||
const [L, A, B] = convert.hex.lab(c);
|
||||
return { L, A, B };
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Request, Response, NextFunction, RequestHandler } from 'express';
|
||||
import { Request, Response, RequestHandler } from 'express';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as moment from 'moment';
|
||||
import * as ExpressBrute from 'express-brute';
|
||||
import rateLimit from 'express-rate-limit';
|
||||
import { noop } from 'lodash';
|
||||
import { HASH } from '../generated/hash';
|
||||
import { isAdmin } from '../common/accountUtils';
|
||||
@@ -96,19 +96,18 @@ export const admin = (server: ServerConfig): RequestHandler => (req, res, next)
|
||||
}
|
||||
};
|
||||
|
||||
const store = new ExpressBrute.MemoryStore();
|
||||
|
||||
export function limit(freeRetries: number, lifetime: number) {
|
||||
const options: any = {
|
||||
freeRetries,
|
||||
lifetime,
|
||||
failCallback(req: Request, res: Response, _next: NextFunction, nextValidRequestDate: any) {
|
||||
const limiter = rateLimit({
|
||||
windowMs: lifetime * 1000,
|
||||
max: freeRetries,
|
||||
handler(req, res) {
|
||||
logger.warn(`rate limit ${req.url} ${req.ip}`);
|
||||
res.status(429).send(`Too many requests, please try again ${moment(nextValidRequestDate).fromNow()}`);
|
||||
const retryAfter = moment(Date.now() + lifetime * 1000).fromNow();
|
||||
res.status(429).send(`Too many requests, please try again ${retryAfter}`);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
return (new (ExpressBrute as any)(store, options)).prevent;
|
||||
return limiter;
|
||||
}
|
||||
|
||||
function reportError(e: Error, server: ServerConfig, req: Request) {
|
||||
|
||||
+10
-10
@@ -293,19 +293,19 @@ if (args.admin) {
|
||||
const adminSocket = host.socket(AdminServerActions, ClientAdminActionsTemplate, createClient, socketOptionsBase);
|
||||
const sendAdminPage = index.admin(production, `${base}/`, assetsBase, 'bootstrap-admin.js', adminSocket);
|
||||
|
||||
app.use(`${base}`, ...adminMiddlewares(), sendAdminPage);
|
||||
app.get(`${base}`, ...adminMiddlewares(), sendAdminPage);
|
||||
app.get(`${base}/*`, ...adminMiddlewares(), sendAdminPage);
|
||||
}
|
||||
|
||||
if (args.tools) {
|
||||
const toolsPage = index.user(
|
||||
production, '/tools/', 'style-tools.css', 'bootstrap-tools.js', 'bootstrap-tools.js', undefined, true, !!args.local, false);
|
||||
|
||||
app.use('/tools', ...sessionMiddlewares(), auth, (_, res) => res.send(toolsPage.page));
|
||||
app.get('/tools', ...sessionMiddlewares(), auth, (_, res) => res.send(toolsPage.page));
|
||||
app.get('/tools/*', ...sessionMiddlewares(), auth, (_, res) => res.send(toolsPage.page));
|
||||
|
||||
app.use('/api-tools', ...sessionMiddlewares(), apiTools(server, settings, theWorld));
|
||||
app.get('/api-tools/*', (_, res) => res.sendStatus(404));
|
||||
app.get('/api-tools', (_, res) => res.sendStatus(404));
|
||||
}
|
||||
|
||||
if (args.login) {
|
||||
@@ -343,14 +343,14 @@ if (args.login) {
|
||||
const loginApi = createInternalLoginApi(settings, liveSettings, stats, reloadSettings, removedDocument);
|
||||
app.use('/api-internal-login', internal(config, server), wrapApi(server, loginApi));
|
||||
|
||||
app.get('/assets-admin/*', notFound);
|
||||
app.get('/assets/*', notFound);
|
||||
app.get('/auth/*', notFound);
|
||||
app.get('/api/*', notFound);
|
||||
app.get('/api1/*', notFound);
|
||||
app.get('/api2/*', notFound);
|
||||
app.use('/assets-admin', notFound);
|
||||
app.use('/assets', notFound);
|
||||
app.use('/auth', notFound);
|
||||
app.use('/api', notFound);
|
||||
app.use('/api1', notFound);
|
||||
app.use('/api2', notFound);
|
||||
|
||||
app.get('/*', (req, res) => {
|
||||
app.use((req, res) => {
|
||||
if (settings.isPageOffline) {
|
||||
res.send(offlinePage);
|
||||
} else {
|
||||
|
||||
Vendored
-15
@@ -49,18 +49,3 @@ declare module 'timsort' {
|
||||
export function sort<T>(array: T[], compare: (a: T, b: T) => number): void;
|
||||
}
|
||||
|
||||
declare module 'color-convert' {
|
||||
export const hex: {
|
||||
lab(color: string): [number, number, number];
|
||||
};
|
||||
}
|
||||
|
||||
declare module 'delta-e' {
|
||||
export interface LAB {
|
||||
L: number;
|
||||
A: number;
|
||||
B: number;
|
||||
}
|
||||
|
||||
export function getDeltaE00(a: LAB, b: LAB): number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user