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 d9827f7 commit d3d8dce
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
import { FC } from 'react';
import { withProvider } from '@gitroom/frontend/components/launches/providers/high.order.provider';
import { useSettings } from '@gitroom/frontend/components/launches/helpers/use.values';
import { MediaComponent } from '@gitroom/frontend/components/media/media.component';

export default withProvider(null, undefined, undefined, undefined, 63206);
const FacebookSettings: FC = () => {
const { register } = useSettings();
return (
<div className="mt-[20px]">
<MediaComponent
type="image"
width={1280}
height={720}
label="Video Thumbnail"
description="Thumbnail for video posts (optional)"
{...register('thumbnail')}
/>
</div>
);
};

export default withProvider(
FacebookSettings,
undefined,
undefined,
undefined,
63206
);
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {
};
}

async uploadVideoThumbnail(
accessToken: string,
videoId: string,
thumbnailUrl: string
): Promise<void> {
const response = await this.fetch(
`https://graph.facebook.com/v20.0/${videoId}/thumbnails`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
access_token: accessToken,
is_preferred: true,
source: thumbnailUrl,
}),
}
);

if (!response.ok) {
const errorData = await response.json();
throw new Error(
`Failed to upload video thumbnail: ${JSON.stringify(errorData)}`
);
}
}

async authenticate(params: {
code: string;
codeVerifier: string;
Expand Down Expand Up @@ -202,6 +230,13 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {

finalUrl = 'https://www.facebook.com/reel/' + videoId;
finalId = videoId;
if (firstPost.settings?.thumbnail?.url) {
await this.uploadVideoThumbnail(
accessToken,
videoId,
firstPost.settings.thumbnail.url
);
}
} else {
const uploadPhotos = !firstPost?.media?.length
? []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export type PostResponse = {
export type PostDetails<T = any> = {
id: string;
message: string;
settings: T;
settings: T & {
thumbnail?: {
url: string;
};
};
media?: MediaContent[];
poll?: PollDetails;
};
Expand Down

0 comments on commit d3d8dce

Please sign in to comment.