2020-11-27 05:37:06 +00:00
|
|
|
const fs = require('fs')
|
|
|
|
|
|
|
|
const exists = async file => {
|
|
|
|
return new Promise(res => {
|
|
|
|
fs.promises.stat(file).then(() => res(true)).catch(() => res(false))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-27 01:57:37 +00:00
|
|
|
module.exports = exports = async (message, di) => {
|
|
|
|
const { descriptor } = message.data()
|
|
|
|
|
2020-11-27 05:37:06 +00:00
|
|
|
const node_uuid = message.socket.session.file_descriptors?.[descriptor]
|
|
|
|
if ( node_uuid ) {
|
2020-11-27 01:57:37 +00:00
|
|
|
delete message.socket.session.file_descriptors[descriptor]
|
|
|
|
}
|
|
|
|
|
2020-11-29 17:53:55 +00:00
|
|
|
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]
|
2020-11-27 05:37:06 +00:00
|
|
|
}
|
|
|
|
|
2020-11-27 01:57:37 +00:00
|
|
|
message.send_response(
|
|
|
|
message.fresh()
|
|
|
|
)
|
|
|
|
}
|