@@ -121,26 +121,28 @@ class TransferFunc extends Component {
121121 const repoName = 'TxDOT' ;
122122 const branch = 'main' ;
123123
124- const getFileSHA = async ( ) => {
124+ const getFileSHA = async ( filePath ) => {
125125 try {
126126 const res = await axios . get (
127- `https://api.github.com/repos/${ repoOwner } /${ repoName } /contents/${ filePath } ?ref=${ branch } ` , {
127+ `https://api.github.com/repos/${ repoOwner } /${ repoName } /contents/${ filePath } ?ref=${ branch } ` ,
128+ {
128129 headers : {
129130 Authorization : `token ${ token } ` ,
130131 } ,
131132 }
132133 ) ;
133- return res . data . sha ;
134+ return res . data . sha ; // File exists, return its SHA
134135 } catch ( err ) {
135- console . warn ( 'File does not exist, creating a new one' ) ;
136- return null ; // File doesn't exist, so no SHA to pass
136+ console . warn ( ` ${ filePath } does not exist, creating a new one` ) ;
137+ return null ; // File doesn't exist, return null to create a new file
137138 }
138139 } ;
139140
140141 this . setState ( {
141142 loading : true
142143 } ) ;
143- const sha = await getFileSHA ( ) ;
144+ const shaTransferFuncVar = await getFileSHA ( filePath ) ;
145+ const shaPackageJson = await getFileSHA ( 'package.json' ) ;
144146 this . setState ( {
145147 loading : false
146148 } ) ; // Reset loading after the request is done
@@ -163,8 +165,9 @@ class TransferFunc extends Component {
163165 try {
164166 const response = await axios . put (
165167 `https://api.github.com/repos/${ repoOwner } /${ repoName } /contents/${ filePath } ` , {
166- message : sha ? 'Update TransferFuncVar.js file' : 'Create TransferFuncVar.js file' ,
168+ message : shaTransferFuncVar ? 'Update TransferFuncVar.js file' : 'Create TransferFuncVar.js file' ,
167169 content : content ,
170+ sha : shaTransferFuncVar ,
168171 branch : branch ,
169172 } , {
170173 headers : {
@@ -177,6 +180,7 @@ class TransferFunc extends Component {
177180 `https://api.github.com/repos/${ repoOwner } /${ repoName } /contents/package.json` , {
178181 message : 'Update package.json version' ,
179182 content : contentPackageJson ,
183+ sha : shaPackageJson ,
180184 branch : branch ,
181185 } , {
182186 headers : {
@@ -188,6 +192,7 @@ class TransferFunc extends Component {
188192
189193 // Show success alert
190194 alert ( 'File uploaded successfully!' ) ;
195+ this . props . toMenu ( ) ;
191196 } catch ( error ) {
192197 console . error ( 'Error uploading file' , error ) ;
193198
0 commit comments