diff --git a/src/routes/log.ts b/src/routes/log.ts index 1ae31abc..0256fcd0 100644 --- a/src/routes/log.ts +++ b/src/routes/log.ts @@ -10,7 +10,7 @@ const timeInputProcessor = (timestamp: string): number => { } function sanitizeSqlPayload(input: string): string { - return input.replace(/'/g, "''"); + return input.replace(/'/g, "''") } type SQLFiltersParam = { diff --git a/src/server.ts b/src/server.ts index 9cdad9a7..acbe4be4 100644 --- a/src/server.ts +++ b/src/server.ts @@ -79,13 +79,16 @@ app.set('trust proxy', true) app.use(cors({ methods: ['POST'] })) app.use(express.json()) app.use(cookieParser()) -app.use(function(req, res, next) { - res.setHeader('X-Content-Type-Options', 'nosniff'); - res.setHeader('Permissions-Policy', 'accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), unload=(), window-placement=(), vertical-scroll=()'); - res.setHeader('X-Frame-Options', 'SAMEORIGIN'); - res.setHeader('Content-Security-Policy', "default-src 'self'"); - next(); -}); +app.use(function (req, res, next) { + res.setHeader('X-Content-Type-Options', 'nosniff') + res.setHeader( + 'Permissions-Policy', + 'accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), unload=(), window-placement=(), vertical-scroll=()' + ) + res.setHeader('X-Frame-Options', 'SAMEORIGIN') + res.setHeader('Content-Security-Policy', "default-src 'self'") + next() +}) if (config.dashboard.enabled && config.dashboard.dist_path) { const clientDirectory = diff --git a/src/utils.ts b/src/utils.ts index c07e1f60..72bf056a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -142,12 +142,12 @@ export async function updateNodeList(tryInfinate = false): Promise<void> { //const promises = nodes.map(checkIfNodeIsActive) //dont blast all requests at once const concurrentRequests = 50 - const semaphore = new Semaphore(concurrentRequests); - const results: boolean[] = new Array(nodes.length).fill(false); + const semaphore = new Semaphore(concurrentRequests) + const results: boolean[] = new Array(nodes.length).fill(false) const waitForAllPromise = new Deferred<void>() let finished = 0 - for(let i=0; i<nodes.length; i++) { + for (let i = 0; i < nodes.length; i++) { const node = nodes[i] //promises.push(checkIfNodeIsActive(node)) //not stacking up promises //@ts-ignore what are we using es5 for? @@ -1804,49 +1804,48 @@ export function hexToBN(hexString: string): BN { return new BN(hexString, 16) } - class Semaphore { - private queue: (() => void)[] = []; - private value: number; + private queue: (() => void)[] = [] + private value: number constructor(maxConcurrency: number) { - this.value = maxConcurrency; + this.value = maxConcurrency } async wait(): Promise<void> { return new Promise<void>((resolve) => { const tryAcquire = () => { if (this.value > 0) { - this.value--; - resolve(); + this.value-- + resolve() } else { - this.queue.push(tryAcquire); + this.queue.push(tryAcquire) } - }; - tryAcquire(); - }); + } + tryAcquire() + }) } signal(): void { - this.value++; + this.value++ if (this.queue.length > 0) { - const next = this.queue.shift(); + const next = this.queue.shift() if (next) { - next(); + next() } } } } class Deferred<T> { - public promise: Promise<T>; - public resolve!: (value: T | PromiseLike<T>) => void; - public reject!: (reason?: any) => void; + public promise: Promise<T> + public resolve!: (value: T | PromiseLike<T>) => void + public reject!: (reason?: any) => void constructor() { this.promise = new Promise<T>((resolve, reject) => { - this.resolve = resolve; - this.reject = reject; - }); + this.resolve = resolve + this.reject = reject + }) } -} \ No newline at end of file +}