Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: better rate limiting for instagram

Nevo David9b1308b2e63c
diff --git a/libraries/nestjs-libraries/src/integrations/social.abstract.ts b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
index 8761446f1..e3fe7ba05 100644
--- a/libraries/nestjs-libraries/src/integrations/social.abstract.ts
+++ b/libraries/nestjs-libraries/src/integrations/social.abstract.ts
@@ -1,4 +1,5 @@
import { timer } from '@gitroom/helpers/utils/timer';
+import pThrottle from 'p-throttle';
export class RefreshToken {
constructor(
@@ -19,15 +20,24 @@ export class NotEnoughScopes {
constructor(public message = 'Not enough scopes') {}
}
+const pThrottleInstance = pThrottle({
+ limit: 1,
+ interval: 2000
+});
+
export abstract class SocialAbstract {
+ private fetchInstance = pThrottleInstance(
+ (url: RequestInfo, options?: RequestInit) => fetch(url, options)
+ );
+
async fetch(
url: string,
options: RequestInit = {},
identifier = '',
totalRetries = 0
): Promise<Response> {
- const request = await fetch(url, options);
-``
+ const request = await this.fetchInstance(url, options);
+
if (request.status === 200 || request.status === 201) {
return request;
}
diff --git a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
index f43536c3a..984567149 100644
--- a/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
+++ b/libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts
@@ -260,7 +260,7 @@ export class InstagramProvider
`https://${type}/v20.0/${photoId}?access_token=${accessToken}&fields=status_code`
)
).json();
- await timer(3000);
+ await timer(10000);
status = status_code;
}
console.log('in progress3');
@@ -320,7 +320,7 @@ export class InstagramProvider
`https://${type}/v20.0/${containerId}?fields=status_code&access_token=${accessToken}`
)
).json();
- await timer(3000);
+ await timer(10000);
status = status_code;
}
diff --git a/package.json b/package.json
index 8944898d3..254d20c3a 100644
--- a/package.json
+++ b/package.json
@@ -171,6 +171,7 @@
"nx": "19.7.2",
"openai": "^4.47.1",
"p-limit": "^3.1.0",
+ "p-throttle": "4.1.1",
"polotno": "^2.10.5",
"posthog-js": "^1.178.0",
"react": "18.3.1",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 26e43dacf..30e081bc7 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -390,6 +390,9 @@ importers:
p-limit:
specifier: ^3.1.0
version: 3.1.0
+ p-throttle:
+ specifier: 4.1.1
+ version: 4.1.1
polotno:
specifier: ^2.10.5
@@ -12367,6 +12370,10 @@ packages:
resolution: {integrity: sha512-hEt02O4hUct5wtwg4H4KcWgDdm+l1bOaEy/hWzd8xtXB9BqxTWBBhb+2ImAtH4Cv4rPjV76xN3Zumqk3k3AhhQ==}
engines: {node: '>=16.17'}
+ resolution: {integrity: sha512-TuU8Ato+pRTPJoDzYD4s7ocJYcNSEZRvlxoq3hcPI2kZDZ49IQ1Wkj7/gDJc3X7XiEAAvRGtDzdXJI0tC3IL1g==}
+ engines: {node: '>=10'}
+
resolution: {integrity: sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==}
engines: {node: '>=8'}
@@ -31944,6 +31951,8 @@ snapshots:
is-network-error: 1.1.0
retry: 0.13.1
+
dependencies:
p-finally: 1.0.0