check if phpbb is installed

This commit is contained in:
Alexander Yakovlev 2023-03-22 08:21:45 +07:00
parent 2c7f1a8e56
commit 12fe66e790
1 changed files with 20 additions and 7 deletions

27
urq.js
View File

@ -51,11 +51,6 @@ export default class Urq {
this.db = await mysql.createConnection(this.dbopts);
this.browser = await puppeteer.launch({
"headless": true,
"args": [
"--disable-web-security",
"--no-sandbox",
"--disable-dev-shm-usage"
]
});
await this.db.execute(`
CREATE TABLE IF NOT EXISTS \`${config.DB_PREFIX}bordathreads\` (
@ -64,7 +59,17 @@ export default class Urq {
\`name\` Varchar(255) NOT NULL,
PRIMARY KEY ( \`id\` )
);`);
// await this.scrape_pages();
try {
let [threadrow, fields] = await this.db.execute(
`SELECT COUNT(*) FROM \`${config.DB_PREFIX}posts\``
);
} catch (e) {
console.error('Please install phpbb first.');
await this.browser.close();
return;
}
await this.scrape_pages();
await this.scrape_threads();
await this.browser.close();
};
@ -107,12 +112,20 @@ export default class Urq {
for (let i = 0; i < threads.length; i++) {
try {
let [rows, fields] = await this.db.execute(`
let [threadrow, fields] = await this.db.execute(`
SELECT \`id\` FROM \`${config.DB_PREFIX}bordathreads\`
WHERE \`url\` = ?
`,[
threads[i].url,
]);
if (threadrow.length === 0) {
let [rows, fields] = await this.db.execute(`
INSERT INTO ${config.DB_PREFIX}bordathreads (url, name) VALUES( ?, ? )
`, [
threads[i].url,
threads[i].name,
]);
}
} catch(e) {
console.log(e);
}