52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
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.NotDirectoryDescriptor)
|
||
|
)
|
||
|
}
|
||
|
|
||
|
const child = await Node.findOne({
|
||
|
pied_parent_path: path,
|
||
|
overlay_name: message.socket.session.overlay_name || 'mainline',
|
||
|
deleted: false,
|
||
|
})
|
||
|
|
||
|
if ( child ) {
|
||
|
return message.send_response(
|
||
|
message.fresh().error(Errors.NodeNotEmpty)
|
||
|
)
|
||
|
}
|
||
|
|
||
|
node.deleted = true
|
||
|
await node.save()
|
||
|
|
||
|
message.send_response(
|
||
|
message.fresh()
|
||
|
)
|
||
|
}
|