Compare commits

..

No commits in common. "a5799e4b48c5ca86274aa1589568e9bb879fd553" and "6d3ed58526a3476543b3d6024ca19ab3c600f7a8" have entirely different histories.

5 changed files with 4 additions and 22 deletions

View file

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

View file

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

View file

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

View file

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

View file

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