Expose tree in API, with hacks to make initial sync-in work sort of

This commit is contained in:
Lucien Greathouse
2019-09-10 15:39:50 -07:00
parent 6a786f18e6
commit e6ba6203bb
3 changed files with 66 additions and 17 deletions

View File

@@ -12,8 +12,8 @@ use crate::{
serve_session::ServeSession,
web::{
interface::{
NotFoundError, ReadResponse, ServerInfoResponse, SubscribeResponse, PROTOCOL_VERSION,
SERVER_VERSION,
Instance, NotFoundError, ReadResponse, ServerInfoResponse, SubscribeResponse,
PROTOCOL_VERSION, SERVER_VERSION,
},
util::{json, json_ok},
},
@@ -94,8 +94,8 @@ impl ApiService {
let argument = &request.uri().path()["/api/read/".len()..];
let requested_ids: Option<Vec<RbxId>> = argument.split(',').map(RbxId::parse_str).collect();
let _requested_ids = match requested_ids {
Some(id) => id,
let requested_ids = match requested_ids {
Some(ids) => ids,
None => {
return Box::new(future::ok(
Response::builder()
@@ -110,7 +110,20 @@ impl ApiService {
let message_queue = self.serve_session.message_queue();
let message_cursor = message_queue.cursor();
let instances = HashMap::new(); // TODO
let tree = self.serve_session.tree();
let inner_tree = tree.inner();
let mut instances = HashMap::new();
for id in requested_ids {
if let Some(instance) = inner_tree.get_instance(id) {
instances.insert(id, Instance::from_rbx_instance(instance));
for descendant in inner_tree.descendants(id) {
instances.insert(descendant.get_id(), Instance::from_rbx_instance(descendant));
}
}
}
json_ok(ReadResponse {
session_id: self.serve_session.session_id(),