mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-24 06:35:39 +00:00
Add Imfs to ServeSession, threading through generic ImfsFetcher
This commit is contained in:
@@ -70,7 +70,7 @@ pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
|
|||||||
let patch_set = compute_patch_set(&snapshot, &tree, root_id);
|
let patch_set = compute_patch_set(&snapshot, &tree, root_id);
|
||||||
apply_patch_set(&mut tree, &patch_set);
|
apply_patch_set(&mut tree, &patch_set);
|
||||||
|
|
||||||
let session = Arc::new(ServeSession::new(tree, maybe_project));
|
let session = Arc::new(ServeSession::new(imfs, tree, maybe_project));
|
||||||
let server = LiveServer::new(session);
|
let server = LiveServer::new(session);
|
||||||
|
|
||||||
server.start(port);
|
server.start(port);
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
message_queue::MessageQueue, project::Project, session_id::SessionId, snapshot::RojoTree,
|
imfs::new::{Imfs, ImfsFetcher},
|
||||||
|
message_queue::MessageQueue,
|
||||||
|
project::Project,
|
||||||
|
session_id::SessionId,
|
||||||
|
snapshot::RojoTree,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Contains all of the state for a Rojo serve session.
|
/// Contains all of the state for a Rojo serve session.
|
||||||
pub struct ServeSession {
|
pub struct ServeSession<F> {
|
||||||
root_project: Option<Project>,
|
root_project: Option<Project>,
|
||||||
session_id: SessionId,
|
session_id: SessionId,
|
||||||
tree: RojoTree,
|
tree: RojoTree,
|
||||||
message_queue: MessageQueue<()>, // TODO: Real message type
|
message_queue: MessageQueue<()>, // TODO: Real message type
|
||||||
|
imfs: Imfs<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServeSession {
|
impl<F: ImfsFetcher> ServeSession<F> {
|
||||||
pub fn new(tree: RojoTree, root_project: Option<Project>) -> ServeSession {
|
pub fn new(imfs: Imfs<F>, tree: RojoTree, root_project: Option<Project>) -> Self {
|
||||||
let session_id = SessionId::new();
|
let session_id = SessionId::new();
|
||||||
let message_queue = MessageQueue::new();
|
let message_queue = MessageQueue::new();
|
||||||
|
|
||||||
@@ -22,6 +27,7 @@ impl ServeSession {
|
|||||||
root_project,
|
root_project,
|
||||||
tree,
|
tree,
|
||||||
message_queue,
|
message_queue,
|
||||||
|
imfs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use hyper::{header, service::Service, Body, Method, Request, Response, StatusCod
|
|||||||
use rbx_dom_weak::RbxId;
|
use rbx_dom_weak::RbxId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
imfs::new::ImfsFetcher,
|
||||||
serve_session::ServeSession,
|
serve_session::ServeSession,
|
||||||
web::{
|
web::{
|
||||||
interface::{
|
interface::{
|
||||||
@@ -19,11 +20,11 @@ use crate::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct ApiService {
|
pub struct ApiService<F> {
|
||||||
serve_session: Arc<ServeSession>,
|
serve_session: Arc<ServeSession<F>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service for ApiService {
|
impl<F: ImfsFetcher> Service for ApiService<F> {
|
||||||
type ReqBody = Body;
|
type ReqBody = Body;
|
||||||
type ResBody = Body;
|
type ResBody = Body;
|
||||||
type Error = hyper::Error;
|
type Error = hyper::Error;
|
||||||
@@ -42,13 +43,13 @@ impl Service for ApiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApiService {
|
impl<F: ImfsFetcher> ApiService<F> {
|
||||||
pub fn new(serve_session: Arc<ServeSession>) -> ApiService {
|
pub fn new(serve_session: Arc<ServeSession<F>>) -> Self {
|
||||||
ApiService { serve_session }
|
ApiService { serve_session }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a summary of information about the server
|
/// Get a summary of information about the server
|
||||||
fn handle_api_rojo(&self) -> <ApiService as Service>::Future {
|
fn handle_api_rojo(&self) -> <Self as Service>::Future {
|
||||||
let tree = self.serve_session.tree();
|
let tree = self.serve_session.tree();
|
||||||
let root_instance_id = tree.get_root_id();
|
let root_instance_id = tree.get_root_id();
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ impl ApiService {
|
|||||||
|
|
||||||
/// Retrieve any messages past the given cursor index, and if
|
/// Retrieve any messages past the given cursor index, and if
|
||||||
/// there weren't any, subscribe to receive any new messages.
|
/// there weren't any, subscribe to receive any new messages.
|
||||||
fn handle_api_subscribe(&self, request: Request<Body>) -> <ApiService as Service>::Future {
|
fn handle_api_subscribe(&self, request: Request<Body>) -> <Self as Service>::Future {
|
||||||
let argument = &request.uri().path()["/api/subscribe/".len()..];
|
let argument = &request.uri().path()["/api/subscribe/".len()..];
|
||||||
let _input_cursor: u32 = match argument.parse() {
|
let _input_cursor: u32 = match argument.parse() {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
@@ -93,7 +94,7 @@ impl ApiService {
|
|||||||
// })
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_api_read(&self, request: Request<Body>) -> <ApiService as Service>::Future {
|
fn handle_api_read(&self, request: Request<Body>) -> <Self as Service>::Future {
|
||||||
let argument = &request.uri().path()["/api/read/".len()..];
|
let argument = &request.uri().path()["/api/read/".len()..];
|
||||||
let requested_ids: Option<Vec<RbxId>> = argument.split(',').map(RbxId::parse_str).collect();
|
let requested_ids: Option<Vec<RbxId>> = argument.split(',').map(RbxId::parse_str).collect();
|
||||||
|
|
||||||
|
|||||||
@@ -12,16 +12,16 @@ use futures::{
|
|||||||
use hyper::{service::Service, Body, Request, Response, Server};
|
use hyper::{service::Service, Body, Request, Response, Server};
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
use crate::serve_session::ServeSession;
|
use crate::{imfs::new::ImfsFetcher, serve_session::ServeSession};
|
||||||
|
|
||||||
use self::{api::ApiService, ui::UiService};
|
use self::{api::ApiService, ui::UiService};
|
||||||
|
|
||||||
pub struct RootService {
|
pub struct RootService<F> {
|
||||||
api: ApiService,
|
api: ApiService<F>,
|
||||||
ui: UiService,
|
ui: UiService<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service for RootService {
|
impl<F: ImfsFetcher> Service for RootService<F> {
|
||||||
type ReqBody = Body;
|
type ReqBody = Body;
|
||||||
type ResBody = Body;
|
type ResBody = Body;
|
||||||
type Error = hyper::Error;
|
type Error = hyper::Error;
|
||||||
@@ -38,8 +38,8 @@ impl Service for RootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RootService {
|
impl<F: ImfsFetcher> RootService<F> {
|
||||||
pub fn new(serve_session: Arc<ServeSession>) -> RootService {
|
pub fn new(serve_session: Arc<ServeSession<F>>) -> Self {
|
||||||
RootService {
|
RootService {
|
||||||
api: ApiService::new(Arc::clone(&serve_session)),
|
api: ApiService::new(Arc::clone(&serve_session)),
|
||||||
ui: UiService::new(Arc::clone(&serve_session)),
|
ui: UiService::new(Arc::clone(&serve_session)),
|
||||||
@@ -47,12 +47,12 @@ impl RootService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct LiveServer {
|
pub struct LiveServer<F> {
|
||||||
serve_session: Arc<ServeSession>,
|
serve_session: Arc<ServeSession<F>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LiveServer {
|
impl<F: ImfsFetcher + Send + Sync + 'static> LiveServer<F> {
|
||||||
pub fn new(serve_session: Arc<ServeSession>) -> LiveServer {
|
pub fn new(serve_session: Arc<ServeSession<F>>) -> Self {
|
||||||
LiveServer { serve_session }
|
LiveServer { serve_session }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ use hyper::{header, service::Service, Body, Method, Request, Response, StatusCod
|
|||||||
use ritz::html;
|
use ritz::html;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
imfs::new::ImfsFetcher,
|
||||||
serve_session::ServeSession,
|
serve_session::ServeSession,
|
||||||
web::{
|
web::{
|
||||||
interface::{NotFoundError, SERVER_VERSION},
|
interface::{NotFoundError, SERVER_VERSION},
|
||||||
@@ -16,12 +17,12 @@ use crate::{
|
|||||||
|
|
||||||
static HOME_CSS: &str = include_str!("../../assets/index.css");
|
static HOME_CSS: &str = include_str!("../../assets/index.css");
|
||||||
|
|
||||||
pub struct UiService {
|
pub struct UiService<F> {
|
||||||
#[allow(unused)] // TODO: Fill out interface service
|
#[allow(unused)] // TODO: Fill out interface service
|
||||||
serve_session: Arc<ServeSession>,
|
serve_session: Arc<ServeSession<F>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service for UiService {
|
impl<F: ImfsFetcher> Service for UiService<F> {
|
||||||
type ReqBody = Body;
|
type ReqBody = Body;
|
||||||
type ResBody = Body;
|
type ResBody = Body;
|
||||||
type Error = hyper::Error;
|
type Error = hyper::Error;
|
||||||
@@ -39,8 +40,8 @@ impl Service for UiService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UiService {
|
impl<F: ImfsFetcher> UiService<F> {
|
||||||
pub fn new(serve_session: Arc<ServeSession>) -> UiService {
|
pub fn new(serve_session: Arc<ServeSession<F>>) -> Self {
|
||||||
UiService { serve_session }
|
UiService { serve_session }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user