π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: prevent infinite loops
Nevo David935d4a469608
diff --git a/libraries/nestjs-libraries/src/3rdparties/heygen/heygen.provider.ts b/libraries/nestjs-libraries/src/3rdparties/heygen/heygen.provider.tsindex 8fc248c3c..00d0af9d7 100644--- a/libraries/nestjs-libraries/src/3rdparties/heygen/heygen.provider.ts+++ b/libraries/nestjs-libraries/src/3rdparties/heygen/heygen.provider.ts@@ -167,7 +167,13 @@ export class HeygenProvider extends ThirdPartyAbstract<{})).json();+ let attempts = 0;+ const maxAttempts = 600; // ~30 minutes at 3s intervalwhile (true) {+ if (attempts++ >= maxAttempts) {+ throw new Error('Video generation timed out');+ }+const {data: { status, video_url },} = await (diff --git a/libraries/nestjs-libraries/src/integrations/social/bluesky.provider.ts b/libraries/nestjs-libraries/src/integrations/social/bluesky.provider.tsindex 5821657fb..b3f9d6376 100644--- a/libraries/nestjs-libraries/src/integrations/social/bluesky.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/bluesky.provider.ts@@ -112,7 +112,18 @@ async function uploadVideo(let blob: BlobRef | undefined = jobStatus.blob;const videoAgent = new AtpAgent({ service: 'https://video.bsky.app' });+ let attempts = 0;+ const maxAttempts = 60; // ~30 minutes at 30s intervalwhile (!blob) {+ if (attempts++ >= maxAttempts) {+ throw new BadBody(+ 'bluesky',+ JSON.stringify({}),+ {} as any,+ 'Video upload timed out, job did not complete'+ );+ }+const { data: status } = await videoAgent.app.bsky.video.getJobStatus({jobId: jobStatus.jobId,});diff --git a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.tsindex e1b3ae555..5713aeb3e 100644--- a/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/facebook.provider.ts@@ -492,7 +492,13 @@ export class FacebookProvider extends SocialAbstract implements SocialProvider {);let videoStatus = 'in_progress';+ let attempts = 0;+ const maxAttempts = 180; // ~30 minutes at 10s intervalwhile (videoStatus !== 'upload_complete' && videoStatus !== 'ready') {+ if (attempts++ >= maxAttempts) {+ throw new Error('Video processing timed out');+ }+const { status } = await (await this.fetch(`https://graph.facebook.com/v20.0/${video_id}?fields=status&access_token=${accessToken}`,diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.tsindex de15d414c..ceff0de1d 100644--- a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts@@ -682,7 +682,13 @@ export class InstagramProviderconsole.log('in progress2', id);let status = 'IN_PROGRESS';+ let attempts = 0;+ const maxAttempts = 60; // ~30 minutes at 30s intervalwhile (status === 'IN_PROGRESS') {+ if (attempts++ >= maxAttempts) {+ throw new Error('Media processing timed out');+ }+const { status_code } = await (await this.fetch(`https://${type}/v20.0/${photoId}?access_token=${@@ -777,7 +783,13 @@ export class InstagramProvider).json();let status = 'IN_PROGRESS';+ let attempts = 0;+ const maxAttempts = 60; // ~30 minutes at 30s intervalwhile (status === 'IN_PROGRESS') {+ if (attempts++ >= maxAttempts) {+ throw new Error('Media processing timed out');+ }+const { status_code } = await (await this.fetch(`https://${type}/v20.0/${containerId}?fields=status_code&access_token=${diff --git a/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts b/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.tsindex 8bef3f8b0..c2e0fcfa0 100644--- a/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/pinterest.provider.ts@@ -288,7 +288,18 @@ export class PinterestProviderawait axios.post(upload_url, formData);let statusCode = '';+ let attempts = 0;+ const maxAttempts = 60; // ~30 minutes at 30s intervalwhile (statusCode !== 'succeeded') {+ if (attempts++ >= maxAttempts) {+ throw new BadBody(+ 'pinterest',+ JSON.stringify({}),+ {} as any,+ 'The file took too long to process, please try again'+ );+ }+const mediafile = await (await this.fetch('https://api.pinterest.com/v5/media/' + media_id,diff --git a/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts b/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.tsindex f212b8377..1d6da52c2 100644--- a/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts@@ -414,7 +414,7 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {): Promise<{ url: string; id: string }> {const ctx = Context.current();// eslint-disable-next-line no-constant-condition- for (const i of Array(10).keys()) {+ for (const i of Array(600).keys()) {const post = await (await this.fetch('https://open.tiktokapis.com/v2/post/publish/status/fetch/',@@ -466,7 +466,7 @@ export class TiktokProvider extends SocialAbstract implements SocialProvider {);}- await timer(10000);+ await timer(20000);}throw new BadBody(diff --git a/libraries/nestjs-libraries/src/integrations/social/whop.provider.ts b/libraries/nestjs-libraries/src/integrations/social/whop.provider.tsindex a1c71b862..12c058c31 100644--- a/libraries/nestjs-libraries/src/integrations/social/whop.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/whop.provider.ts@@ -254,7 +254,13 @@ export class WhopProvider extends SocialAbstract implements SocialProvider {});let uploadStatus = 'pending';+ let attempts = 0;+ const maxAttempts = 360; // ~30 minutes at 5s intervalwhile (uploadStatus !== 'ready') {+ if (attempts++ >= maxAttempts) {+ throw new Error('File upload timed out');+ }+const fileStatus = await (await this.fetch(`https://api.whop.com/api/v1/files/${createFileResponse.id}`,