diff --git a/apps/server/src/modules/board/controller/card.controller.ts b/apps/server/src/modules/board/controller/card.controller.ts index 00f0cd31bf4..38a979dbf1e 100644 --- a/apps/server/src/modules/board/controller/card.controller.ts +++ b/apps/server/src/modules/board/controller/card.controller.ts @@ -25,6 +25,7 @@ import { CreateContentElementBodyParams, ExternalToolElementResponse, FileElementResponse, + LinkElementResponse, MoveCardBodyParams, RenameBodyParams, RichTextElementResponse, @@ -116,19 +117,21 @@ export class CardController { @ApiOperation({ summary: 'Create a new element on a card.' }) @ApiExtraModels( - RichTextElementResponse, + ExternalToolElementResponse, FileElementResponse, - SubmissionContainerElementResponse, - ExternalToolElementResponse + LinkElementResponse, + RichTextElementResponse, + SubmissionContainerElementResponse ) @ApiResponse({ status: 201, schema: { oneOf: [ - { $ref: getSchemaPath(RichTextElementResponse) }, + { $ref: getSchemaPath(ExternalToolElementResponse) }, { $ref: getSchemaPath(FileElementResponse) }, + { $ref: getSchemaPath(LinkElementResponse) }, + { $ref: getSchemaPath(RichTextElementResponse) }, { $ref: getSchemaPath(SubmissionContainerElementResponse) }, - { $ref: getSchemaPath(ExternalToolElementResponse) }, ], }, }) diff --git a/apps/server/src/modules/board/controller/dto/card/card.response.ts b/apps/server/src/modules/board/controller/dto/card/card.response.ts index 66846387040..3577fcbc2a1 100644 --- a/apps/server/src/modules/board/controller/dto/card/card.response.ts +++ b/apps/server/src/modules/board/controller/dto/card/card.response.ts @@ -11,7 +11,13 @@ import { import { TimestampsResponse } from '../timestamps.response'; import { VisibilitySettingsResponse } from './visibility-settings.response'; -@ApiExtraModels(LinkElementResponse, RichTextElementResponse) +@ApiExtraModels( + ExternalToolElementResponse, + FileElementResponse, + LinkElementResponse, + RichTextElementResponse, + SubmissionContainerElementResponse +) export class CardResponse { constructor({ id, title, height, elements, visibilitySettings, timestamps }: CardResponse) { this.id = id; @@ -40,9 +46,9 @@ export class CardResponse { oneOf: [ { $ref: getSchemaPath(ExternalToolElementResponse) }, { $ref: getSchemaPath(FileElementResponse) }, + { $ref: getSchemaPath(LinkElementResponse) }, { $ref: getSchemaPath(RichTextElementResponse) }, { $ref: getSchemaPath(SubmissionContainerElementResponse) }, - { $ref: getSchemaPath(LinkElementResponse) }, ], }, }) diff --git a/apps/server/src/modules/board/controller/dto/element/link-element.response.ts b/apps/server/src/modules/board/controller/dto/element/link-element.response.ts index ee4fed36474..28e347d27eb 100644 --- a/apps/server/src/modules/board/controller/dto/element/link-element.response.ts +++ b/apps/server/src/modules/board/controller/dto/element/link-element.response.ts @@ -1,9 +1,48 @@ -import { ApiExtraModels, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; +import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { ContentElementType } from '@shared/domain'; -import { OpenGraphData } from '@src/modules/board/service'; import { TimestampsResponse } from '../timestamps.response'; -@ApiExtraModels(OpenGraphData) +export class OpenGraphImageData { + constructor({ url, type, width, height }: OpenGraphImageData) { + this.url = url; + this.type = type; + this.width = width ? +width : undefined; + this.height = height ? +height : undefined; + } + + @ApiProperty() + url: string; + + @ApiPropertyOptional() + type?: string; + + @ApiPropertyOptional() + width?: number; + + @ApiPropertyOptional() + height?: number; +} + +export class OpenGraphData { + constructor({ title, description, image, url }: OpenGraphData) { + this.title = title; + this.description = description; + this.image = image; + this.url = url; + } + + @ApiProperty() + title: string; + + @ApiProperty() + description: string; + + @ApiPropertyOptional({ type: OpenGraphImageData }) + image?: OpenGraphImageData; + + @ApiProperty() + url: string; +} export class LinkElementContent { constructor({ url, openGraphData }: LinkElementContent) { this.url = url; @@ -13,7 +52,7 @@ export class LinkElementContent { @ApiProperty() url: string; - @ApiPropertyOptional({ type: 'OpenGraphData' }) + @ApiPropertyOptional({ type: OpenGraphData }) openGraphData?: OpenGraphData; } diff --git a/apps/server/src/modules/board/service/open-graph-proxy.service.ts b/apps/server/src/modules/board/service/open-graph-proxy.service.ts index 5cc1b9b7ea8..ee6338ede67 100644 --- a/apps/server/src/modules/board/service/open-graph-proxy.service.ts +++ b/apps/server/src/modules/board/service/open-graph-proxy.service.ts @@ -1,50 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { sortBy } from 'lodash'; import ogs from 'open-graph-scraper'; import { ImageObject } from 'open-graph-scraper/dist/lib/types'; - -export class OpenGraphImageData { - constructor({ url, type, width, height }: OpenGraphImageData) { - this.url = url; - this.type = type; - this.width = width ? +width : undefined; - this.height = height ? +height : undefined; - } - - @ApiProperty() - url: string; - - @ApiPropertyOptional() - type?: string; - - @ApiPropertyOptional() - width?: number; - - @ApiPropertyOptional() - height?: number; -} - -export class OpenGraphData { - constructor({ title, description, image, url }: OpenGraphData) { - this.title = title; - this.description = description; - this.image = image; - this.url = url; - } - - @ApiProperty() - title: string; - - @ApiProperty() - description: string; - - @ApiPropertyOptional() - image?: OpenGraphImageData; - - @ApiProperty() - url: string; -} +import { OpenGraphData, OpenGraphImageData } from '../controller/dto'; @Injectable() export class OpenGraphProxyService { @@ -70,7 +28,6 @@ export class OpenGraphProxyService { const sortedImages = sortBy(imagesWithCorrectDimensions, ['width', 'height']); const biggestSmallEnoughImage = [...sortedImages].reverse().find((i) => i.width && i.width <= maxWidth); const smallestBigEnoughImage = sortedImages.find((i) => i.width && i.width >= minWidth); - // return imagesWithCorrectDimensions[0]; return biggestSmallEnoughImage ?? smallestBigEnoughImage ?? sortedImages[0]; } } diff --git a/apps/server/src/shared/domain/domainobject/board/link-element.do.ts b/apps/server/src/shared/domain/domainobject/board/link-element.do.ts index d810ee5b5a8..37fddeac453 100644 --- a/apps/server/src/shared/domain/domainobject/board/link-element.do.ts +++ b/apps/server/src/shared/domain/domainobject/board/link-element.do.ts @@ -1,4 +1,4 @@ -import { OpenGraphData } from '@src/modules/board/service'; +import { OpenGraphData } from '@src/modules/board/controller/dto'; import { BoardComposite, BoardCompositeProps } from './board-composite.do'; import type { BoardCompositeVisitor, BoardCompositeVisitorAsync } from './types';