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

40 lines
1020 B
JavaScript

const { Errors } = require('../../shared')
const { NodeDescriptorType } = require('../../enum')
module.exports = exports = async (message, di) => {
const Node = di.models.get('fs:Node')
const { path } = message.data()
if ( !path ) {
return message.send_response(
message.fresh().error(Errors.NodeDoesNotExist)
)
}
if ( path === '/' ) {
return message.send_response(
message.fresh.error(Errors.NodePermissionFail)
)
}
const node = await Node.get_path(path, message.socket.session.overlay_name || 'mainline')
if ( !node ) {
return message.send_response(
message.fresh().error(Errors.NodeDoesNotExist)
)
}
if ( node.descriptor_type === NodeDescriptorType.Directory ) {
return message.send_response(
message.fresh().error(Errors.IsDirectoryDescriptor)
)
}
node.deleted = true
await node.save()
message.send_response(
message.fresh()
)
}