This commit is contained in:
tamasvar
2025-02-16 04:45:41 +00:00
committed by GitHub

View File

@@ -612,14 +612,11 @@ module.exports = function(RED) {
}
var mediaPromise;
if (msg.media && Buffer.isBuffer(msg.media)) {
// var mediaType = fileType(msg.media);
// if (mediaType === null) {
// node.status({fill:"red",shape:"ring",text:"twitter.status.failed"});
// node.error("msg.media is not a valid media object",msg);
// return;
// }
mediaPromise = node.twitterConfig.post("https://upload.twitter.com/1.1/media/upload.json",null,null,{
media: msg.media
mediaPromise = node.twitterConfig.post("https://upload.twitter.com/1.1/media/upload.json",{
command: "INIT",
total_bytes: msg.mediaSize,
media_type: msg.mediaType
}).then(function(result) {
if (result.status === 200) {
return result.body.media_id_string;
@@ -628,6 +625,31 @@ module.exports = function(RED) {
}
});
mediaPromise = node.twitterConfig.post("https://upload.twitter.com/1.1/media/upload.json",{
command: "APPEND",
media_id: mediaId,
media: msg.media,
segment_index: 0
}).then(function(result) {
if (result.status === 200) {
return result.media_id;
} else {
throw new Error(result.body.errors[0]);
}
});
mediaPromise = node.twitterConfig.post("https://upload.twitter.com/1.1/media/upload.json",{
command: "FINALIZE",
media_id: mediaId
}).then(function(result) {
if (result.status === 200) {
return result.media_id;
} else {
throw new Error(result.body.errors[0]);
}
});
} else {
mediaPromise = Promise.resolve();
}