You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

const { Errors } = require('../../shared')
const { NodeDescriptorType } = require('../../enum')
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',
mode: 16877, // TODO account for the mode from the client!
descriptor_type: NodeDescriptorType.Directory,
size: 100,
})
await node.save()
message.send_response(
message.fresh().data({ node: node.to_api() })
)
}