Skip to content

Commit

Permalink
facebook thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitdash08 committed Oct 29, 2024
1 parent c5c8d20 commit 56a324e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -51,22 +52,23 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
};
}

supportsVideoThumbnails = true;

async uploadVideoThumbnail(
accessToken: string,
videoId: string,
thumbnailUrl: string
options: VideoThumbnailOptions
): Promise<void> {
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: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
access_token: accessToken,
is_preferred: true,
source: thumbnailUrl,
is_preferred: options.isPreferred ?? true,
source: options.source,
}),
}
);
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
customFields?: () => Promise<
{
key: string;
Expand Down

0 comments on commit 56a324e

Please sign in to comment.