Finish Add Instance Flow #1
5 arquivos alterados com 63 adições e 3 exclusões
Proxying
commit
490c2a8080
28
Cargo.lock
gerado
28
Cargo.lock
gerado
|
|
@ -279,6 +279,7 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||||
name = "fedirect"
|
name = "fedirect"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"rocket",
|
"rocket",
|
||||||
"semver",
|
"semver",
|
||||||
|
|
@ -367,6 +368,17 @@ version = "0.3.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-macro"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "futures-sink"
|
name = "futures-sink"
|
||||||
version = "0.3.31"
|
version = "0.3.31"
|
||||||
|
|
@ -388,6 +400,7 @@ dependencies = [
|
||||||
"futures-channel",
|
"futures-channel",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
"futures-io",
|
||||||
|
"futures-macro",
|
||||||
"futures-sink",
|
"futures-sink",
|
||||||
"futures-task",
|
"futures-task",
|
||||||
"memchr",
|
"memchr",
|
||||||
|
|
@ -1318,11 +1331,13 @@ dependencies = [
|
||||||
"system-configuration",
|
"system-configuration",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-native-tls",
|
"tokio-native-tls",
|
||||||
|
"tokio-util",
|
||||||
"tower",
|
"tower",
|
||||||
"tower-service",
|
"tower-service",
|
||||||
"url",
|
"url",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
|
"wasm-streams",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"windows-registry",
|
"windows-registry",
|
||||||
]
|
]
|
||||||
|
|
@ -2159,6 +2174,19 @@ version = "0.2.99"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6"
|
checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasm-streams"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b65dc4c90b63b118468cf747d8bf3566c1913ef60be765b5730ead9e0a3ba129"
|
||||||
|
dependencies = [
|
||||||
|
"futures-util",
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
"wasm-bindgen-futures",
|
||||||
|
"web-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.76"
|
version = "0.3.76"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest = "0.12.12"
|
bytes = "1.9.0"
|
||||||
|
reqwest = { version = "0.12.12", features = ["stream"] }
|
||||||
rocket = { version = "0.5.1", features = ["json"] }
|
rocket = { version = "0.5.1", features = ["json"] }
|
||||||
semver = "1.0.24"
|
semver = "1.0.24"
|
||||||
serde = { version = "1.0.217", features = ["derive"] }
|
serde = { version = "1.0.217", features = ["derive"] }
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
use rocket::Route;
|
use rocket::Route;
|
||||||
|
|
||||||
pub mod instance_info;
|
pub mod instance_info;
|
||||||
|
pub mod proxy;
|
||||||
|
|
||||||
pub fn get_routes() -> Vec<Route> {
|
pub fn get_routes() -> Vec<Route> {
|
||||||
routes![instance_info::instance_info]
|
routes![instance_info::instance_info, proxy::proxy]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
30
src/api/proxy.rs
Arquivo normal
30
src/api/proxy.rs
Arquivo normal
|
|
@ -0,0 +1,30 @@
|
||||||
|
use bytes::Bytes;
|
||||||
|
use rocket::response::stream::ByteStream;
|
||||||
|
|
||||||
|
/// Copy-pasted and modified from https://github.com/rwf2/Rocket/issues/1521
|
||||||
|
mod req {
|
||||||
|
use super::*;
|
||||||
|
use rocket::response::Debug;
|
||||||
|
|
||||||
|
pub type Result<T, E = Debug<reqwest::Error>> = std::result::Result<T, E>;
|
||||||
|
|
||||||
|
pub async fn get(url: &str) -> Result<ByteStream![Bytes]> {
|
||||||
|
let bytes_stream = reqwest::get(url).await?.bytes_stream();
|
||||||
|
Ok(ByteStream! {
|
||||||
|
for await bytes in bytes_stream {
|
||||||
|
match bytes {
|
||||||
|
Ok(bytes) => yield bytes,
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("error while streaming: {}", e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/proxy/<url>")]
|
||||||
|
pub async fn proxy(url: &str) -> req::Result<ByteStream![Bytes]> {
|
||||||
|
req::get(url).await
|
||||||
|
}
|
||||||
|
|
@ -55,7 +55,7 @@ export function initializeInstanceDetailsDialog(
|
||||||
instanceHost.value = instanceHostValue;
|
instanceHost.value = instanceHostValue;
|
||||||
instanceHostSecure.checked = instanceHostSecureValue;
|
instanceHostSecure.checked = instanceHostSecureValue;
|
||||||
instanceSoftware.value = instanceSoftwareValue;
|
instanceSoftware.value = instanceSoftwareValue;
|
||||||
instanceIcon.src = instanceIconValue ?? blankImage;
|
instanceIcon.src = instanceIconValue === null ? blankImage : `/api/proxy/${encodeURIComponent(instanceIconValue)}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
form.addEventListener("submit", e => {
|
form.addEventListener("submit", e => {
|
||||||
|
|
|
||||||
Carregando…
Adicionar tabela
Adicionar um link
Referência em uma nova issue