11import fs from 'fs' ;
22import FormData from 'form-data' ;
33import axios , { AxiosInstance , AxiosRequestConfig } from 'axios' ;
4- import { Env , ProcessedSnapshot , Git , Build , Context } from '../types.js' ;
4+ import { Env , Snapshot , ProcessedSnapshot , Git , Build , Context } from '../types.js' ;
55import constants from './constants.js' ;
66import type { Logger } from 'winston'
77import pkgJSON from './../../package.json'
@@ -36,7 +36,6 @@ export default class httpClient {
3636 if ( config && config . data ) {
3737 log . debug ( config . data ) ;
3838 }
39-
4039 return this . axiosInstance . request ( config )
4140 . then ( resp => {
4241 log . debug ( `http response: ${ JSON . stringify ( {
@@ -131,6 +130,24 @@ export default class httpClient {
131130 } , ctx . log )
132131 }
133132
133+ processSnapshot ( ctx : Context , snapshot : ProcessedSnapshot , snapshotUuid : string ) {
134+ return this . request ( {
135+ url : `/build/${ ctx . build . id } /snapshot` ,
136+ method : 'POST' ,
137+ headers : { 'Content-Type' : 'application/json' } ,
138+ data : {
139+ name : snapshot . name ,
140+ url : snapshot . url ,
141+ snapshotUuid : snapshotUuid ,
142+ test : {
143+ type : ctx . testType ,
144+ source : 'cli'
145+ } ,
146+ async : false ,
147+ }
148+ } , ctx . log )
149+ }
150+
134151 uploadScreenshot (
135152 { id : buildId , name : buildName , baseline } : Build ,
136153 ssPath : string , ssName : string , browserName :string , viewport : string , log : Logger
@@ -210,6 +227,19 @@ export default class httpClient {
210227 } , ctx . log )
211228 }
212229
230+ getS3PresignedURLForSnapshotUpload ( ctx : Context , snapshotName : string , snapshotUuid : string ) {
231+ return this . request ( {
232+ url : `/snapshotuploadurl` ,
233+ method : 'POST' ,
234+ headers : { 'Content-Type' : 'application/json' } ,
235+ data : {
236+ buildId : ctx . build . id ,
237+ snapshotName : snapshotName ,
238+ snapshotUuid : snapshotUuid
239+ }
240+ } , ctx . log )
241+ }
242+
213243 uploadLogs ( ctx : Context , uploadURL : string ) {
214244 const fileStream = fs . createReadStream ( constants . LOG_FILE_PATH ) ;
215245 const { size } = fs . statSync ( constants . LOG_FILE_PATH ) ;
@@ -227,6 +257,19 @@ export default class httpClient {
227257 } , ctx . log )
228258 }
229259
260+ uploadSnapshotToS3 ( ctx : Context , uploadURL : string , snapshot : Snapshot ) {
261+ return this . request ( {
262+ url : uploadURL ,
263+ method : 'PUT' ,
264+ headers :{
265+ 'Content-Type' : 'application/json' ,
266+ } ,
267+ data : snapshot ,
268+ maxBodyLength : Infinity , // prevent axios from limiting the body size
269+ maxContentLength : Infinity , // prevent axios from limiting the content size
270+ } , ctx . log )
271+ }
272+
230273 processWebFigma ( requestBody : any , log : Logger ) {
231274 return this . request ( {
232275 url : "figma-web/upload" ,
0 commit comments