2020-11-27 01:57:37 +00:00
|
|
|
const { Errors } = require('../../shared')
|
2020-11-27 19:18:37 +00:00
|
|
|
const { NodeDescriptorType, NodeModeType } = require('../../enum')
|
2020-11-27 01:57:37 +00:00
|
|
|
|
|
|
|
module.exports = exports = async (message, di) => {
|
|
|
|
const Node = di.models.get('fs:Node')
|
|
|
|
const { path, mode } = message.data()
|
|
|
|
|
|
|
|
if ( !path ) {
|
|
|
|
return message.send_response(
|
|
|
|
message.fresh().error(Errors.NodeDoesNotExist)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( path === '/' ) {
|
|
|
|
return message.send_response(
|
|
|
|
message.fresh.error(Errors.NodeAlreadyExists)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const existing_node = await Node.get_path(path, message.socket.session.overlay_name || 'mainline')
|
|
|
|
if ( existing_node ) {
|
|
|
|
return message.send_response(
|
|
|
|
message.fresh().error(Errors.NodeAlreadyExists)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const [pied_parent_path, pied_name] = Node.path_parts(path)
|
|
|
|
const node = new Node({
|
|
|
|
pied_name,
|
|
|
|
pied_parent_path,
|
|
|
|
overlay_name: message.socket.session.overlay_name || 'mainline',
|
2020-11-27 19:18:37 +00:00
|
|
|
mode: NodeModeType.Directory, // TODO account for the mode from the client!
|
2020-11-27 01:57:37 +00:00
|
|
|
descriptor_type: NodeDescriptorType.Directory,
|
|
|
|
size: 100,
|
|
|
|
})
|
|
|
|
|
|
|
|
await node.save()
|
|
|
|
|
|
|
|
message.send_response(
|
|
|
|
message.fresh().data({ node: node.to_api() })
|
|
|
|
)
|
|
|
|
}
|