29 lines
751 B
JavaScript
29 lines
751 B
JavaScript
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) => {
|
|
console.log('[RELEASE]')
|
|
const { descriptor } = message.data()
|
|
|
|
const node_uuid = message.socket.session.file_descriptors?.[descriptor]
|
|
if ( node_uuid ) {
|
|
delete message.socket.session.file_descriptors[descriptor]
|
|
}
|
|
|
|
const placeholder = message.socket.session.temp_write_files?.[node_uuid]
|
|
if ( placeholder && (await exists(placeholder.path)) ) {
|
|
await fs.promises.unlink(placeholder.path)
|
|
}
|
|
|
|
message.send_response(
|
|
message.fresh()
|
|
)
|
|
|
|
console.log('[/RELEASE]')
|
|
}
|