Local dapps embeddable on signer port (#2815)

This commit is contained in:
Tomasz Drwięga 2016-10-24 16:36:15 +02:00 committed by Gav Wood
parent 487da9c9c6
commit 16ec413508
5 changed files with 18 additions and 11 deletions

View File

@ -46,6 +46,7 @@ pub struct ContentFetcher<R: URLHint = URLHintContract> {
resolver: R,
cache: Arc<Mutex<ContentCache>>,
sync: Arc<SyncStatus>,
embeddable_at: Option<u16>,
}
impl<R: URLHint> Drop for ContentFetcher<R> {
@ -57,7 +58,7 @@ impl<R: URLHint> Drop for ContentFetcher<R> {
impl<R: URLHint> ContentFetcher<R> {
pub fn new(resolver: R, sync_status: Arc<SyncStatus>) -> Self {
pub fn new(resolver: R, sync_status: Arc<SyncStatus>, embeddable_at: Option<u16>) -> Self {
let mut dapps_path = env::temp_dir();
dapps_path.push(random_filename());
@ -66,6 +67,7 @@ impl<R: URLHint> ContentFetcher<R> {
resolver: resolver,
sync: sync_status,
cache: Arc::new(Mutex::new(ContentCache::default())),
embeddable_at: embeddable_at,
}
}
@ -152,6 +154,7 @@ impl<R: URLHint> ContentFetcher<R> {
id: content_id.clone(),
dapps_path: self.dapps_path.clone(),
on_done: Box::new(on_done),
embeddable_at: self.embeddable_at,
}
);
@ -276,6 +279,7 @@ struct DappInstaller {
id: String,
dapps_path: PathBuf,
on_done: Box<Fn(String, Option<LocalPageEndpoint>) + Send>,
embeddable_at: Option<u16>,
}
impl DappInstaller {
@ -368,7 +372,7 @@ impl ContentValidator for DappInstaller {
try!(manifest_file.write_all(manifest_str.as_bytes()));
// Create endpoint
let app = LocalPageEndpoint::new(target, manifest.clone().into());
let app = LocalPageEndpoint::new(target, manifest.clone().into(), self.embeddable_at);
// Return modified app manifest
Ok((manifest.id.clone(), app))
@ -401,14 +405,14 @@ mod tests {
fn should_true_if_contains_the_app() {
// given
let path = env::temp_dir();
let fetcher = ContentFetcher::new(FakeResolver, Arc::new(|| false));
let fetcher = ContentFetcher::new(FakeResolver, Arc::new(|| false), None);
let handler = LocalPageEndpoint::new(path, EndpointInfo {
name: "fake".into(),
description: "".into(),
version: "".into(),
author: "".into(),
icon_url: "".into(),
});
}, None);
// when
fetcher.set_status("test", ContentStatus::Ready(handler));

View File

@ -97,12 +97,12 @@ fn read_manifest(name: &str, mut path: PathBuf) -> EndpointInfo {
})
}
pub fn local_endpoints(dapps_path: String) -> Endpoints {
pub fn local_endpoints(dapps_path: String, signer_port: Option<u16>) -> Endpoints {
let mut pages = Endpoints::new();
for dapp in local_dapps(dapps_path) {
pages.insert(
dapp.id,
Box::new(LocalPageEndpoint::new(dapp.path, dapp.info))
Box::new(LocalPageEndpoint::new(dapp.path, dapp.info, signer_port))
);
}
pages

View File

@ -47,7 +47,7 @@ pub fn utils() -> Box<Endpoint> {
pub fn all_endpoints(dapps_path: String, signer_port: Option<u16>) -> Endpoints {
// fetch fs dapps at first to avoid overwriting builtins
let mut pages = fs::local_endpoints(dapps_path);
let mut pages = fs::local_endpoints(dapps_path, signer_port);
// NOTE [ToDr] Dapps will be currently embeded on 8180
insert::<parity_ui::App>(&mut pages, "ui", Embeddable::Yes(signer_port));

View File

@ -218,7 +218,7 @@ impl Server {
) -> Result<Server, ServerError> {
let panic_handler = Arc::new(Mutex::new(None));
let authorization = Arc::new(authorization);
let content_fetcher = Arc::new(apps::fetcher::ContentFetcher::new(apps::urlhint::URLHintContract::new(registrar), sync_status));
let content_fetcher = Arc::new(apps::fetcher::ContentFetcher::new(apps::urlhint::URLHintContract::new(registrar), sync_status, signer_port));
let endpoints = Arc::new(apps::all_endpoints(dapps_path, signer_port.clone()));
let cors_domains = Self::cors_domains(signer_port);

View File

@ -26,14 +26,16 @@ pub struct LocalPageEndpoint {
path: PathBuf,
mime: Option<String>,
info: Option<EndpointInfo>,
embeddable_at: Option<u16>,
}
impl LocalPageEndpoint {
pub fn new(path: PathBuf, info: EndpointInfo) -> Self {
pub fn new(path: PathBuf, info: EndpointInfo, embeddable_at: Option<u16>) -> Self {
LocalPageEndpoint {
path: path,
mime: None,
info: Some(info),
embeddable_at: embeddable_at,
}
}
@ -42,6 +44,7 @@ impl LocalPageEndpoint {
path: path,
mime: Some(mime),
info: None,
embeddable_at: None,
}
}
@ -62,7 +65,7 @@ impl Endpoint for LocalPageEndpoint {
prefix: None,
path: path,
file: handler::ServedFile::new(None),
safe_to_embed_at_port: None,
safe_to_embed_at_port: self.embeddable_at,
})
} else {
Box::new(handler::PageHandler {
@ -70,7 +73,7 @@ impl Endpoint for LocalPageEndpoint {
prefix: None,
path: path,
file: handler::ServedFile::new(None),
safe_to_embed_at_port: None,
safe_to_embed_at_port: self.embeddable_at,
})
}
}