2023-01-27 03:22:44 -08:00
import type { IExecuteFunctions } from 'n8n-core' ;
2021-11-10 13:48:20 -08:00
2023-01-27 03:22:44 -08:00
import type {
IDataObject ,
INodeExecutionData ,
INodeType ,
INodeTypeDescription ,
} from 'n8n-workflow' ;
2021-11-10 13:48:20 -08:00
2022-08-17 08:50:24 -07:00
import { oneSimpleApiRequest } from './GenericFunctions' ;
2021-11-10 13:48:20 -08:00
export class OneSimpleApi implements INodeType {
description : INodeTypeDescription = {
displayName : 'One Simple API' ,
name : 'oneSimpleApi' ,
icon : 'file:onesimpleapi.svg' ,
group : [ 'transform' ] ,
version : 1 ,
description : 'A toolbox of no-code utilities' ,
defaults : {
name : 'One Simple API' ,
} ,
inputs : [ 'main' ] ,
outputs : [ 'main' ] ,
credentials : [
{
name : 'oneSimpleApi' ,
required : true ,
} ,
] ,
properties : [
{
displayName : 'Resource' ,
name : 'resource' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2021-11-10 13:48:20 -08:00
options : [
{
name : 'Information' ,
value : 'information' ,
} ,
2021-12-11 09:01:43 -08:00
{
name : 'Social Profile' ,
value : 'socialProfile' ,
} ,
2021-11-10 13:48:20 -08:00
{
name : 'Utility' ,
value : 'utility' ,
} ,
{
name : 'Website' ,
value : 'website' ,
} ,
] ,
default : 'website' ,
required : true ,
} ,
2021-12-11 09:01:43 -08:00
// website
2021-11-10 13:48:20 -08:00
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2021-11-10 13:48:20 -08:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'website' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
options : [
{
name : 'Generate PDF' ,
value : 'pdf' ,
description : 'Generate a PDF from a webpage' ,
2022-07-10 13:50:51 -07:00
action : 'Generate PDF' ,
2021-11-10 13:48:20 -08:00
} ,
{
name : 'Get SEO Data' ,
value : 'seo' ,
description : 'Get SEO information from website' ,
2022-07-10 13:50:51 -07:00
action : 'Get SEO Data' ,
2021-11-10 13:48:20 -08:00
} ,
{
name : 'Take Screenshot' ,
value : 'screenshot' ,
description : 'Create a screenshot from a webpage' ,
2022-07-10 13:50:51 -07:00
action : 'Screenshot' ,
2021-11-10 13:48:20 -08:00
} ,
] ,
default : 'pdf' ,
} ,
2021-12-11 09:01:43 -08:00
// socialProfile
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2021-12-11 09:01:43 -08:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'socialProfile' ] ,
2021-12-11 09:01:43 -08:00
} ,
} ,
options : [
{
name : 'Instagram' ,
value : 'instagramProfile' ,
description : 'Get details about an Instagram profile' ,
2022-07-10 13:50:51 -07:00
action : 'Get details about an Instagram profile' ,
2021-12-11 09:01:43 -08:00
} ,
{
name : 'Spotify' ,
value : 'spotifyArtistProfile' ,
description : 'Get details about a Spotify Artist' ,
2022-07-10 13:50:51 -07:00
action : 'Get details about a Spotify artist' ,
2021-12-11 09:01:43 -08:00
} ,
] ,
default : 'instagramProfile' ,
} ,
2021-11-10 13:48:20 -08:00
// Information
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2021-11-10 13:48:20 -08:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'information' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
options : [
{
name : 'Exchange Rate' ,
value : 'exchangeRate' ,
description : 'Convert a value between currencies' ,
2022-07-10 13:50:51 -07:00
action : 'Convert a value between currencies' ,
2021-11-10 13:48:20 -08:00
} ,
{
name : 'Image Metadata' ,
value : 'imageMetadata' ,
description : 'Retrieve image metadata from a URL' ,
2022-07-10 13:50:51 -07:00
action : 'Get image metadata from a URL' ,
2021-11-10 13:48:20 -08:00
} ,
] ,
default : 'exchangeRate' ,
} ,
2021-12-11 09:01:43 -08:00
// Utility
2021-11-10 13:48:20 -08:00
{
displayName : 'Operation' ,
name : 'operation' ,
type : 'options' ,
2022-05-20 14:47:24 -07:00
noDataExpression : true ,
2021-11-10 13:48:20 -08:00
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'utility' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
options : [
{
name : 'Expand URL' ,
value : 'expandURL' ,
2022-06-03 10:23:49 -07:00
description : 'Expand a shortened URL' ,
2022-07-10 13:50:51 -07:00
action : 'Expand a shortened URL' ,
2021-11-10 13:48:20 -08:00
} ,
{
name : 'Generate QR Code' ,
value : 'qrCode' ,
description : 'Generate a QR Code' ,
2022-07-10 13:50:51 -07:00
action : 'Generate a QR code utility' ,
2021-11-10 13:48:20 -08:00
} ,
{
name : 'Validate Email' ,
value : 'validateEmail' ,
description : 'Validate an email address' ,
2022-07-10 13:50:51 -07:00
action : 'Validate an email address' ,
2021-11-10 13:48:20 -08:00
} ,
] ,
default : 'validateEmail' ,
} ,
// website: pdf
{
displayName : 'Webpage URL' ,
name : 'link' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'pdf' ] ,
resource : [ 'website' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
description : 'Link to webpage to convert' ,
} ,
{
displayName : 'Download PDF?' ,
name : 'download' ,
type : 'boolean' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'pdf' ] ,
resource : [ 'website' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : false ,
description : 'Whether to download the PDF or return a link to it' ,
} ,
{
displayName : 'Put Output In Field' ,
name : 'output' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'pdf' ] ,
resource : [ 'website' ] ,
download : [ true ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : 'data' ,
description : 'The name of the output field to put the binary file data in' ,
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
placeholder : 'Add Option' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'website' ] ,
operation : [ 'pdf' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
options : [
{
displayName : 'Page Size' ,
name : 'page' ,
type : 'options' ,
options : [
{
name : 'A0' ,
value : 'A0' ,
} ,
{
name : 'A1' ,
value : 'A1' ,
} ,
{
name : 'A2' ,
value : 'A2' ,
} ,
{
name : 'A3' ,
value : 'A3' ,
} ,
{
name : 'A4' ,
value : 'A4' ,
} ,
{
name : 'A5' ,
value : 'A5' ,
} ,
{
name : 'A6' ,
value : 'A6' ,
} ,
{
name : 'Ledger' ,
value : 'Ledger' ,
} ,
2022-06-03 10:23:49 -07:00
{
name : 'Legal' ,
value : 'Legal' ,
} ,
2021-11-10 13:48:20 -08:00
{
name : 'Letter' ,
value : 'Letter' ,
} ,
{
name : 'Tabloid' ,
value : 'Tabloid' ,
} ,
] ,
default : '' ,
} ,
{
displayName : 'Force Refresh' ,
name : 'force' ,
type : 'boolean' ,
default : false ,
2022-06-20 07:54:01 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
2022-08-17 08:50:24 -07:00
description :
"Normally the API will reuse a previously taken screenshot of the URL to give a faster response. This option allows you to retake the screenshot at that exact time, for those times when it's necessary." ,
2021-11-10 13:48:20 -08:00
} ,
] ,
} ,
// website: qrCode
{
displayName : 'QR Content' ,
name : 'message' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'qrCode' ] ,
resource : [ 'utility' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
description : 'The text that should be turned into a QR code - like a website URL' ,
} ,
{
displayName : 'Download Image?' ,
name : 'download' ,
type : 'boolean' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'qrCode' ] ,
resource : [ 'utility' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : false ,
description : 'Whether to download the QR code or return a link to it' ,
} ,
{
displayName : 'Put Output In Field' ,
name : 'output' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'qrCode' ] ,
resource : [ 'utility' ] ,
download : [ true ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : 'data' ,
description : 'The name of the output field to put the binary file data in' ,
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
placeholder : 'Add Option' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'utility' ] ,
operation : [ 'qrCode' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
options : [
{
displayName : 'Size' ,
name : 'size' ,
type : 'options' ,
options : [
{
name : 'Small' ,
value : 'Small' ,
} ,
{
name : 'Medium' ,
value : 'Medium' ,
} ,
{
name : 'Large' ,
value : 'Large' ,
} ,
] ,
default : 'Small' ,
description : 'The QR Code size' ,
} ,
{
displayName : 'Format' ,
name : 'format' ,
type : 'options' ,
options : [
{
name : 'PNG' ,
value : 'PNG' ,
} ,
{
name : 'SVG' ,
value : 'SVG' ,
} ,
] ,
default : 'PNG' ,
description : 'The QR Code format' ,
} ,
] ,
} ,
// website: screenshot
{
displayName : 'Webpage URL' ,
name : 'link' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'screenshot' ] ,
resource : [ 'website' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
description : 'Link to webpage to convert' ,
} ,
{
displayName : 'Download Screenshot?' ,
name : 'download' ,
type : 'boolean' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'screenshot' ] ,
resource : [ 'website' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : false ,
description : 'Whether to download the screenshot or return a link to it' ,
} ,
{
displayName : 'Put Output In Field' ,
name : 'output' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'screenshot' ] ,
resource : [ 'website' ] ,
download : [ true ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : 'data' ,
description : 'The name of the output field to put the binary file data in' ,
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
placeholder : 'Add Option' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'website' ] ,
operation : [ 'screenshot' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
options : [
{
displayName : 'Screen Size' ,
name : 'screen' ,
type : 'options' ,
options : [
{
name : 'Phone' ,
value : 'phone' ,
} ,
{
name : 'Phone Landscape' ,
value : 'phone-landscape' ,
} ,
{
name : 'Retina' ,
value : 'retina' ,
} ,
{
name : 'Tablet' ,
value : 'tablet' ,
} ,
{
name : 'Tablet Landscape' ,
value : 'tablet-landscape' ,
} ,
] ,
default : '' ,
} ,
{
displayName : 'Force Refresh' ,
name : 'force' ,
type : 'boolean' ,
default : false ,
2022-06-20 07:54:01 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
2022-08-17 08:50:24 -07:00
description :
"Normally the API will reuse a previously taken screenshot of the URL to give a faster response. This option allows you to retake the screenshot at that exact time, for those times when it's necessary." ,
2021-11-10 13:48:20 -08:00
} ,
{
displayName : 'Full Page' ,
name : 'fullpage' ,
type : 'boolean' ,
default : false ,
2022-06-20 07:54:01 -07:00
// eslint-disable-next-line n8n-nodes-base/node-param-description-boolean-without-whether
2022-08-17 08:50:24 -07:00
description :
'The API takes a screenshot of the viewable area for the desired screen size. If you need a screenshot of the whole length of the page, use this option.' ,
2021-11-10 13:48:20 -08:00
} ,
] ,
} ,
2021-12-11 09:01:43 -08:00
// socialProfile: instagramProfile
{
displayName : 'Profile Name' ,
name : 'profileName' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'instagramProfile' ] ,
resource : [ 'socialProfile' ] ,
2021-12-11 09:01:43 -08:00
} ,
} ,
default : '' ,
description : 'Profile name to get details of' ,
} ,
// socialProfile: spotifyArtistProfile
{
displayName : 'Artist Name' ,
name : 'artistName' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'spotifyArtistProfile' ] ,
resource : [ 'socialProfile' ] ,
2021-12-11 09:01:43 -08:00
} ,
} ,
default : '' ,
description : 'Artist name to get details for' ,
} ,
2021-11-10 13:48:20 -08:00
// information: exchangeRate
{
displayName : 'Value' ,
name : 'value' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'exchangeRate' ] ,
resource : [ 'information' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
description : 'Value to convert' ,
} ,
{
displayName : 'From Currency' ,
name : 'fromCurrency' ,
type : 'string' ,
required : true ,
placeholder : 'USD' ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'exchangeRate' ] ,
resource : [ 'information' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
} ,
{
displayName : 'To Currency' ,
name : 'toCurrency' ,
type : 'string' ,
placeholder : 'EUR' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'exchangeRate' ] ,
resource : [ 'information' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
} ,
// information: imageMetadata
{
displayName : 'Link To Image' ,
name : 'link' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'imageMetadata' ] ,
resource : [ 'information' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
description : 'Image to get metadata from' ,
} ,
// website: seo
{
displayName : 'Webpage URL' ,
name : 'link' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'seo' ] ,
resource : [ 'website' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
description : 'Webpage to get SEO information for' ,
} ,
{
displayName : 'Options' ,
name : 'options' ,
type : 'collection' ,
placeholder : 'Add Option' ,
default : { } ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
resource : [ 'website' ] ,
operation : [ 'seo' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
options : [
{
displayName : 'Include Headers?' ,
name : 'headers' ,
type : 'boolean' ,
default : false ,
} ,
] ,
} ,
// utility: validateEmail
{
displayName : 'Email Address' ,
name : 'emailAddress' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'validateEmail' ] ,
resource : [ 'utility' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
} ,
// utility: expandURL
{
displayName : 'URL' ,
name : 'link' ,
type : 'string' ,
required : true ,
displayOptions : {
show : {
2022-08-17 08:50:24 -07:00
operation : [ 'expandURL' ] ,
resource : [ 'utility' ] ,
2021-11-10 13:48:20 -08:00
} ,
} ,
default : '' ,
description : 'URL to unshorten' ,
} ,
] ,
} ;
async execute ( this : IExecuteFunctions ) : Promise < INodeExecutionData [ ] [ ] > {
const items = this . getInputData ( ) ;
const returnData : IDataObject [ ] = [ ] ;
2022-04-22 09:29:51 -07:00
const length = items . length ;
2021-11-10 13:48:20 -08:00
const qs : IDataObject = { } ;
let responseData ;
let download ;
for ( let i = 0 ; i < length ; i ++ ) {
try {
2022-12-02 03:53:59 -08:00
const resource = this . getNodeParameter ( 'resource' , 0 ) ;
const operation = this . getNodeParameter ( 'operation' , 0 ) ;
2021-11-10 13:48:20 -08:00
if ( resource === 'website' ) {
if ( operation === 'pdf' ) {
const link = this . getNodeParameter ( 'link' , i ) as string ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2022-11-18 05:31:38 -08:00
download = this . getNodeParameter ( 'download' , i ) ;
2021-11-10 13:48:20 -08:00
qs . url = link ;
if ( options . page ) {
qs . page = options . page as string ;
}
if ( options . force ) {
qs . force = 'yes' ;
} else {
qs . force = 'no' ;
}
const response = await oneSimpleApiRequest . call ( this , 'GET' , '/pdf' , { } , qs ) ;
if ( download ) {
const output = this . getNodeParameter ( 'output' , i ) as string ;
2022-08-17 08:50:24 -07:00
const buffer = ( await oneSimpleApiRequest . call (
this ,
'GET' ,
'' ,
{ } ,
{ } ,
response . url ,
{ json : false , encoding : null } ,
) ) as Buffer ;
2021-11-10 13:48:20 -08:00
responseData = {
json : response ,
binary : {
[ output ] : await this . helpers . prepareBinaryData ( buffer ) ,
} ,
} ;
} else {
responseData = response ;
}
}
if ( operation === 'screenshot' ) {
const link = this . getNodeParameter ( 'link' , i ) as string ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2022-11-18 05:31:38 -08:00
download = this . getNodeParameter ( 'download' , i ) ;
2021-11-10 13:48:20 -08:00
qs . url = link ;
if ( options . screen ) {
qs . screen = options . screen as string ;
}
if ( options . fullpage ) {
qs . fullpage = 'yes' ;
} else {
qs . fullpage = 'no' ;
}
if ( options . force ) {
qs . force = 'yes' ;
} else {
qs . force = 'no' ;
}
const response = await oneSimpleApiRequest . call ( this , 'GET' , '/screenshot' , { } , qs ) ;
if ( download ) {
const output = this . getNodeParameter ( 'output' , i ) as string ;
2022-08-17 08:50:24 -07:00
const buffer = ( await oneSimpleApiRequest . call (
this ,
'GET' ,
'' ,
{ } ,
{ } ,
response . url ,
{ json : false , encoding : null } ,
) ) as Buffer ;
2021-11-10 13:48:20 -08:00
responseData = {
json : response ,
binary : {
[ output ] : await this . helpers . prepareBinaryData ( buffer ) ,
} ,
} ;
} else {
responseData = response ;
}
}
if ( operation === 'seo' ) {
const link = this . getNodeParameter ( 'link' , i ) as string ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2021-11-10 13:48:20 -08:00
qs . url = link ;
if ( options . headers ) {
qs . headers = 'yes' ;
}
responseData = await oneSimpleApiRequest . call ( this , 'GET' , '/page_info' , { } , qs ) ;
}
}
2021-12-11 09:01:43 -08:00
if ( resource === 'socialProfile' ) {
if ( operation === 'instagramProfile' ) {
const profileName = this . getNodeParameter ( 'profileName' , i ) as string ;
qs . profile = profileName ;
2022-08-17 08:50:24 -07:00
responseData = await oneSimpleApiRequest . call (
this ,
'GET' ,
'/instagram_profile' ,
{ } ,
qs ,
) ;
2021-12-11 09:01:43 -08:00
}
if ( operation === 'spotifyArtistProfile' ) {
const artistName = this . getNodeParameter ( 'artistName' , i ) as string ;
qs . profile = artistName ;
responseData = await oneSimpleApiRequest . call ( this , 'GET' , '/spotify_profile' , { } , qs ) ;
}
}
2021-11-10 13:48:20 -08:00
if ( resource === 'information' ) {
if ( operation === 'exchangeRate' ) {
const value = this . getNodeParameter ( 'value' , i ) as string ;
const fromCurrency = this . getNodeParameter ( 'fromCurrency' , i ) as string ;
const toCurrency = this . getNodeParameter ( 'toCurrency' , i ) as string ;
qs . from_currency = fromCurrency ;
qs . to_currency = toCurrency ;
qs . from_value = value ;
responseData = await oneSimpleApiRequest . call ( this , 'GET' , '/exchange_rate' , { } , qs ) ;
}
if ( operation === 'imageMetadata' ) {
const link = this . getNodeParameter ( 'link' , i ) as string ;
qs . url = link ;
qs . raw = true ;
responseData = await oneSimpleApiRequest . call ( this , 'GET' , '/image_info' , { } , qs ) ;
}
}
if ( resource === 'utility' ) {
// validateEmail
if ( operation === 'validateEmail' ) {
const emailAddress = this . getNodeParameter ( 'emailAddress' , i ) as string ;
qs . email = emailAddress ;
responseData = await oneSimpleApiRequest . call ( this , 'GET' , '/email' , { } , qs ) ;
}
// expandURL
if ( operation === 'expandURL' ) {
const url = this . getNodeParameter ( 'link' , i ) as string ;
qs . url = url ;
responseData = await oneSimpleApiRequest . call ( this , 'GET' , '/unshorten' , { } , qs ) ;
}
if ( operation === 'qrCode' ) {
const message = this . getNodeParameter ( 'message' , i ) as string ;
2022-11-18 07:29:44 -08:00
const options = this . getNodeParameter ( 'options' , i ) ;
2022-11-18 05:31:38 -08:00
download = this . getNodeParameter ( 'download' , i ) ;
2021-11-10 13:48:20 -08:00
qs . message = message ;
if ( options . size ) {
qs . size = options . size as string ;
}
if ( options . format ) {
qs . format = options . format as string ;
}
const response = await oneSimpleApiRequest . call ( this , 'GET' , '/qr_code' , { } , qs ) ;
if ( download ) {
const output = this . getNodeParameter ( 'output' , i ) as string ;
2022-08-17 08:50:24 -07:00
const buffer = ( await oneSimpleApiRequest . call (
this ,
'GET' ,
'' ,
{ } ,
{ } ,
response . url ,
{ json : false , encoding : null } ,
) ) as Buffer ;
2021-11-10 13:48:20 -08:00
responseData = {
json : response ,
binary : {
[ output ] : await this . helpers . prepareBinaryData ( buffer ) ,
} ,
} ;
} else {
responseData = response ;
}
}
}
if ( Array . isArray ( responseData ) ) {
returnData . push . apply ( returnData , responseData as IDataObject [ ] ) ;
} else {
returnData . push ( responseData as IDataObject ) ;
}
} catch ( error ) {
if ( this . continueOnFail ( ) ) {
returnData . push ( { error : error.message } ) ;
continue ;
}
throw error ;
}
}
if ( download ) {
return this . prepareOutputData ( returnData as unknown as INodeExecutionData [ ] ) ;
}
return [ this . helpers . returnJsonArray ( returnData ) ] ;
}
}