facebook-api-video-upload
Advanced tools
Comparing version 1.2.1 to 1.2.2
31
index.js
'use strict'; | ||
// Dependencies | ||
const Promise = require('bluebird'); | ||
@@ -7,3 +6,2 @@ const streamToPromise = require('stream-to-promise'); | ||
// Define | ||
const url = 'https://graph-video.facebook.com'; | ||
@@ -37,3 +35,7 @@ | ||
return rp(options).then(res => ({res, id: video_id })); | ||
return rp(options) | ||
.then(res => { | ||
res.video_id = video_id; | ||
return res; | ||
}); | ||
} | ||
@@ -64,12 +66,9 @@ | ||
function uploadChain(buffer, args, id, res) { | ||
function uploadChain(buffer, args, res, ids) { | ||
if (res.start_offset === res.end_offset) { | ||
return { | ||
id, | ||
video_id: res.video_id, | ||
}; | ||
return ids; | ||
} | ||
var chunk = buffer.slice(res.start_offset, res.end_offset); | ||
return uploadChunk(args, id, res.start_offset, chunk) | ||
.then(resp => uploadChain(buffer, args, id, {resp: resp, video_id: res.video_id })); | ||
return uploadChunk(args, ids[0], res.start_offset, chunk) | ||
.then(res => uploadChain(buffer, args, res, ids)); | ||
} | ||
@@ -79,9 +78,11 @@ | ||
return Promise.resolve(streamToPromise(args.stream)) | ||
.then((buffer) => buffer) | ||
.then((buffer) => [buffer, apiInit(args, buffer.length)]) | ||
.spread((buffer, res) => uploadChain(buffer, args, res.upload_session_id, res)) | ||
.then((res) => apiFinish(args, res.id, res.video_id)); | ||
.then(buffer => buffer) | ||
.then(buffer => [buffer, apiInit(args, buffer.length)]) | ||
.spread((buffer, res) => { | ||
const ids = [res.upload_session_id, res.video_id]; | ||
return uploadChain(buffer, args, res, ids); | ||
}) | ||
.spread((id, video_id) => apiFinish(args, id, video_id)); | ||
} | ||
module.exports = facebookApiVideoUpload; | ||
{ | ||
"name": "facebook-api-video-upload", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "A handy function to upload video in chunk on the facebook graph.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -25,3 +25,3 @@ [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo) | ||
console.log('res: ', res); | ||
// res: { success: true, id: video_id } } | ||
//res: { success: true, video_id: '1838312909759132' } | ||
}).catch((e) => { | ||
@@ -28,0 +28,0 @@ console.error(e); |
11
test.js
@@ -5,13 +5,12 @@ const fs = require('fs'); | ||
const args = { | ||
token: "EAAPL7TojSBQBAJN4eLlYkCwSUGlkNULoE50kvECtPnbzGbvkNhMaet27QN0Q9OqllohcZCBNQd1tbklsDnqD2S0GDKr2qYQVxV0zboXjdHOMDRxW2s5uEbaLL8H9jLhpfWK3kjnH4APhdPWfwCI28zVRl4AYZD", // with the permission to upload | ||
id: 1747978302125927, //The id represent {page_id || user_id || event_id || group_id} | ||
stream: fs.createReadStream('./test/fixture/fixture.mp4') //path to the video | ||
token: "EAAPL7TojSBQBAJN4eLlYkCwSUGlkNULoE50kvECtPnbzGbvkNhMaet27QN0Q9OqllohcZCBNQd1tbklsDnqD2S0GDKr2qYQVxV0zboXjdHOMDRxW2s5uEbaLL8H9jLhpfWK3kjnH4APhdPWfwCI28zVRl4AYZD", // with the permission to upload | ||
id: 1747978302125927, //The id represent {page_id || user_id || event_id || group_id} | ||
stream: fs.createReadStream('./test/fixture/fixture.mp4') //path to the video | ||
}; | ||
fbUpload(args).then((res) => { | ||
console.log('success'); | ||
console.log('res: ', res); | ||
console.log('res: ', res); | ||
// res: { success: true, id: video_id } } | ||
}).catch((e) => { | ||
console.error(e); | ||
console.error(e); | ||
}); |
87
24461504