From 0f51b27baef17e7988d884d410d3cb1014c832f7 Mon Sep 17 00:00:00 2001 From: Caralee Jackson Date: Fri, 19 Jul 2024 13:22:03 -0500 Subject: [PATCH] ran format-fix --- src/routes/log.ts | 2 +- src/server.ts | 17 ++++++++++------- src/utils.ts | 45 ++++++++++++++++++++++----------------------- 3 files changed, 33 insertions(+), 31 deletions(-) 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 { //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() let finished = 0 - for(let i=0; i void)[] = []; - private value: number; + private queue: (() => void)[] = [] + private value: number constructor(maxConcurrency: number) { - this.value = maxConcurrency; + this.value = maxConcurrency } async wait(): Promise { return new Promise((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 { - public promise: Promise; - public resolve!: (value: T | PromiseLike) => void; - public reject!: (reason?: any) => void; + public promise: Promise + public resolve!: (value: T | PromiseLike) => void + public reject!: (reason?: any) => void constructor() { this.promise = new Promise((resolve, reject) => { - this.resolve = resolve; - this.reject = reject; - }); + this.resolve = resolve + this.reject = reject + }) } -} \ No newline at end of file +}