recycleactor commited on
Commit
2905dc1
·
verified ·
1 Parent(s): e1c6aeb

Upload src/main.rs

Browse files
Files changed (1) hide show
  1. src/main.rs +14 -5
src/main.rs CHANGED
@@ -20,6 +20,8 @@ use cbc::Decryptor;
20
  use reqwest::{cookie::Jar, Url};
21
  use reqwest::header::ACCEPT;
22
 
 
 
23
  mod api;
24
  use api::{APIClient, APIError, Format};
25
 
@@ -228,9 +230,16 @@ async fn stream(State(state): State<Arc<RwLock<APIClient>>>, Query(q): Query<Str
228
 
229
  let mut upstream = upstream.bytes_stream();
230
 
231
- let out = async_stream::try_stream! {
232
- while let Some(chunk) = upstream.next().await {
233
- let chunk = chunk.map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, "upstream"))?;
 
 
 
 
 
 
 
234
  carry.extend_from_slice(&chunk);
235
 
236
  while carry.len() >= 2048 {
@@ -239,12 +248,12 @@ async fn stream(State(state): State<Arc<RwLock<APIClient>>>, Query(q): Query<Str
239
  let _ = decrypt_stripe(&mut block, &key);
240
  }
241
  block_index += 1;
242
- yield Bytes::from(block);
243
  }
244
  }
245
 
246
  if !carry.is_empty() {
247
- yield Bytes::from(carry);
248
  }
249
  };
250
 
 
20
  use reqwest::{cookie::Jar, Url};
21
  use reqwest::header::ACCEPT;
22
 
23
+ type BoxErr = Box<dyn std::error::Error + Send + Sync + 'static>;
24
+
25
  mod api;
26
  use api::{APIClient, APIError, Format};
27
 
 
230
 
231
  let mut upstream = upstream.bytes_stream();
232
 
233
+ let out = async_stream::stream! {
234
+ while let Some(chunk_res) = upstream.next().await {
235
+ let chunk = match chunk_res {
236
+ Ok(c) => c,
237
+ Err(e) => {
238
+ yield Err::<Bytes, BoxErr>(Box::new(e));
239
+ break;
240
+ }
241
+ };
242
+
243
  carry.extend_from_slice(&chunk);
244
 
245
  while carry.len() >= 2048 {
 
248
  let _ = decrypt_stripe(&mut block, &key);
249
  }
250
  block_index += 1;
251
+ yield Ok::<Bytes, BoxErr>(Bytes::from(block));
252
  }
253
  }
254
 
255
  if !carry.is_empty() {
256
+ yield Ok::<Bytes, BoxErr>(Bytes::from(std::mem::take(&mut carry)));
257
  }
258
  };
259