server/app/ws/routes/fs.release.js

32 lines
870 B
JavaScript
Raw Normal View History

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()
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 01:57:37 +00:00
message.send_response(
message.fresh()
)
}