n8n-nodes-twitter-uploader-inf
Version:
Twitter media upload nodes for n8n
62 lines • 2.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TwitterBinaryCheck = void 0;
class TwitterBinaryCheck {
constructor() {
this.description = {
displayName: 'Twitter Binary Check',
name: 'twitterBinaryCheck', // This name is important
icon: 'file:twitter.svg',
group: ['transform'],
version: 1,
description: 'Checks and ensures correct binary data property for Twitter upload',
defaults: {
name: 'Twitter Binary Check',
color: '#1DA1F2',
},
inputs: ['main'],
outputs: ['main'],
properties: [], // No configuration needed for this node
};
}
async execute() {
const items = this.getInputData();
const returnData = [];
// Process all items, not just the first one
for (let i = 0; i < items.length; i++) {
const item = items[i];
console.log(`Processing item ${i + 1}/${items.length}`);
const binaryKeys = Object.keys(item.binary || {});
console.log(`Binary properties available for item ${i + 1}:`, binaryKeys);
if (binaryKeys.length > 0) {
// Find the first image property
const imageKey = binaryKeys.find(key => { var _a; return (_a = item.binary[key].mimeType) === null || _a === void 0 ? void 0 : _a.startsWith('image/'); });
if (imageKey) {
console.log(`Found image property: ${imageKey}`);
// Normalize to 'data' property as expected by TwitterMediaUpload
returnData.push({
json: {
...item.json,
originalProperty: imageKey,
},
binary: {
data: item.binary[imageKey],
},
});
console.log('Binary data normalized to "data" property');
}
else {
console.log('No image property found in binary data');
returnData.push(item);
}
}
else {
console.log('No binary properties found');
returnData.push(item);
}
}
return [returnData];
}
}
exports.TwitterBinaryCheck = TwitterBinaryCheck;
//# sourceMappingURL=TwitterBinaryCheck.node.js.map