π¨ The ultimate agentic social media scheduling tool π€
TypeScript nextjsopen-sourceopen-source-social-media-scheduling-toolosspostiz-cloudpostiz-hostedredisscheduling-toolsocial-media-scheduling-tooltypescript
feat: fix linkedin chunks upload
Nevo David9235a8de1c9c
diff --git a/libraries/helpers/src/utils/read.or.fetch.ts b/libraries/helpers/src/utils/read.or.fetch.tsindex 10c939048..f5b2338b5 100644--- a/libraries/helpers/src/utils/read.or.fetch.ts+++ b/libraries/helpers/src/utils/read.or.fetch.ts@@ -1,8 +1,13 @@import {readFileSync} from "fs";+import axios from 'axios';export const readOrFetch = async (path: string) => {if (path.indexOf('http') === 0) {- return (await fetch(path)).arrayBuffer();+ return (await axios({+ url: path,+ method: 'GET',+ responseType: 'arraybuffer',+ })).data;}return readFileSync(path);diff --git a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.tsindex 177b59942..1422505b5 100644--- a/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts+++ b/libraries/nestjs-libraries/src/integrations/social/linkedin.provider.ts@@ -231,21 +231,25 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {const sendUrlRequest = uploadInstructions?.[0]?.uploadUrl || uploadUrl;const finalOutput = video || image;- const upload = await this.fetch(sendUrlRequest, {- method: 'PUT',- headers: {- 'X-Restli-Protocol-Version': '2.0.0',- 'LinkedIn-Version': '202402',- Authorization: `Bearer ${accessToken}`,- ...(fileName.indexOf('mp4') > -1- ? { 'Content-Type': 'application/octet-stream' }- : {}),- },- body: picture,- });+ 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': '202402',+ Authorization: `Bearer ${accessToken}`,+ ...(fileName.indexOf('mp4') > -1+ ? { 'Content-Type': 'application/octet-stream' }+ : {}),+ },+ body: picture.slice(i, i + 1024 * 1024 * 2),+ });++ etags.push(upload.headers.get('etag'));+ }if (fileName.indexOf('mp4') > -1) {- const etag = upload.headers.get('etag');const a = await this.fetch('https://api.linkedin.com/rest/videos?action=finalizeUpload',{@@ -254,7 +258,7 @@ export class LinkedinProvider extends SocialAbstract implements SocialProvider {finalizeUploadRequest: {video,uploadToken: '',- uploadedPartIds: [etag],+ uploadedPartIds: etags,},}),headers: {