const fs = require('fs') const exists = async file => { return new Promise(res => { fs.promises.stat(file).then(() => res(true)).catch(() => res(false)) }) } module.exports = exports = async (message, di) => { const { descriptor } = message.data() const node_uuid = message.socket.session.file_descriptors?.[descriptor] if ( node_uuid ) { delete message.socket.session.file_descriptors[descriptor] } const placeholders = message.socket.session.temp_write_files?.[descriptor] if ( placeholders ) { for ( const placeholder of placeholders ) { if ( await exists(placeholder.path) ) { await fs.promises.unlink(placeholder.path) } } delete message.socket.session.temp_write_files[descriptor] } message.send_response( message.fresh() ) }