-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip on changing the server to support different manifest structure
- Loading branch information
Caspar Oostendorp
committed
Apr 27, 2024
1 parent
64c72c6
commit 53c93be
Showing
5 changed files
with
42 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,48 @@ | ||
use serde_json::json; | ||
use axum::extract::Path; | ||
use axum::http::StatusCode; | ||
use axum::{Extension, Json}; | ||
use axum::response::IntoResponse; | ||
use dojo_world::manifest::Manifest; | ||
use dojo_world::manifest::{AbstractManifestError, DeploymentManifest}; | ||
use crate::server_state::ServerState; | ||
use std::fs; | ||
use std::io::ErrorKind; | ||
use starknet::core::types::FieldElement; | ||
use starknet::providers::jsonrpc::HttpTransport; | ||
use starknet::providers::JsonRpcClient; | ||
|
||
// pub async fn store_manifest(Path(app_name): Path<String>, Extension(server_state): Extension<ServerState>, Json(manifest): Json<Manifest<T>>) -> impl IntoResponse { | ||
// let path = &server_state.manifest_base_dir; | ||
// if !std::path::Path::new(path).exists() { | ||
// if let Err(_) = fs::create_dir_all(path) { | ||
// return (StatusCode::INTERNAL_SERVER_ERROR, "Server Error"); | ||
// } | ||
// } | ||
// let path = format!("{}/{}.json", &server_state.manifest_base_dir, app_name); | ||
// match fs::metadata(&path) { | ||
// Ok(_) => (StatusCode::IM_USED, "Already uploaded"), | ||
// Err(ref e) if e.kind() == ErrorKind::NotFound => { | ||
// let json = serde_json::to_string(&manifest).unwrap(); | ||
// match fs::write(path, json) { | ||
// Ok(_) => (StatusCode::CREATED, "Stored manifest"), | ||
// Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Server error") | ||
// } | ||
// } | ||
// Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Server error"), | ||
// } | ||
// } | ||
|
||
pub async fn get_manifest(Path(app_name): Path<String>, Extension(server_state): Extension<ServerState>) -> impl IntoResponse { | ||
let path = format!("{}/{}.json", &server_state.manifest_base_dir, app_name); | ||
println!("{}", path); | ||
match fs::read_to_string(&path) { | ||
Ok(content) => (StatusCode::OK, content), | ||
Err(ref e) if e.kind() == ErrorKind::NotFound => (StatusCode::NOT_FOUND, "Not Found".into()), | ||
Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Server error".into()), | ||
pub async fn get_manifest( | ||
Path(app_name): Path<String>, | ||
Extension(server_state): Extension<ServerState>, | ||
) | ||
-> impl IntoResponse | ||
{ | ||
let provider = JsonRpcClient::new(HttpTransport::new( | ||
server_state.rpc_url | ||
)); | ||
|
||
// let manifest = DeploymentManifest::load_from_remote(provider, FieldElement::from(server_state.world_address)).await?; | ||
let world_address = FieldElement::from_hex_be(server_state.world_address.as_str()).unwrap(); | ||
|
||
|
||
match DeploymentManifest::load_from_remote(provider, world_address).await { | ||
Ok(manifest) => { | ||
let world_json = serde_json::to_value(&manifest.base).unwrap(); | ||
(StatusCode::OK, Json(world_json)) | ||
} | ||
|
||
_ => (StatusCode::NOT_FOUND, Json(serde_json::json!("Not found"))) | ||
} | ||
|
||
// | ||
// if remote_manifest.is_none() { | ||
// ui.print_sub("No remote World found"); | ||
// } | ||
// | ||
// match fs::read_to_string(&path) { | ||
// Ok(content) => (StatusCode::OK, manifest), | ||
// Err(ref e) if e.kind() == ErrorKind::NotFound => (StatusCode::NOT_FOUND, "Not Found".into()), | ||
// Err(_) => (StatusCode::INTERNAL_SERVER_ERROR, "Server error".into()), | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters