From 5e5ca78e9aff6ea10e9c98e236549465cfda7e10 Mon Sep 17 00:00:00 2001 From: Nevo David Date: Wed, 13 Aug 2025 22:08:20 +0700 Subject: [PATCH] feat: long upload should not be in a concurrenct --- .../integrations/social/linkedin.provider.ts | 36 +++++++++++-------- .../src/integrations/social/x.provider.ts | 32 +++++++++-------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts index d4731735..da870fd1 100644 --- a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts @@ -254,20 +254,26 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider { const etags = []; for (let i = 0; i < picture.length; i += 1024 * 1024 * 2) { - const upload = await this.fetch(sendUrlRequest, { - method: 'PUT', - headers: { - 'X-Restli-Protocol-Version': '2.0.0', - 'LinkedIn-Version': '202501', - Authorization: `Bearer ${accessToken}`, - ...(isVideo - ? { 'Content-Type': 'application/octet-stream' } - : isPdf - ? { 'Content-Type': 'application/pdf' } - : {}), + const upload = await this.fetch( + sendUrlRequest, + { + method: 'PUT', + headers: { + 'X-Restli-Protocol-Version': '2.0.0', + 'LinkedIn-Version': '202501', + Authorization: `Bearer ${accessToken}`, + ...(isVideo + ? { 'Content-Type': 'application/octet-stream' } + : isPdf + ? { 'Content-Type': 'application/pdf' } + : {}), + }, + body: picture.slice(i, i + 1024 * 1024 * 2), }, - body: picture.slice(i, i + 1024 * 1024 * 2), - }); + 'linkedin', + 0, + true + ); etags.push(upload.headers.get('etag')); } @@ -737,7 +743,9 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider { return elements.map((p: any) => ({ id: String(p.id), label: p.localizedName, - image: p.logoV2?.['original~']?.elements?.[0]?.identifiers?.[0]?.identifier || '', + image: + p.logoV2?.['original~']?.elements?.[0]?.identifiers?.[0]?.identifier || + '', })); } diff --git a/libraries/nestjs-libraries/src/integrations/social/x.provider.ts b/libraries/nestjs-libraries/src/integrations/social/x.provider.ts index 14bff67a..1467352e 100644 --- a/libraries/nestjs-libraries/src/integrations/social/x.provider.ts +++ b/libraries/nestjs-libraries/src/integrations/social/x.provider.ts @@ -317,22 +317,24 @@ export class XProvider extends SocialAbstract implements SocialProvider { postDetails.flatMap((p) => p?.media?.flatMap(async (m) => { return { - id: await this.runInConcurrent(async () => - client.v1.uploadMedia( - m.path.indexOf('mp4') > -1 - ? Buffer.from(await readOrFetch(m.path)) - : await sharp(await readOrFetch(m.path), { - animated: lookup(m.path) === 'image/gif', - }) - .resize({ - width: 1000, + id: await this.runInConcurrent( + async () => + client.v1.uploadMedia( + m.path.indexOf('mp4') > -1 + ? Buffer.from(await readOrFetch(m.path)) + : await sharp(await readOrFetch(m.path), { + animated: lookup(m.path) === 'image/gif', }) - .gif() - .toBuffer(), - { - mimeType: lookup(m.path) || '', - } - ) + .resize({ + width: 1000, + }) + .gif() + .toBuffer(), + { + mimeType: lookup(m.path) || '', + } + ), + true ), postId: p.id, };