delint
parent
a1d8227eb0
commit
dd31b877a2
23
src/main.rs
23
src/main.rs
|
@ -9,19 +9,16 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
|||
mod stream;
|
||||
|
||||
fn mangle_account(post: &mut serde_json::Value) {
|
||||
match post {
|
||||
serde_json::Value::Object(ref mut obj) => {
|
||||
if let Entry::Occupied(mut account) = obj.entry("account") {
|
||||
let id = account.get_mut().get_mut("acct").map(|id| id.take());
|
||||
match id {
|
||||
Some(id) =>
|
||||
account.insert(id),
|
||||
None =>
|
||||
account.remove(),
|
||||
};
|
||||
}
|
||||
if let serde_json::Value::Object(ref mut obj) = post {
|
||||
if let Entry::Occupied(mut account) = obj.entry("account") {
|
||||
let id = account.get_mut().get_mut("acct").map(serde_json::Value::take);
|
||||
match id {
|
||||
Some(id) =>
|
||||
account.insert(id),
|
||||
None =>
|
||||
account.remove(),
|
||||
};
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +40,7 @@ async fn main() {
|
|||
let default_debug = "buzz2elastic=info".into();
|
||||
tracing_subscriber::registry()
|
||||
.with(
|
||||
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| default_debug),
|
||||
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or(default_debug),
|
||||
)
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
|
|
@ -7,27 +7,27 @@ use tokio::{
|
|||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum StreamError {
|
||||
pub enum Error {
|
||||
Http(reqwest::Error),
|
||||
HttpStatus(reqwest::StatusCode),
|
||||
InvalidContentType,
|
||||
}
|
||||
|
||||
async fn run(host: &str) -> Result<impl Stream<Item = String>, StreamError> {
|
||||
async fn run(host: &str) -> Result<impl Stream<Item = String>, Error> {
|
||||
let url = format!("https://{}/api/v1/streaming/public", host);
|
||||
let client = reqwest::Client::new();
|
||||
let res = client.get(url)
|
||||
.timeout(Duration::MAX)
|
||||
.send()
|
||||
.await
|
||||
.map_err(StreamError::Http)?;
|
||||
.map_err(Error::Http)?;
|
||||
if res.status() != 200 {
|
||||
return Err(StreamError::HttpStatus(res.status()));
|
||||
return Err(Error::HttpStatus(res.status()));
|
||||
}
|
||||
let ct = res.headers().get("content-type")
|
||||
.and_then(|c| c.to_str().ok());
|
||||
if ct.map_or(true, |ct| ct != "text/event-stream") {
|
||||
return Err(StreamError::InvalidContentType);
|
||||
return Err(Error::InvalidContentType);
|
||||
}
|
||||
|
||||
let src = res.bytes_stream()
|
||||
|
|
Loading…
Reference in New Issue