mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Strip out web endpoints that are going to be replaced
This commit is contained in:
parent
86d6cc5259
commit
ee1505646e
1 changed files with 3 additions and 104 deletions
|
|
@ -3,10 +3,9 @@ use std::sync::{Arc, Mutex};
|
||||||
use rouille;
|
use rouille;
|
||||||
|
|
||||||
use project::Project;
|
use project::Project;
|
||||||
use vfs::{VfsSession, VfsChange};
|
use vfs::{VfsSession};
|
||||||
use rbx::RbxInstance;
|
|
||||||
use middleware::MiddlewareChain;
|
use middleware::MiddlewareChain;
|
||||||
use web_util::{json, read_json};
|
use web_util::json;
|
||||||
|
|
||||||
/// The set of configuration the web server needs to start.
|
/// The set of configuration the web server needs to start.
|
||||||
pub struct WebConfig {
|
pub struct WebConfig {
|
||||||
|
|
@ -25,31 +24,8 @@ struct ServerInfo<'a> {
|
||||||
current_time: f64,
|
current_time: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
struct ReadResult<'a> {
|
|
||||||
items: Vec<Option<RbxInstance>>,
|
|
||||||
server_id: &'a str,
|
|
||||||
current_time: f64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
struct ChangesResult<'a> {
|
|
||||||
changes: &'a [VfsChange],
|
|
||||||
server_id: &'a str,
|
|
||||||
current_time: f64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
struct WriteSpecifier {
|
|
||||||
route: String,
|
|
||||||
item: RbxInstance,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start the Rojo web server and park our current thread.
|
/// Start the Rojo web server and park our current thread.
|
||||||
pub fn start(config: WebConfig, project: Project, middleware_chain: &'static MiddlewareChain, vfs: Arc<Mutex<VfsSession>>) {
|
pub fn start(config: WebConfig, project: Project, _middleware_chain: &'static MiddlewareChain, vfs: Arc<Mutex<VfsSession>>) {
|
||||||
let address = format!("localhost:{}", config.port);
|
let address = format!("localhost:{}", config.port);
|
||||||
|
|
||||||
let server_id = config.server_id.to_string();
|
let server_id = config.server_id.to_string();
|
||||||
|
|
@ -74,83 +50,6 @@ pub fn start(config: WebConfig, project: Project, middleware_chain: &'static Mid
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
(GET) (/changes/{ last_time: f64 }) => {
|
|
||||||
// Get the list of changes since the given time.
|
|
||||||
|
|
||||||
let vfs = vfs.lock().unwrap();
|
|
||||||
let current_time = vfs.current_time();
|
|
||||||
let changes = vfs.changes_since(last_time);
|
|
||||||
|
|
||||||
json(ChangesResult {
|
|
||||||
changes,
|
|
||||||
server_id: &server_id,
|
|
||||||
current_time,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
(POST) (/read) => {
|
|
||||||
// Read some instances from the server according to a JSON
|
|
||||||
// format body.
|
|
||||||
|
|
||||||
let read_request: Vec<Vec<String>> = match read_json(&request) {
|
|
||||||
Some(v) => v,
|
|
||||||
None => return rouille::Response::empty_400(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Read the files off of the filesystem that the client
|
|
||||||
// requested.
|
|
||||||
let (items, current_time) = {
|
|
||||||
let vfs = vfs.lock().unwrap();
|
|
||||||
|
|
||||||
let current_time = vfs.current_time();
|
|
||||||
|
|
||||||
let mut items = Vec::new();
|
|
||||||
|
|
||||||
for route in &read_request {
|
|
||||||
match vfs.read(&route) {
|
|
||||||
Ok(v) => items.push(Some(v)),
|
|
||||||
Err(_) => items.push(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
(items, current_time)
|
|
||||||
};
|
|
||||||
|
|
||||||
// Transform all of our VfsItem objects into Roblox instances
|
|
||||||
// the client can use.
|
|
||||||
let rbx_items = items
|
|
||||||
.iter()
|
|
||||||
.map(|item| {
|
|
||||||
match *item {
|
|
||||||
Some(ref item) => middleware_chain.transform_file(item),
|
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
if config.verbose {
|
|
||||||
println!("Got read request: {:?}", read_request);
|
|
||||||
println!("Responding with:\n\t{:?}", rbx_items);
|
|
||||||
}
|
|
||||||
|
|
||||||
json(ReadResult {
|
|
||||||
server_id: &server_id,
|
|
||||||
items: rbx_items,
|
|
||||||
current_time,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
(POST) (/write) => {
|
|
||||||
// Not yet implemented.
|
|
||||||
|
|
||||||
let _write_request: Vec<WriteSpecifier> = match read_json(&request) {
|
|
||||||
Some(v) => v,
|
|
||||||
None => return rouille::Response::empty_400(),
|
|
||||||
};
|
|
||||||
|
|
||||||
rouille::Response::empty_404()
|
|
||||||
},
|
|
||||||
|
|
||||||
_ => rouille::Response::empty_404()
|
_ => rouille::Response::empty_404()
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue