@@ -706,77 +706,82 @@ export class ProjectService {
706706 userId : string ,
707707 projectId : string ,
708708 ) : Promise < { zipPath : string ; fileName : string } > {
709-
710709 // Get the project
711710 const project = await this . getProjectById ( projectId ) ;
712-
711+
713712 // Check ownership or if project is public
714713 if ( project . userId !== userId && ! project . isPublic ) {
715714 throw new ForbiddenException (
716715 'You do not have permission to download this project' ,
717716 ) ;
718717 }
719-
718+
720719 // Ensure the project path exists
721720 const projectPath = getProjectPath ( project . projectPath ) ;
722721 this . logger . debug ( `Project path: ${ projectPath } ` ) ;
723-
722+
724723 if ( ! fs . existsSync ( projectPath ) ) {
725724 throw new NotFoundException (
726725 `Project directory not found at ${ projectPath } ` ,
727726 ) ;
728727 }
729-
728+
730729 // Create a temporary directory for the zip file if it doesn't exist
731730 const tempDir = getTempDir ( ) ;
732731 if ( ! fs . existsSync ( tempDir ) ) {
733732 fs . mkdirSync ( tempDir , { recursive : true } ) ;
734733 }
735-
734+
736735 // Generate a filename for the zip
737736 const fileName = `${ project . projectName . replace ( / [ ^ a - z 0 - 9 ] / gi, '_' ) } _${ Date . now ( ) } .zip` ;
738737 const zipPath = path . join ( tempDir , fileName ) ;
739-
738+
740739 // Create a write stream for the zip file
741740 const output = fs . createWriteStream ( zipPath ) ;
742741 const archive = archiver ( 'zip' , {
743742 zlib : { level : 9 } , // Set the compression level
744743 } ) ;
745-
744+
746745 // Listen for errors
747746 output . on ( 'error' , ( err ) => {
748747 throw new InternalServerErrorException (
749748 `Error creating zip file: ${ err . message } ` ,
750749 ) ;
751750 } ) ;
752-
751+
753752 // Pipe the archive to the output file
754753 archive . pipe ( output ) ;
755754
756755 // Filter unwanted files/folders
757756 const ignored = [ 'node_modules' , '.git' , '.gitignore' , '.env' ] ;
758-
757+
759758 // Add the project directory to the archive
760- archive . glob ( '**/*' , {
761- cwd : projectPath ,
762- ignore : ignored . map ( pattern => `**/${ pattern } /**` ) . concat ( ignored ) ,
763- dot : true
764- } , { } ) ;
765-
759+ archive . glob (
760+ '**/*' ,
761+ {
762+ cwd : projectPath ,
763+ ignore : ignored . map ( ( pattern ) => `**/${ pattern } /**` ) . concat ( ignored ) ,
764+ dot : true ,
765+ } ,
766+ { } ,
767+ ) ;
768+
766769 // Finalize the archive
767770 await archive . finalize ( ) ;
768-
771+
769772 // Wait for the output stream to finish
770773 await new Promise < void > ( ( resolve , reject ) => {
771774 output . on ( 'close' , ( ) => {
772- this . logger . debug ( `Created zip file: ${ zipPath } , size: ${ archive . pointer ( ) } bytes` ) ;
775+ this . logger . debug (
776+ `Created zip file: ${ zipPath } , size: ${ archive . pointer ( ) } bytes` ,
777+ ) ;
773778 resolve ( ) ;
774779 } ) ;
775780 output . on ( 'error' , ( err ) => {
776781 reject ( err ) ;
777782 } ) ;
778783 } ) ;
779-
784+
780785 return { zipPath, fileName } ;
781786 }
782787
@@ -788,18 +793,21 @@ export class ProjectService {
788793 async syncProjectToGitHub (
789794 userId : string ,
790795 projectId : string ,
791- isPublic : boolean , // the user decides if the new repo is public or private
796+ isPublic : boolean , // the user decides if the new repo is public or private
792797 ) : Promise < Project > {
793-
794798 const user = await this . userService . getUser ( userId ) ;
795-
799+
796800 // 1) Find the project
797- const project = await this . projectsRepository . findOne ( { where : { id : projectId } } ) ;
801+ const project = await this . projectsRepository . findOne ( {
802+ where : { id : projectId } ,
803+ } ) ;
798804 if ( ! project ) {
799805 throw new Error ( 'Project not found' ) ;
800806 }
801-
802- this . logger . log ( "check if the github project exist: " + project . isSyncedWithGitHub ) ;
807+
808+ this . logger . log (
809+ 'check if the github project exist: ' + project . isSyncedWithGitHub ,
810+ ) ;
803811 // 2) Check user’s GitHub installation
804812 if ( ! user . githubInstallationId ) {
805813 throw new Error ( 'GitHub App not installed for this user' ) ;
@@ -816,15 +824,15 @@ export class ProjectService {
816824 // Use project.projectName or generate a safe name
817825
818826 // TODO: WHEN REPO NAME EXIST
819- const repoName = project . projectName
820- . replace ( / \s + / g, '-' )
821- . toLowerCase ( ) // e.g. "my-project"
822- + '-' + " ChangeME" ; // to make it unique if needed
827+ const repoName =
828+ project . projectName . replace ( / \s + / g, '-' ) . toLowerCase ( ) + // e.g. "my-project"
829+ '-' +
830+ ' ChangeME' ; // to make it unique if needed
823831
824832 const { owner, repo, htmlUrl } = await this . gitHubService . createUserRepo (
825833 repoName ,
826834 isPublic ,
827- userOAuthToken
835+ userOAuthToken ,
828836 ) ;
829837
830838 project . githubRepoName = repo ;
0 commit comments