sffc / socketio-file-upload

Uploads files to a Node.JS server using Socket.IO
321 stars 84 forks source link

Client details async #90

Open xeroxstar opened 5 years ago

xeroxstar commented 5 years ago

Hello, The client details that returns to the browser after the upload is completed should have return promise also. for example:

let uploader = new siofu();
    uploader.on('saved', async (event) => {
        event.file.clientDetail = new Promise((x) => {
            x({data: 'hello world'});
        })
 });
 uploader.dir = "./uploads";
 uploader.listen(socket);

to solve it i edit few lines in server.js to make it work:

socket.emit(_getTopicName("_complete"), _wrapData({
            id: id,
            success: success,
            detail: typeof fileInfo.clientDetail.then === 'function' ? await fileInfo.clientDetail:fileInfo.clientDetail
}, "complete"));

i think it will be a nice option if we will have this in the module so devs will have more flexible way to work with the data. Anyway, it works great.

sffc commented 5 years ago

Looks good. My only feedback is if you can make this work without the "await" keyword, then the same source can be used on older versions of Node.js. Can you open a PR?