@@ -370,68 +370,76 @@ export default {
370370 return { } ;
371371 } ,
372372 async run ( { $ } ) {
373- const data = new FormData ( ) ;
373+ try {
374+ const data = new FormData ( ) ;
374375
375- data . append ( "Url" , this . url ) ;
376- if ( this . fileName ) data . append ( "FileName" , this . fileName ) ;
377- if ( this . timeout ) data . append ( "Timeout" , this . timeout ) ;
378- if ( this . conversionDelay ) data . append ( "ConversionDelay" , this . conversionDelay ) ;
379- if ( this . authUsername ) data . append ( "AuthUsername" , this . authUsername ) ;
380- if ( this . authPassword ) data . append ( "AuthPassword" , this . authPassword ) ;
381- if ( this . adBlock ) data . append ( "AdBlock" , this . adBlock ) ;
382- if ( this . cookieConsentBlock ) data . append ( "CookieConsentBlock" , this . cookieConsentBlock ) ;
383- if ( this . cookies ) data . append ( "Cookies" , this . cookies ) ;
384- if ( this . javaScript ) data . append ( "JavaScript" , this . javaScript ) ;
385- if ( this . waitElement ) data . append ( "WaitElement" , this . waitElement ) ;
386- if ( this . userJs ) data . append ( "UserJs" , this . userJs ) ;
387- if ( this . userCss ) data . append ( "UserCss" , this . userCss ) ;
388- if ( this . hideElements ) data . append ( "HideElements" , this . hideElements ) ;
389- if ( this . cssMediaType ) data . append ( "CssMediaType" , this . cssMediaType ) ;
376+ data . append ( "Url" , this . url ) ;
377+ if ( this . fileName ) data . append ( "FileName" , this . fileName ) ;
378+ if ( this . timeout ) data . append ( "Timeout" , this . timeout ) ;
379+ if ( this . conversionDelay ) data . append ( "ConversionDelay" , this . conversionDelay ) ;
380+ if ( this . authUsername ) data . append ( "AuthUsername" , this . authUsername ) ;
381+ if ( this . authPassword ) data . append ( "AuthPassword" , this . authPassword ) ;
382+ if ( this . adBlock ) data . append ( "AdBlock" , ` ${ this . adBlock } ` ) ;
383+ if ( this . cookieConsentBlock ) data . append ( "CookieConsentBlock" , ` ${ this . cookieConsentBlock } ` ) ;
384+ if ( this . cookies ) data . append ( "Cookies" , this . cookies ) ;
385+ if ( this . javaScript ) data . append ( "JavaScript" , ` ${ this . javaScript } ` ) ;
386+ if ( this . waitElement ) data . append ( "WaitElement" , this . waitElement ) ;
387+ if ( this . userJs ) data . append ( "UserJs" , this . userJs ) ;
388+ if ( this . userCss ) data . append ( "UserCss" , this . userCss ) ;
389+ if ( this . hideElements ) data . append ( "HideElements" , this . hideElements ) ;
390+ if ( this . cssMediaType ) data . append ( "CssMediaType" , this . cssMediaType ) ;
390391
391- if ( this . formatTo === "jpg" ) {
392- if ( this . imageWidth ) data . append ( "ImageWidth" , this . imageWidth ) ;
393- if ( this . imageHeight ) data . append ( "ImageHeight" , this . imageHeight ) ;
394- if ( this . type ) data . append ( "Type" , this . type ) ;
395- if ( this . cropElement ) data . append ( "CropElement" , this . cropElement ) ;
396- if ( this . cropX ) data . append ( "CropX" , this . cropX ) ;
397- if ( this . cropY ) data . append ( "CropY" , this . cropY ) ;
398- if ( this . cropWidth ) data . append ( "CropWidth" , this . cropWidth ) ;
399- if ( this . cropHeight ) data . append ( "CropHeight" , this . cropHeight ) ;
400- if ( this . zoom ) data . append ( "Zoom" , this . zoom ) ;
401- } else {
402- if ( this . loadLazyContent ) data . append ( "LoadLazyContent" , this . loadLazyContent ) ;
403- if ( this . viewportWidth ) data . append ( "ViewportWidth" , this . viewportWidth ) ;
404- if ( this . viewportHeight ) data . append ( "ViewportHeight" , this . viewportHeight ) ;
405- if ( this . respectViewport ) data . append ( "RespectViewport" , this . respectViewport ) ;
406- if ( this . scale ) data . append ( "Scale" , this . scale ) ;
407- if ( this . pageOrientation ) data . append ( "PageOrientation" , this . pageOrientation ) ;
408- if ( this . pageSize ) data . append ( "PageSize" , this . pageSize ) ;
409- if ( this . pageWidth ) data . append ( "PageWidth" , this . pageWidth ) ;
410- if ( this . pageHeight ) data . append ( "PageHeight" , this . pageHeight ) ;
411- if ( this . marginTop ) data . append ( "MarginTop" , this . marginTop ) ;
412- if ( this . marginRight ) data . append ( "MarginRight" , this . marginRight ) ;
413- if ( this . marginBottom ) data . append ( "MarginBottom" , this . marginBottom ) ;
414- if ( this . marginLeft ) data . append ( "MarginLeft" , this . marginLeft ) ;
415- if ( this . pageRange ) data . append ( "PageRange" , this . pageRange ) ;
416- if ( this . background ) data . append ( "Background" , this . background ) ;
417- if ( this . fixedElements ) data . append ( "FixedElements" , this . fixedElements ) ;
418- if ( this . showElements ) data . append ( "ShowElements" , this . showElements ) ;
419- if ( this . avoidBreakElements ) data . append ( "AvoidBreakElements" , this . avoidBreakElements ) ;
420- if ( this . breakBeforeElements ) data . append ( "BreakBeforeElements" , this . breakBeforeElements ) ;
421- if ( this . breakAfterElements ) data . append ( "BreakAfterElements" , this . breakAfterElements ) ;
422- if ( this . compressPDF ) data . append ( "CompressPDF" , this . compressPDF ) ;
423- }
392+ if ( this . formatTo === "jpg" ) {
393+ if ( this . imageWidth ) data . append ( "ImageWidth" , this . imageWidth ) ;
394+ if ( this . imageHeight ) data . append ( "ImageHeight" , this . imageHeight ) ;
395+ if ( this . type ) data . append ( "Type" , this . type ) ;
396+ if ( this . cropElement ) data . append ( "CropElement" , this . cropElement ) ;
397+ if ( this . cropX ) data . append ( "CropX" , this . cropX ) ;
398+ if ( this . cropY ) data . append ( "CropY" , this . cropY ) ;
399+ if ( this . cropWidth ) data . append ( "CropWidth" , this . cropWidth ) ;
400+ if ( this . cropHeight ) data . append ( "CropHeight" , this . cropHeight ) ;
401+ if ( this . zoom ) data . append ( "Zoom" , this . zoom ) ;
402+ } else {
403+ if ( this . loadLazyContent ) data . append ( "LoadLazyContent" , ` ${ this . loadLazyContent } ` ) ;
404+ if ( this . viewportWidth ) data . append ( "ViewportWidth" , this . viewportWidth ) ;
405+ if ( this . viewportHeight ) data . append ( "ViewportHeight" , this . viewportHeight ) ;
406+ if ( this . respectViewport ) data . append ( "RespectViewport" , ` ${ this . respectViewport } ` ) ;
407+ if ( this . scale ) data . append ( "Scale" , this . scale ) ;
408+ if ( this . pageOrientation ) data . append ( "PageOrientation" , this . pageOrientation ) ;
409+ if ( this . pageSize ) data . append ( "PageSize" , this . pageSize ) ;
410+ if ( this . pageWidth ) data . append ( "PageWidth" , this . pageWidth ) ;
411+ if ( this . pageHeight ) data . append ( "PageHeight" , this . pageHeight ) ;
412+ if ( this . marginTop ) data . append ( "MarginTop" , this . marginTop ) ;
413+ if ( this . marginRight ) data . append ( "MarginRight" , this . marginRight ) ;
414+ if ( this . marginBottom ) data . append ( "MarginBottom" , this . marginBottom ) ;
415+ if ( this . marginLeft ) data . append ( "MarginLeft" , this . marginLeft ) ;
416+ if ( this . pageRange ) data . append ( "PageRange" , this . pageRange ) ;
417+ if ( this . background ) data . append ( "Background" , ` ${ this . background } ` ) ;
418+ if ( this . fixedElements ) data . append ( "FixedElements" , this . fixedElements ) ;
419+ if ( this . showElements ) data . append ( "ShowElements" , this . showElements ) ;
420+ if ( this . avoidBreakElements ) data . append ( "AvoidBreakElements" , this . avoidBreakElements ) ;
421+ if ( this . breakBeforeElements ) data . append ( "BreakBeforeElements" , this . breakBeforeElements ) ;
422+ if ( this . breakAfterElements ) data . append ( "BreakAfterElements" , this . breakAfterElements ) ;
423+ if ( this . compressPDF ) data . append ( "CompressPDF" , ` ${ this . compressPDF } ` ) ;
424+ }
424425
425- const { Files } = await this . convertapi . convertWebToFormat ( {
426- $,
427- formatTo : this . formatTo ,
428- data,
429- headers : data . getHeaders ( ) ,
430- } ) ;
426+ const { Files } = await this . convertapi . convertWebToFormat ( {
427+ $,
428+ formatTo : this . formatTo ,
429+ data,
430+ headers : data . getHeaders ( ) ,
431+ timeout : 2000 * this . timeout ,
432+ } ) ;
431433
432- await saveFile ( Files ) ;
434+ await saveFile ( Files ) ;
435+ const filename = Files [ 0 ] . FileName ;
433436
434- $ . export ( "$summary" , `Successfully converted URL to ${ this . formatTo } and saved in /tmp directory as **${ Files [ 0 ] . FileName } **.` ) ;
435- return ;
437+ $ . export ( "$summary" , `Successfully converted URL to ${ this . formatTo } and saved in /tmp directory as **${ filename } **.` ) ;
438+ return {
439+ filepath : `/tmp/${ filename } ` ,
440+ } ;
441+ } catch ( e ) {
442+ throw new Error ( e ) ;
443+ }
436444 } ,
437445} ;
0 commit comments