feat: fix linkedin chunks upload
This commit is contained in:
parent
967fe62b1b
commit
9235a8de1c
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
Loading…
Reference in New Issue