@@ -17,6 +17,7 @@ const readFile = require('../utils/filemanager/readfile');
1717const FlowtestAI = require ( '../ai/flowtestai' ) ;
1818const { stringify, parse } = require ( 'flatted' ) ;
1919const { deserialize, serialize } = require ( '../utils/flowparser/parser' ) ;
20+ const { axiosClient } = require ( './axiosClient' ) ;
2021
2122const collectionStore = new Collections ( ) ;
2223const flowTestAI = new FlowtestAI ( ) ;
@@ -336,6 +337,55 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
336337 return Promise . reject ( error ) ;
337338 }
338339 } ) ;
340+
341+ ipcMain . handle ( 'renderer:upload-logs' , async ( event , name , config , logs ) => {
342+ function bytesToBase64 ( bytes ) {
343+ const binString = Array . from ( bytes , ( byte ) => String . fromCodePoint ( byte ) ) . join ( '' ) ;
344+ return btoa ( binString ) ;
345+ }
346+
347+ try {
348+ const data = {
349+ version : 1 ,
350+ name,
351+ scan : logs ,
352+ } ;
353+ try {
354+ const response = await axiosClient ( config . hostUrl , config . accessId , config . accessKey ) . post (
355+ '/upload' ,
356+ bytesToBase64 ( new TextEncoder ( ) . encode ( JSON . stringify ( data ) ) ) ,
357+ ) ;
358+ return {
359+ upload : 'success' ,
360+ url : `${ config . hostUrl } /scan/${ response . data . data [ 0 ] . id } ` ,
361+ } ;
362+ } catch ( error ) {
363+ if ( error ?. response ) {
364+ if ( error . response ?. status === 403 || error . response ?. status === 429 ) {
365+ return {
366+ upload : 'fail' ,
367+ message : 'Unable to upload build scan' ,
368+ reason : `${ JSON . stringify ( error . response ?. data ) } ` ,
369+ } ;
370+ }
371+
372+ if ( error . response ?. status === 500 ) {
373+ return {
374+ upload : 'fail' ,
375+ message : 'Unable to upload build scan' ,
376+ reason : 'Internal Server Error' ,
377+ } ;
378+ }
379+ }
380+ return {
381+ upload : 'fail' ,
382+ message : 'Unable to upload build scan' ,
383+ } ;
384+ }
385+ } catch ( error ) {
386+ return Promise . reject ( error ) ;
387+ }
388+ } ) ;
339389} ;
340390
341391module . exports = registerRendererEventHandlers ;
0 commit comments