mirror of
https://github.com/xevidos/codiad.git
synced 2024-11-10 21:26:35 +01:00
Continued work on new uploader
This commit is contained in:
parent
0fd4f782ef
commit
fd11904f89
@ -287,9 +287,6 @@ switch( $action ) {
|
|||||||
|
|
||||||
case 'upload':
|
case 'upload':
|
||||||
|
|
||||||
echo var_dump( $_GET );
|
|
||||||
echo var_dump( $_POST );
|
|
||||||
|
|
||||||
if( ! isset( $_POST["data"] ) ) {
|
if( ! isset( $_POST["data"] ) ) {
|
||||||
|
|
||||||
$response["status"] = "error";
|
$response["status"] = "error";
|
||||||
@ -299,7 +296,19 @@ switch( $action ) {
|
|||||||
exit( json_encode( $response ) );
|
exit( json_encode( $response ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$blob = $_POST["data"];
|
if( $_POST["data"] !== "data:" ) {
|
||||||
|
|
||||||
|
$blob = @file_get_contents( $_POST["data"] );
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$response["status"] = "error";
|
||||||
|
$response["data"] = array(
|
||||||
|
"error" => "No blob given",
|
||||||
|
"data" => $_POST["data"],
|
||||||
|
);
|
||||||
|
exit( json_encode( $response ) );
|
||||||
|
}
|
||||||
|
|
||||||
$response = $Filemanager->upload( $path, $blob );
|
$response = $Filemanager->upload( $path, $blob );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1647,7 +1647,7 @@
|
|||||||
|
|
||||||
entry.file( function( file ) {
|
entry.file( function( file ) {
|
||||||
|
|
||||||
_this.upload_blobs( file, destination );
|
_this.upload_blobs( file, destination + file.name );
|
||||||
});
|
});
|
||||||
} else if( entry.isDirectory ) {
|
} else if( entry.isDirectory ) {
|
||||||
|
|
||||||
@ -1656,7 +1656,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
upload_blob: async function( blob, path ) {
|
upload_blob: function( blob, path ) {
|
||||||
|
|
||||||
|
return new Promise( function( resolve, reject ) {
|
||||||
|
|
||||||
let _this = codiad.filemanager;
|
let _this = codiad.filemanager;
|
||||||
let form = new FormData();
|
let form = new FormData();
|
||||||
@ -1669,47 +1671,65 @@
|
|||||||
data: form,
|
data: form,
|
||||||
processData: false,
|
processData: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
}).done( function( data ) {
|
success: function( data ) {
|
||||||
|
|
||||||
console.log( data );
|
resolve( data );
|
||||||
|
},
|
||||||
|
error: function( data ) {
|
||||||
|
|
||||||
|
reject( data );
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
upload_blobs: function( file, path ) {
|
upload_blobs: function( file, path, start = 0, status = null ) {
|
||||||
|
|
||||||
console.log( file, path );
|
console.log( file, path );
|
||||||
let _this = codiad.filemanager;
|
let _this = codiad.filemanager;
|
||||||
let blob_size = 1024;
|
let blob_size = 1024*1024;
|
||||||
let total_size = file.size;
|
let total_size = file.size;
|
||||||
let current = 0 + blob_size;
|
|
||||||
|
if( total_size < blob_size ) {
|
||||||
|
|
||||||
|
blob_size = total_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
let current = start + blob_size;
|
||||||
let reader = new FileReader();
|
let reader = new FileReader();
|
||||||
let blob = file.slice( current, current + blob_size );
|
let blob = file.slice( current, current + blob_size );
|
||||||
let upload_status = null;
|
let upload_status = null;
|
||||||
let file_path = path;
|
|
||||||
|
|
||||||
if( path.charAt( path.length - 1 ) !== '/' ) {
|
if( status === null ) {
|
||||||
|
|
||||||
file_path = file_path + '/';
|
status = $().toastmessage( 'showToast', {
|
||||||
|
text: 'Uploading blobs 0%',
|
||||||
|
sticky: true,
|
||||||
|
position: 'top-right',
|
||||||
|
type: 'warning',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
reader.onload = async function( e ) {
|
reader.onload = async function( e ) {
|
||||||
|
|
||||||
upload_status = await _this.upload_blob( blob, file_path );
|
upload_status = await _this.upload_blob( e.target.result, path );
|
||||||
console.log( upload_status );
|
try {
|
||||||
|
|
||||||
while( current <= total_size && typeof upload_status === "Boolean" ) {
|
console.log( upload_status )
|
||||||
|
|
||||||
console.log( ( current / total_size ) * 100 );
|
let result = JSON.parse( upload_status );
|
||||||
blob = file.slice( current, current + blob_size );
|
if( result.bytes > 0 && current <= total_size ) {
|
||||||
let upload_status = await _this.upload_blob( blob, file_path );
|
|
||||||
|
|
||||||
console.log( upload_status );
|
status.text( ( ( current / total_size )*100 ).toFixed( 2 ) + '%' );
|
||||||
|
_this.upload_blobs( file, path, current, status );
|
||||||
|
}
|
||||||
|
} catch( exception ) {
|
||||||
|
|
||||||
reader.readAsBinaryString( blob );
|
console.log( 'done?', upload_status );
|
||||||
|
console.log( exception )
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
reader.readAsBinaryString( blob );
|
reader.readAsDataURL( blob );
|
||||||
},
|
},
|
||||||
|
|
||||||
upload_data: {
|
upload_data: {
|
||||||
|
Loading…
Reference in New Issue
Block a user