diff --git a/libraries/nestjs-libraries/src/dtos/posts/providers-settings/facebook.settings.dto.ts b/libraries/nestjs-libraries/src/dtos/posts/providers-settings/facebook.settings.dto.ts new file mode 100644 index 00000000..9d47c929 --- /dev/null +++ b/libraries/nestjs-libraries/src/dtos/posts/providers-settings/facebook.settings.dto.ts @@ -0,0 +1,10 @@ +import { IsOptional, ValidateNested } from 'class-validator'; +import { MediaDto } from '@gitroom/nestjs-libraries/dtos/media/media.dto'; +import { Type } from 'class-transformer'; + +export class FacebookSettingsDto { + @IsOptional() + @ValidateNested() + @Type(() => MediaDto) + thumbnail?: MediaDto; +} diff --git a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts index cca52f70..2ed5cf48 100644 --- a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts @@ -4,6 +4,7 @@ import { PostDetails, PostResponse, SocialProvider, + VideoThumbnailOptions, } from '@gitroom/nestjs-libraries/integrations/social/social.integrations.interface'; import { makeId } from '@gitroom/nestjs-libraries/services/make.is'; import dayjs from 'dayjs'; @@ -51,13 +52,14 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider { }; } + supportsVideoThumbnails = true; + async uploadVideoThumbnail( accessToken: string, - videoId: string, - thumbnailUrl: string + options: VideoThumbnailOptions ): Promise { const response = await this.fetch( - `https://graph.facebook.com/v20.0/${videoId}/thumbnails`, + `https://graph.facebook.com/v20.0/${options.videoId}/thumbnails`, { method: 'POST', headers: { @@ -65,8 +67,8 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider { }, body: JSON.stringify({ access_token: accessToken, - is_preferred: true, - source: thumbnailUrl, + is_preferred: options.isPreferred ?? true, + source: options.source, }), } ); @@ -229,8 +231,11 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider { if (firstPost.settings?.thumbnail?.url) { await this.uploadVideoThumbnail( accessToken, - videoId, - firstPost.settings.thumbnail.url + { + videoId: videoId, + source: firstPost.settings.thumbnail.url, + isPreferred: true + } ); } } else { diff --git a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts index 876f6fea..eac2595b 100644 --- a/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts +++ b/libraries/nestjs-libraries/src/integrations/social/social.integrations.interface.ts @@ -97,11 +97,19 @@ export type MediaContent = { path: string; }; +export interface VideoThumbnailOptions { + source: string; + isPreferred?: boolean; + videoId: string; +} + export interface SocialProvider extends IAuthenticator, ISocialMediaIntegration { identifier: string; refreshWait?: boolean; + supportsVideoThumbnails?: boolean; + uploadVideoThumbnail?(accessToken: string, options: VideoThumbnailOptions): Promise; customFields?: () => Promise< { key: string;