import fileUpload from "/elements/fileUpload.js"; import fileIcon from "./fileManager.icon.js"; #ifdef SERVER import fs from "fs"; import path from "path"; //import android from 'androidjs'; #endif export default class stream extends fileUpload { placeholder = "Upload." margin = 20; stream; type; /* inputType = "button"; click( event ) { //this.android_file_chooser(); //var fileChooser = this.parent.fileChooser; //fileChooser.show("flex") //fileChooser.open(); } */ async change( event ) { var input = this.customElement; var files = input.files; for (var i = 0; i < files.length; i++) { var file = files[i]; var chunksize = 64 * 1024; var offset = 0; var filename = file.name.replaceAll(" ", "_"); await this.createStream( filename ); while( offset < file.size ) { const chunkfile = await file.slice( offset, offset + chunksize ); const chunk = await chunkfile.arrayBuffer(); var intChunk = new Int8Array( chunk ); this.writeChunk( intChunk ) offset += chunksize; } await this.endstream(); } } node async createStream( filename ) { var absolutePath = path.resolve( "./assets/uploads/" + filename ); this.filename = filename; console.log("Writing file to path", absolutePath); this.stream = fs.createWriteStream( absolutePath, { encoding: 'binary' } ); this.stream.on('finish', function() { console.log('file has been written'); }); } node async writeChunk( chunk ) { this.stream.write( Buffer.from( Object.values( chunk ) ) ); } node async endstream() { this.stream.end(); var currentFileIcon = new fileIcon(); currentFileIcon.value = this.filename; this.parent.fileList.add( currentFileIcon ); } node async android_file_chooser() { //const status = app.mobiledata.isEnabled(); //console.log(android); //console.log("Mobile Data status: ", android); //console.log(app.mobiledata.isEnabled()); } //mouseover() { // console.log("mouseover??", this.parent.removeIcons) // if( this.parent.removeIcons.mode == "wiggle" ) { // this.parent.removeIcons.click(); // } //} }