34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
const { Errors } = require('../../shared')
|
|
const { NodeDescriptorType } = require('../../enum')
|
|
|
|
module.exports = exports = async (message, di) => {
|
|
const send_error = (err) => message.send_response(
|
|
message.fresh().error(err)
|
|
)
|
|
|
|
const new_fd = (node_uuid) => {
|
|
if ( !message.socket.session.last_file_descriptor ) {
|
|
message.socket.session.last_file_descriptor = 0
|
|
message.socket.session.file_descriptors = {}
|
|
}
|
|
|
|
message.socket.session.last_file_descriptor += 1
|
|
message.socket.session.file_descriptors[message.socket.session.last_file_descriptor] = node_uuid
|
|
return message.socket.session.last_file_descriptor
|
|
}
|
|
|
|
const Node = di.models.get('fs:Node')
|
|
const { path, flags } = message.data()
|
|
|
|
if ( !path ) return send_error(Errors.NodeDoesNotExist)
|
|
if ( path === '/' ) return send_error(Errors.IsDirectoryDescriptor)
|
|
|
|
const node = await Node.get_path(path, message.socket.session.overlay_name || 'mainline')
|
|
if ( !node ) send_error(Errors.NodeDoesNotExist)
|
|
if ( node.descriptor_type === NodeDescriptorType.Directory ) send_error(Errors.IsDirectoryDescriptor)
|
|
|
|
message.send_response(
|
|
message.fresh().data({ node: node.to_api(), descriptor: new_fd(node.uuid) })
|
|
)
|
|
}
|