0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2024-12-22 05:12:57 -05:00

add optimizations

This commit is contained in:
dragongoose 2023-03-07 17:54:53 -05:00
parent 3cd74145e0
commit f1c771282d
2 changed files with 17 additions and 17 deletions

View file

@ -5,6 +5,8 @@
"dotenv": "^16.0.3",
"express": "^4.18.2",
"puppeteer": "^19.7.2",
"puppeteer-extra": "^3.3.6",
"puppeteer-extra-plugin-adblocker": "^2.13.6",
"winston": "^3.8.2"
},
"devDependencies": {

View file

@ -1,8 +1,14 @@
import { Router } from 'express'
import puppeteer, { Browser, Page } from 'puppeteer'
import puppeteer from 'puppeteer-extra'
import { Browser, Page } from 'puppeteer'
import { PuppeteerExtraPluginAdblocker } from 'puppeteer-extra-plugin-adblocker'
import { LooseObject } from '../../types/looseTypes'
import { Streamlink } from '@dragongoose/streamlink'
puppeteer.use(new PuppeteerExtraPluginAdblocker({
blockTrackersAndAnnoyances: true
}))
const profileRouter = Router()
export interface Socials {
@ -30,6 +36,7 @@ export interface StreamerData {
stream?: StreamData
}
const abbreviatedNumberToNumber = (num: string) => {
const base = parseFloat(num)
@ -65,22 +72,13 @@ const withBrowser = async (fn: Function) => {
const withPage = (browser: Browser) => async (fn: Function) => {
const page = await browser.newPage();
//turns request interceptor on
await page.setRequestInterception(true);
//if the page makes a request to a resource type of image or stylesheet then abort that request
page.on('request', request => {
if (request.resourceType() === 'image')
request.abort();
else
request.continue();
});
try {
return await fn(page);
} finally {
await page.close();
}
//await page.tracing.start({ path: '../profile.json', screenshots: true });
try {
return await fn(page);
} finally {
//await page.tracing.stop();
await page.close();
}
}
let isLive: boolean