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

25 lines
749 B
JavaScript
Raw Permalink Normal View History

2020-11-27 19:18:37 +00:00
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()
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.Symlink ) {
return message.send_response(
message.fresh().error(Errors.NodeAlreadyExists)
)
}
message.send_response(
message.fresh().data({ node: node.to_api(), link: node.symlink_path })
)
}