@@ -11,11 +11,12 @@ import { generateSettings } from "../settings";
1111import { uuidv4 } from '../utils/setup_utils' ;
1212import { removeFile } from '../utils/file_utils' ;
1313import { pathUtils } from '../utils/path_utils' ;
14- import { uploadFileTos3 } from '../utils/upload_utils' ;
14+ import { uploadFileTos3 , uploadFileToGCS } from '../utils/upload_utils' ;
1515import { CodeSyncLogger } from '../logger' ;
1616import { CODESYNC_STATES , CodeSyncState } from '../utils/state_utils' ;
1717import { IS3UploaderFile , IS3UploaderPreProcess } from '../interface' ;
1818import { S3_UPLOADR_RETRY_AFTER } from '../constants' ;
19+ import { UserUtils } from "../utils/user_utils" ;
1920
2021
2122export class s3UploaderUtils {
@@ -272,26 +273,46 @@ class s3Uploader extends s3UploaderUtils {
272273 return await this . processTasks ( 0 ) ;
273274 }
274275
275- createTasks = async ( content : IS3UploaderFile ) => {
276- // Proceess the given file and create parallelTasks
277- const pathUtils_ = new pathUtils ( this . repoPath , content . branch ) ;
278- this . originalsRepoBranchPath = pathUtils_ . getOriginalsRepoBranchPath ( ) ;
279- const fileRelPaths = Object . keys ( content . file_path_and_urls ) ;
280- if ( ! fileRelPaths || isEmpty ( content . file_path_and_urls ) ) return ;
281- this . filePathAndURLs = < any > { } ;
282- // Skip files which don't exist in .originals or don't have URL
283- fileRelPaths . sort ( ) . forEach ( fileRelPath => {
284- const originalsFilePath = path . join ( this . originalsRepoBranchPath , fileRelPath ) ;
285- if ( ! fs . existsSync ( originalsFilePath ) ) return ;
286- const presignedURL = content . file_path_and_urls [ fileRelPath ] ;
287- if ( ! presignedURL ) return removeFile ( originalsFilePath , "s3Uploader.deleting-originals-file" ) ;
288- this . filePathAndURLs [ fileRelPath ] = presignedURL ;
289- this . tasks . push ( async function ( callback : any ) {
290- const json = < any > await uploadFileTos3 ( originalsFilePath , presignedURL ) ;
291- callback ( json . error , originalsFilePath ) ;
292- } ) ;
293- } ) ;
294- }
276+ createTasks = async ( content : IS3UploaderFile ) => {
277+ // Proceess the given file and create parallelTasks
278+ const pathUtils_ = new pathUtils ( this . repoPath , content . branch ) ;
279+ this . originalsRepoBranchPath = pathUtils_ . getOriginalsRepoBranchPath ( ) ;
280+ const fileRelPaths = Object . keys ( content . file_path_and_urls ) ;
281+ if ( ! fileRelPaths || isEmpty ( content . file_path_and_urls ) ) return ;
282+ this . filePathAndURLs = < any > { } ;
283+ // Skip files which don't exist in .originals or don't have URL
284+ fileRelPaths . sort ( ) . forEach ( ( fileRelPath ) => {
285+ const originalsFilePath = path . join (
286+ this . originalsRepoBranchPath ,
287+ fileRelPath
288+ ) ;
289+ if ( ! fs . existsSync ( originalsFilePath ) ) return ;
290+ const presignedURL = content . file_path_and_urls [ fileRelPath ] ;
291+ if ( ! presignedURL )
292+ return removeFile (
293+ originalsFilePath ,
294+ "s3Uploader.deleting-originals-file"
295+ ) ;
296+ this . filePathAndURLs [ fileRelPath ] = presignedURL ;
297+ this . tasks . push ( async function ( callback : any ) {
298+ const userUtils = new UserUtils ( ) ;
299+ const activeUser : any = userUtils . getActiveUser ( ) ;
300+ let users = < any > { } ;
301+ users = readYML ( generateSettings ( ) . USER_PATH ) || { } ;
302+ let json : any = null ;
303+ let key : any = null ;
304+ if ( activeUser && activeUser ?. email in users ) {
305+ key = users [ activeUser . email ] . gcp_private_key ;
306+ }
307+ if ( key ) {
308+ json = < any > await uploadFileToGCS ( originalsFilePath , presignedURL ) ;
309+ } else {
310+ json = < any > await uploadFileTos3 ( originalsFilePath , presignedURL ) ;
311+ }
312+ callback ( json . error , originalsFilePath ) ;
313+ } ) ;
314+ } ) ;
315+ } ;
295316
296317 processTasks = async ( startIndex : number ) => {
297318 if ( ! await this . shouldProceed ( ) ) return ;
0 commit comments