Skip to content

Commit

Permalink
Merge pull request #244 from Quickchive/feature-#243/crawl-og-data
Browse files Browse the repository at this point in the history
[Feature] Og 데이터 크롤링
  • Loading branch information
stae1102 authored Jan 28, 2024
2 parents 7060c15 + cd415dc commit 78e4b41
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/contents/contents.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import {
LoadPersonalContentsOutput,
} from './dtos/load-personal-contents.dto';
import { LoadReminderCountOutput } from './dtos/load-personal-remider-count.dto';
import { GetLinkInfoResponseDto } from './dtos/get-link.response.dto';

@Controller('contents')
@ApiTags('Contents')
Expand Down Expand Up @@ -256,6 +257,19 @@ export class ContentsController {
return this.contentsService.loadReminderCount(user);
}

@ApiOperation({
summary: 'OG 데이터 크롤링',
description: '링크 내 OG 데이터를 파싱합니다.',
})
@ApiOkResponse({
type: GetLinkInfoResponseDto,
})
@UseGuards(JwtAuthGuard)
@Get('/og')
async getOgData(@Query('link') link: string) {
return this.contentsService.getLinkInfo(link);
}

@ApiOperation({
summary: '콘텐츠 문서 요약',
description: '콘텐츠의 문서를 요약하는 메서드',
Expand Down
7 changes: 7 additions & 0 deletions src/contents/contents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { CategoryUtil } from './util/category.util';
import { CategoryRepository } from './repository/category.repository';
import { ContentUtil } from './util/content.util';
import { OpenaiService } from '../openai/openai.service';
import { GetLinkInfoResponseDto } from './dtos/get-link.response.dto';

@Injectable()
export class ContentsService {
Expand Down Expand Up @@ -406,6 +407,12 @@ export class ContentsService {
}
}

async getLinkInfo(link: string) {
const data = await this.contentUtil.getLinkInfo(link);

return new GetLinkInfoResponseDto(data);
}

async testSummarizeContent({
title,
content: document,
Expand Down
37 changes: 37 additions & 0 deletions src/contents/dtos/get-link.response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { LinkInfo } from '../types/link-info.interface';

export class GetLinkInfoResponseDto {
@ApiProperty({
description: '아티클 제목',
example: '[Terraform] 테라폼 훑어보기 — 턴태의 밑바닥부터 시작하는 de-vlog',
})
private readonly title: string;

@ApiProperty({
description: '아티클 본문 일부',
example:
'인프라 구조마저 코드로 조작하고 있는 현재, 가장 많이 쓰이는 도구는 테라폼과 앤서블이 있습니다.',
})
private readonly description: string;

@ApiProperty({
description: '썸네일/커버 이미지',
example:
'https://img1.daumcdn.net/thumb/R800x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fz52vz%2FbtsCAOBzgTR%2FhFgGDKkr6iKWfU6eKeKUVk%2Fimg.png',
})
private readonly coverImg: string;

@ApiPropertyOptional({
description: '아티클 사이트 주소',
example: '턴태의 밑바닥부터 시작하는 de-vlog',
})
private readonly siteName?: string;

constructor(linkInfo: LinkInfo) {
this.title = linkInfo.title;
this.description = linkInfo.description;
this.coverImg = linkInfo.coverImg;
this.siteName = linkInfo.siteName;
}
}
6 changes: 6 additions & 0 deletions src/contents/types/link-info.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface LinkInfo {
title: string;
description: string;
coverImg: string;
siteName?: string;
}

0 comments on commit 78e4b41

Please sign in to comment.