n8n-nodes-putio
Version:
n8n node for Put.io API integration
35 lines • 1.6 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.downloadFile = void 0;
function downloadFile(itemIndex) {
return __awaiter(this, void 0, void 0, function* () {
const fileId = this.getNodeParameter('fileId', itemIndex);
const response = yield this.helpers.requestWithAuthentication.call(this, 'putioApi', {
method: 'GET',
url: `https://api.put.io/v2/files/${fileId}/download`,
});
const urlMatch = response.match(/href="([^"]+)"/);
if (!urlMatch) {
throw new Error('Could not find download URL in response');
}
const downloadUrl = urlMatch[1].replace(/&/g, '&');
return [
{
json: {
downloadUrl,
},
},
];
});
}
exports.downloadFile = downloadFile;
//# sourceMappingURL=downloadFile.js.map