feat: long upload should not be in a concurrenct

This commit is contained in:
Nevo David 2025-08-13 22:08:20 +07:00
parent 2db252f97f
commit 5e5ca78e9a
2 changed files with 39 additions and 29 deletions

View File

@ -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 ||
'',
}));
}

View File

@ -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,
};