Spaces:
Paused
Paused
Upload main.rs
Browse files- src/main.rs +9 -10
src/main.rs
CHANGED
|
@@ -1,13 +1,12 @@
|
|
| 1 |
use axum::{
|
| 2 |
routing::{get, post},
|
| 3 |
http::StatusCode,
|
| 4 |
-
http::{HeaderMap, header::{RANGE, CONTENT_RANGE, ACCEPT_RANGES, CONTENT_LENGTH}},
|
| 5 |
response::{IntoResponse, Html},
|
| 6 |
extract::{Json, State, Query, Form},
|
| 7 |
Router,
|
| 8 |
};
|
| 9 |
use tower_http::{cors::{CorsLayer, Any}, compression::CompressionLayer, trace::TraceLayer};
|
| 10 |
-
use http::{Method, header::CONTENT_TYPE};
|
| 11 |
use serde_json::json;
|
| 12 |
use serde::Deserialize;
|
| 13 |
use std::collections::HashMap;
|
|
@@ -409,7 +408,7 @@ async fn stream_info(State(state): State<AppState>, Query(q): Query<StreamParams
|
|
| 409 |
if url.is_empty() {
|
| 410 |
if let Some(arl) = q.arl.clone().filter(|s| !s.trim().is_empty()) {
|
| 411 |
let client = api_client_for_arl(&state, Some(arl)).await;
|
| 412 |
-
let res = {
|
| 413 |
let mut client = client.lock().await;
|
| 414 |
let resp: Result<DeezerTrackList, APIError> = client
|
| 415 |
.api_call(
|
|
@@ -462,24 +461,24 @@ async fn stream_info(State(state): State<AppState>, Query(q): Query<StreamParams
|
|
| 462 |
.unwrap();
|
| 463 |
let r = http
|
| 464 |
.get(url.clone())
|
| 465 |
-
.header(RANGE, "bytes=0-0")
|
| 466 |
.send()
|
| 467 |
.await;
|
| 468 |
|
| 469 |
let mut total_bytes: u64 = 0;
|
| 470 |
let mut mime: String = String::new();
|
| 471 |
if let Ok(r) = r {
|
| 472 |
-
if let Some(ct) = r.headers().get(CONTENT_TYPE).and_then(|v| v.to_str().ok()) {
|
| 473 |
mime = ct.to_string();
|
| 474 |
}
|
| 475 |
if let Some(cr) = r
|
| 476 |
.headers()
|
| 477 |
-
.get(CONTENT_RANGE)
|
| 478 |
.and_then(|v| v.to_str().ok())
|
| 479 |
.and_then(total_from_content_range)
|
| 480 |
{
|
| 481 |
total_bytes = cr;
|
| 482 |
-
} else if let Some(cl) = r.headers().get(CONTENT_LENGTH).and_then(|v| v.to_str().ok()) {
|
| 483 |
total_bytes = cl.parse::<u64>().unwrap_or(0);
|
| 484 |
}
|
| 485 |
}
|
|
@@ -639,9 +638,9 @@ async fn stream(
|
|
| 639 |
if e >= start {
|
| 640 |
remaining = Some(e - start + 1);
|
| 641 |
}
|
| 642 |
-
req = req.header(RANGE, format!("bytes={}-{}", aligned_start, e));
|
| 643 |
} else {
|
| 644 |
-
req = req.header(RANGE, format!("bytes={}-", aligned_start));
|
| 645 |
}
|
| 646 |
}
|
| 647 |
|
|
@@ -665,7 +664,7 @@ async fn stream(
|
|
| 665 |
let mut carry: Vec<u8> = Vec::with_capacity(4096);
|
| 666 |
let upstream_headers = upstream.headers().clone();
|
| 667 |
let upstream_total = upstream_headers
|
| 668 |
-
.get(CONTENT_RANGE)
|
| 669 |
.and_then(|v| v.to_str().ok())
|
| 670 |
.and_then(parse_total_from_content_range);
|
| 671 |
|
|
|
|
| 1 |
use axum::{
|
| 2 |
routing::{get, post},
|
| 3 |
http::StatusCode,
|
| 4 |
+
http::{HeaderMap, Method, header::{RANGE, CONTENT_RANGE, ACCEPT_RANGES, CONTENT_LENGTH, CONTENT_TYPE}},
|
| 5 |
response::{IntoResponse, Html},
|
| 6 |
extract::{Json, State, Query, Form},
|
| 7 |
Router,
|
| 8 |
};
|
| 9 |
use tower_http::{cors::{CorsLayer, Any}, compression::CompressionLayer, trace::TraceLayer};
|
|
|
|
| 10 |
use serde_json::json;
|
| 11 |
use serde::Deserialize;
|
| 12 |
use std::collections::HashMap;
|
|
|
|
| 408 |
if url.is_empty() {
|
| 409 |
if let Some(arl) = q.arl.clone().filter(|s| !s.trim().is_empty()) {
|
| 410 |
let client = api_client_for_arl(&state, Some(arl)).await;
|
| 411 |
+
let res = async {
|
| 412 |
let mut client = client.lock().await;
|
| 413 |
let resp: Result<DeezerTrackList, APIError> = client
|
| 414 |
.api_call(
|
|
|
|
| 461 |
.unwrap();
|
| 462 |
let r = http
|
| 463 |
.get(url.clone())
|
| 464 |
+
.header(reqwest::header::RANGE, "bytes=0-0")
|
| 465 |
.send()
|
| 466 |
.await;
|
| 467 |
|
| 468 |
let mut total_bytes: u64 = 0;
|
| 469 |
let mut mime: String = String::new();
|
| 470 |
if let Ok(r) = r {
|
| 471 |
+
if let Some(ct) = r.headers().get(reqwest::header::CONTENT_TYPE).and_then(|v| v.to_str().ok()) {
|
| 472 |
mime = ct.to_string();
|
| 473 |
}
|
| 474 |
if let Some(cr) = r
|
| 475 |
.headers()
|
| 476 |
+
.get(reqwest::header::CONTENT_RANGE)
|
| 477 |
.and_then(|v| v.to_str().ok())
|
| 478 |
.and_then(total_from_content_range)
|
| 479 |
{
|
| 480 |
total_bytes = cr;
|
| 481 |
+
} else if let Some(cl) = r.headers().get(reqwest::header::CONTENT_LENGTH).and_then(|v| v.to_str().ok()) {
|
| 482 |
total_bytes = cl.parse::<u64>().unwrap_or(0);
|
| 483 |
}
|
| 484 |
}
|
|
|
|
| 638 |
if e >= start {
|
| 639 |
remaining = Some(e - start + 1);
|
| 640 |
}
|
| 641 |
+
req = req.header(reqwest::header::RANGE, format!("bytes={}-{}", aligned_start, e));
|
| 642 |
} else {
|
| 643 |
+
req = req.header(reqwest::header::RANGE, format!("bytes={}-", aligned_start));
|
| 644 |
}
|
| 645 |
}
|
| 646 |
|
|
|
|
| 664 |
let mut carry: Vec<u8> = Vec::with_capacity(4096);
|
| 665 |
let upstream_headers = upstream.headers().clone();
|
| 666 |
let upstream_total = upstream_headers
|
| 667 |
+
.get(reqwest::header::CONTENT_RANGE)
|
| 668 |
.and_then(|v| v.to_str().ok())
|
| 669 |
.and_then(parse_total_from_content_range);
|
| 670 |
|