Merge branch 'develop' into dr/eth-multi-chain

This commit is contained in:
dr-frmr 2024-02-22 12:12:48 -03:00
commit d85c98df4c
No known key found for this signature in database
18 changed files with 234 additions and 245 deletions

33
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -0,0 +1,33 @@
---
name: Bug report
about: Create a report to help us improve
title: 'bug: '
labels: 'bug'
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Kinode version [e.g. v1.0.0]
- process_lib version [e.g. v1.0.0]
**Additional context**
Add any other context about the problem here.

View File

@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: 'feature: '
labels: 'enhancement'
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

4
Cargo.lock generated
View File

@ -956,7 +956,7 @@ dependencies = [
"anyhow",
"base64 0.13.1",
"bincode",
"kinode_process_lib 0.6.0 (git+https://github.com/kinode-dao/process_lib?rev=12bf9ee)",
"kinode_process_lib 0.6.0 (git+https://github.com/kinode-dao/process_lib?rev=3232423)",
"pleco",
"serde",
"serde_json",
@ -2709,7 +2709,7 @@ dependencies = [
[[package]]
name = "kit"
version = "0.1.0"
source = "git+https://github.com/kinode-dao/kit?rev=f96cdaa#f96cdaa022ec8d0ff675bce3b92bd436236881ea"
source = "git+https://github.com/kinode-dao/kit?rev=83d1e86#83d1e86203f5a7d239c7d89aa0375167f1af6cdc"
dependencies = [
"anyhow",
"autocontext",

View File

@ -14,7 +14,7 @@ path = "src/main.rs"
[build-dependencies]
anyhow = "1.0.71"
kit = { git = "https://github.com/kinode-dao/kit", rev = "f96cdaa" }
kit = { git = "https://github.com/kinode-dao/kit", rev = "83d1e86" }
rayon = "1.8.1"
sha2 = "0.10"
tokio = "1.28"

View File

@ -47,6 +47,15 @@ pub fn handle_http_request(
Ok(())
}
fn get_package_id(url_params: &HashMap<String, String>) -> anyhow::Result<PackageId> {
let Some(package_id) = url_params.get("id") else {
return Err(anyhow::anyhow!("Missing id"));
};
let id = package_id.parse::<PackageId>()?;
Ok(id)
}
fn gen_package_info(
id: &PackageId,
listing: Option<&PackageListing>,
@ -94,23 +103,10 @@ fn serve_paths(
requested_packages: &mut HashMap<PackageId, RequestedPackage>,
req: &IncomingHttpRequest,
) -> anyhow::Result<(StatusCode, Option<HashMap<String, String>>, Vec<u8>)> {
let path = req.path()?;
let method = req.method()?;
// TODO get rid of this workaround when we change `IncomingHttpRequest`
let bound_path: &str = if path.ends_with("auto-update") {
"/apps/:id/auto-update"
} else if path.ends_with("mirror") {
"/apps/:id/mirror"
} else if path.ends_with("caps") {
"/apps/:id/caps"
} else if path.starts_with("/apps/listed/") {
"/apps/listed/:id"
} else if &path == "/apps/listed" || &path == "/apps" {
&path
} else {
"/apps/:id"
};
let bound_path: &str = req.bound_path(Some(&our.process.to_string()));
let url_params = req.url_params();
// print_to_terminal(0, &format!("HTTP {method} {path} {bound_path}"));
@ -121,7 +117,7 @@ fn serve_paths(
return Ok((
StatusCode::METHOD_NOT_ALLOWED,
None,
format!("Invalid method {method} for {path}").into_bytes(),
format!("Invalid method {method} for {bound_path}").into_bytes(),
));
}
let all: Vec<serde_json::Value> = state
@ -140,7 +136,7 @@ fn serve_paths(
return Ok((
StatusCode::METHOD_NOT_ALLOWED,
None,
format!("Invalid method {method} for {path}").into_bytes(),
format!("Invalid method {method} for {bound_path}").into_bytes(),
));
}
let all: Vec<serde_json::Value> = state
@ -159,11 +155,14 @@ fn serve_paths(
// update a downloaded app: PUT
// uninstall/delete a downloaded app: DELETE
"/apps/:id" => {
let package_id = path
.split("/")
.last()
.unwrap_or_default()
.parse::<PackageId>()?;
let Ok(package_id) = get_package_id(url_params) else {
return Ok((
StatusCode::BAD_REQUEST,
None,
format!("Missing id").into_bytes(),
));
};
match method {
Method::GET => {
let Some(pkg) = state.downloaded_packages.get(&package_id) else {
@ -234,18 +233,21 @@ fn serve_paths(
_ => Ok((
StatusCode::METHOD_NOT_ALLOWED,
None,
format!("Invalid method {method} for {path}").into_bytes(),
format!("Invalid method {method} for {bound_path}").into_bytes(),
)),
}
}
// GET detail about a specific listed app
// download a listed app: POST
"/apps/listed/:id" => {
let package_id = path
.split("/")
.last()
.unwrap_or_default()
.parse::<PackageId>()?;
let Ok(package_id) = get_package_id(url_params) else {
return Ok((
StatusCode::BAD_REQUEST,
None,
format!("Missing id").into_bytes(),
));
};
match method {
Method::GET => {
let Some(listing) = state.get_listing(&package_id) else {
@ -318,18 +320,21 @@ fn serve_paths(
_ => Ok((
StatusCode::METHOD_NOT_ALLOWED,
None,
format!("Invalid method {method} for {path}").into_bytes(),
format!("Invalid method {method} for {bound_path}").into_bytes(),
)),
}
}
// GET caps for a specific downloaded app
// approve capabilities for a downloaded app: POST
"/apps/:id/caps" => {
let package_id = path
.split("/")
.nth(2)
.unwrap_or_default()
.parse::<PackageId>()?;
let Ok(package_id) = get_package_id(url_params) else {
return Ok((
StatusCode::BAD_REQUEST,
None,
format!("Missing id").into_bytes(),
));
};
match method {
// return the capabilities for that app
Method::GET => Ok(match crate::fetch_package_manifest(&package_id) {
@ -356,18 +361,21 @@ fn serve_paths(
_ => Ok((
StatusCode::METHOD_NOT_ALLOWED,
None,
format!("Invalid method {method} for {path}").into_bytes(),
format!("Invalid method {method} for {bound_path}").into_bytes(),
)),
}
}
// start mirroring a downloaded app: PUT
// stop mirroring a downloaded app: DELETE
"/apps/:id/mirror" => {
let package_id = path
.split("/")
.nth(2)
.unwrap_or_default()
.parse::<PackageId>()?;
let Ok(package_id) = get_package_id(url_params) else {
return Ok((
StatusCode::BAD_REQUEST,
None,
format!("Missing id").into_bytes(),
));
};
match method {
// start mirroring an app
Method::PUT => {
@ -382,18 +390,21 @@ fn serve_paths(
_ => Ok((
StatusCode::METHOD_NOT_ALLOWED,
None,
format!("Invalid method {method} for {path}").into_bytes(),
format!("Invalid method {method} for {bound_path}").into_bytes(),
)),
}
}
// start auto-updating a downloaded app: PUT
// stop auto-updating a downloaded app: DELETE
"/apps/:id/auto-update" => {
let package_id = path
.split("/")
.nth(2)
.unwrap_or_default()
.parse::<PackageId>()?;
let Ok(package_id) = get_package_id(url_params) else {
return Ok((
StatusCode::BAD_REQUEST,
None,
format!("Missing id").into_bytes(),
));
};
match method {
// start auto-updating an app
Method::PUT => {
@ -408,14 +419,14 @@ fn serve_paths(
_ => Ok((
StatusCode::METHOD_NOT_ALLOWED,
None,
format!("Invalid method {method} for {path}").into_bytes(),
format!("Invalid method {method} for {bound_path}").into_bytes(),
)),
}
}
_ => Ok((
StatusCode::NOT_FOUND,
None,
format!("Path not found: {}", path).into_bytes(),
format!("Path not found: {bound_path}").into_bytes(),
)),
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -18,8 +18,8 @@
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1.00001, viewport-fit=cover"
/>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet'>
<script type="module" crossorigin src="/main:app_store:sys/assets/index-Wv-dWa0C.js"></script>
<link rel="stylesheet" crossorigin href="/main:app_store:sys/assets/index-aUqPNadJ.css">
<script type="module" crossorigin src="/main:app_store:sys/assets/index-5QTuaL_D.js"></script>
<link rel="stylesheet" crossorigin href="/main:app_store:sys/assets/index-SoWN8KT-.css">
</head>
<body>
<div id="root"></div>

View File

@ -8,7 +8,7 @@ edition = "2021"
anyhow = "1.0"
base64 = "0.13"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "3232423" }
pleco = "0.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@ -193,7 +193,7 @@ fn handle_request(our: &Address, message: &Message, state: &mut ChessState) -> a
}
}
}
http::HttpServerRequest::WebSocketOpen { path, channel_id } => {
http::HttpServerRequest::WebSocketOpen { channel_id, .. } => {
// We know this is authenticated and unencrypted because we only
// bound one path, the root path. So we know that client
// frontend opened a websocket and can send updates
@ -419,7 +419,7 @@ fn handle_http_request(
state: &mut ChessState,
http_request: &http::IncomingHttpRequest,
) -> anyhow::Result<()> {
if http_request.path()? != "/games" {
if http_request.bound_path(Some(&our.process.to_string())) != "/games" {
http::send_response(
http::StatusCode::NOT_FOUND,
None,
@ -454,6 +454,7 @@ fn handle_http_request(
vec![],
));
};
if let Some(game) = state.games.get(game_id)
&& !game.ended
{

View File

@ -178,7 +178,7 @@
a {
color: white;
margin-bottom: 2em;
margin-bottom: 1em;
}
a:visited {
@ -196,9 +196,8 @@
</div>
<h3 id="uq-name">Welcome ${our}!</h3>
<h4>Apps:</h4>
<h3>Apps:</h3>
<a id="app-store" href="/main:app_store:sys/">App Store</a>
<br />
<a id="chess" href="/chess:chess:sys/">Chess</a>
</div>
<script>window.ourName = window.our = '${our}'</script>

View File

@ -1,12 +1,12 @@
{
"files": {
"main.css": "/static/css/main.74f501c5.css",
"main.js": "/static/js/main.77d268ea.js",
"main.js": "/static/js/main.084b4a46.js",
"static/media/unknown.png": "/static/media/unknown.880d04d4611a45ab1001.png",
"index.html": "/index.html"
},
"entrypoints": [
"static/css/main.74f501c5.css",
"static/js/main.77d268ea.js"
"static/js/main.084b4a46.js"
]
}

File diff suppressed because one or more lines are too long

15
pull_request_template.md Normal file
View File

@ -0,0 +1,15 @@
## Problem
{A brief description of the problem, along with necessary context.}
## Solution
{A brief description of how you solved the problem.}
## Docs Update
[Corresponding docs PR](https://github.com/kinode-dao/kinode-book/pull/my-pr-number)
## Notes
{Any other information useful for reviewers.}