Compare commits

...

2 commits

Author SHA1 Message Date
Kfir Dayan
a5799e4b48 passing result to DB service 2023-04-18 13:29:39 +03:00
Kfir Dayan
661d5e9880 db add 2023-04-18 13:23:34 +03:00
5 changed files with 22 additions and 4 deletions

View file

@ -1,11 +1,16 @@
import { Body, Controller, Post } from '@nestjs/common';
import { CrawlerService } from '../crawler/crawler.service';
import { DbService } from '../db/db.service';
@Controller('/')
export class ApiController {
constructor(private crawlerService: CrawlerService) {}
constructor(private crawlerService: CrawlerService, private DbService: DbService) {}
@Post('crawl')
async crawl(@Body() body: { url: string }) {
return this.crawlerService.crawl(body.url);
const results = this.crawlerService.crawl(body.url);
results.then((data) => {
console.log(data)
this.DbService.insert(data, 'crawler');
});
}
}

View file

@ -1,10 +1,11 @@
import { Module } from '@nestjs/common';
import { ApiController } from './api.controller';
import { CrawlerService } from '../crawler/crawler.service';
import { DbService } from '../db/db.service';
@Module({
controllers: [ApiController],
providers: [CrawlerService]
providers: [CrawlerService, DbService]
})
export class ApiModule {}

View file

@ -1,8 +1,9 @@
import { Module } from '@nestjs/common';
import { ApiModule } from './api/api.module';
import { CrawlerModule } from './crawler/crawler.module';
import { DbModule } from './db/db.module';
@Module({
imports: [ApiModule, CrawlerModule]
imports: [ApiModule, CrawlerModule, DbModule]
})
export class AppModule {}

View file

@ -42,6 +42,10 @@ export class CrawlerService {
// URLS //
const urls = await page.$$eval('a', links => links.map(link => link.href));
await browser.close();
return {
cssSheetsLocation,
scriptsSheetsLocation
}
}
async downloadFiles(urls: string[], path: string) {

View file

@ -5,4 +5,11 @@ export class DbService {
constructor() {
console.log(`DbService constructor`);
}
insert(data: {
cssSheetsLocation: string[];
scriptsSheetsLocation: string[];
}, collection: string) {
console.log({data, collection});
}
}