Skip to content

Commit

Permalink
ran format-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TieDyedSheep committed Jul 19, 2024
1 parent df06ebc commit 0f51b27
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/routes/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const timeInputProcessor = (timestamp: string): number => {
}

function sanitizeSqlPayload(input: string): string {
return input.replace(/'/g, "''");
return input.replace(/'/g, "''")
}

type SQLFiltersParam = {
Expand Down
17 changes: 10 additions & 7 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
45 changes: 22 additions & 23 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
})
}
}
}

0 comments on commit 0f51b27

Please sign in to comment.