Skip to content

Commit 94157b1

Browse files
author
Nevo David
committed
feat: redirectmeto
1 parent 2ce05fe commit 94157b1

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

libraries/nestjs-libraries/src/integrations/social/threads.provider.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
4141
'https://threads.net/oauth/authorize' +
4242
`?client_id=${process.env.THREADS_APP_ID}` +
4343
`&redirect_uri=${encodeURIComponent(
44-
process.env.NODE_ENV === 'development' || !process.env.NODE_ENV
45-
? `https://redirectmeto.com/${process.env.FRONTEND_URL}/integrations/social/threads`
46-
: `${process.env.FRONTEND_URL}/integrations/social/threads${
47-
refresh ? `?refresh=${refresh}` : ''
48-
}`
44+
`${
45+
process?.env.FRONTEND_URL?.indexOf('https') == -1
46+
? `https://redirectmeto.com/${process?.env.FRONTEND_URL}`
47+
: `${process?.env.FRONTEND_URL}`
48+
}/integrations/social/threads`
4949
)}` +
5050
`&state=${state}` +
5151
`&scope=${encodeURIComponent(this.scopes.join(','))}`,
@@ -104,8 +104,15 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
104104
};
105105
}
106106

107-
private async checkLoaded(mediaContainerId: string, accessToken: string): Promise<boolean> {
108-
const {status, id, error_message} = await (await this.fetch(`https://graph.threads.net/v1.0/${mediaContainerId}?fields=status,error_message&access_token=${accessToken}`)).json();
107+
private async checkLoaded(
108+
mediaContainerId: string,
109+
accessToken: string
110+
): Promise<boolean> {
111+
const { status, id, error_message } = await (
112+
await this.fetch(
113+
`https://graph.threads.net/v1.0/${mediaContainerId}?fields=status,error_message&access_token=${accessToken}`
114+
)
115+
).json();
109116
console.log(status, error_message);
110117
if (status === 'ERROR') {
111118
throw new Error(id);
@@ -205,12 +212,8 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
205212
mediaLoad.path.indexOf('.mp4') > -1 ? 'video_url' : 'image_url';
206213

207214
const media = new URLSearchParams({
208-
...(type === 'video_url'
209-
? { video_url: mediaLoad.path }
210-
: {}),
211-
...(type === 'image_url'
212-
? { image_url: mediaLoad.path }
213-
: {}),
215+
...(type === 'video_url' ? { video_url: mediaLoad.path } : {}),
216+
...(type === 'image_url' ? { image_url: mediaLoad.path } : {}),
214217
is_carousel_item: 'true',
215218
media_type:
216219
type === 'video_url'
@@ -234,7 +237,9 @@ export class ThreadsProvider extends SocialAbstract implements SocialProvider {
234237
medias.push(mediaId);
235238
}
236239

237-
await Promise.all(medias.map((p: string) => this.checkLoaded(p, accessToken)));
240+
await Promise.all(
241+
medias.map((p: string) => this.checkLoaded(p, accessToken))
242+
);
238243

239244
const { id: containerId } = await (
240245
await this.fetch(

0 commit comments

Comments
 (0)