@@ -25,6 +25,7 @@ import * as commonStorage from '../storage/common_storage';
2525import * as storageNames from '../storage/names' ;
2626import * as storageProject from '../storage/project' ;
2727import * as createPythonFiles from '../storage/create_python_files' ;
28+ import * as serverSideStorage from '../storage/server_side_storage' ;
2829import * as I18Next from 'react-i18next' ;
2930import { TabType } from '../types/TabType' ;
3031
@@ -294,17 +295,45 @@ export function Component(props: MenuProps): React.JSX.Element {
294295
295296 try {
296297 const blobUrl = await createPythonFiles . producePythonProjectBlob ( props . project , props . storage ) ;
297-
298- // Create a temporary link to download the file
299- const link = document . createElement ( 'a' ) ;
300- link . href = blobUrl ;
301- link . download = `${ props . project . projectName } .zip` ;
302- document . body . appendChild ( link ) ;
303- link . click ( ) ;
304- document . body . removeChild ( link ) ;
305298
306- // Clean up the blob URL
307- URL . revokeObjectURL ( blobUrl ) ;
299+ // Check if the backend server is available
300+ const serverAvailable = await serverSideStorage . isServerAvailable ( ) ;
301+ console . log ( 'Server available:' , serverAvailable ) ;
302+
303+ if ( serverAvailable ) {
304+ // Send the file to the backend /deploy endpoint
305+ const response = await fetch ( blobUrl ) ;
306+ const blob = await response . blob ( ) ;
307+
308+ const formData = new FormData ( ) ;
309+ formData . append ( 'file' , blob , `${ props . project . projectName } .zip` ) ;
310+
311+ const deployResponse = await fetch ( '/deploy' , {
312+ method : 'POST' ,
313+ body : formData ,
314+ } ) ;
315+
316+ if ( ! deployResponse . ok ) {
317+ throw new Error ( 'Deploy to server failed' ) ;
318+ }
319+
320+ const result = await deployResponse . json ( ) ;
321+ console . log ( 'Deployment successful:' , result ) ;
322+
323+ // Clean up the blob URL
324+ URL . revokeObjectURL ( blobUrl ) ;
325+ } else {
326+ // Download the file locally
327+ const link = document . createElement ( 'a' ) ;
328+ link . href = blobUrl ;
329+ link . download = `${ props . project . projectName } .zip` ;
330+ document . body . appendChild ( link ) ;
331+ link . click ( ) ;
332+ document . body . removeChild ( link ) ;
333+
334+ // Clean up the blob URL
335+ URL . revokeObjectURL ( blobUrl ) ;
336+ }
308337 } catch ( error ) {
309338 console . error ( 'Failed to deploy project:' , error ) ;
310339 props . setAlertErrorMessage ( t ( 'DEPLOY_FAILED' ) || 'Failed to deploy project' ) ;
0 commit comments