chore: 移除不必要的 image-proxy (#451)
This commit is contained in:
@@ -81,11 +81,6 @@ pub struct InsertSubmissionRequest {
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct ImageProxyParams {
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Validate)]
|
||||
pub struct UpdateVideoSourceRequest {
|
||||
#[validate(custom(function = "crate::utils::validation::validate_path"))]
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use axum::body::Body;
|
||||
use axum::extract::{Extension, Query, Request};
|
||||
use axum::extract::Request;
|
||||
use axum::http::HeaderMap;
|
||||
use axum::middleware::Next;
|
||||
use axum::response::{IntoResponse, Response};
|
||||
use axum::routing::get;
|
||||
use axum::{Router, middleware};
|
||||
use base64::Engine;
|
||||
use base64::prelude::BASE64_URL_SAFE_NO_PAD;
|
||||
use reqwest::{Method, StatusCode, header};
|
||||
use reqwest::StatusCode;
|
||||
|
||||
use super::request::ImageProxyParams;
|
||||
use crate::api::wrapper::ApiResponse;
|
||||
use crate::bilibili::BiliClient;
|
||||
use crate::config::VersionedConfig;
|
||||
|
||||
mod config;
|
||||
@@ -27,7 +20,7 @@ mod ws;
|
||||
pub use ws::{LogHelper, MAX_HISTORY_LOGS};
|
||||
|
||||
pub fn router() -> Router {
|
||||
Router::new().route("/image-proxy", get(image_proxy)).nest(
|
||||
Router::new().nest(
|
||||
"/api",
|
||||
config::router()
|
||||
.merge(me::router())
|
||||
@@ -64,43 +57,3 @@ pub async fn auth(mut headers: HeaderMap, request: Request, next: Next) -> Resul
|
||||
}
|
||||
Ok(ApiResponse::<()>::unauthorized("auth token does not match").into_response())
|
||||
}
|
||||
|
||||
/// B 站的图片会检查 referer,需要做个转发伪造一下,否则直接返回 403
|
||||
pub async fn image_proxy(
|
||||
Extension(bili_client): Extension<Arc<BiliClient>>,
|
||||
Query(params): Query<ImageProxyParams>,
|
||||
) -> Response {
|
||||
let resp = bili_client.client.request(Method::GET, ¶ms.url, None).send().await;
|
||||
let whitelist = [
|
||||
header::CONTENT_TYPE,
|
||||
header::CONTENT_LENGTH,
|
||||
header::CACHE_CONTROL,
|
||||
header::EXPIRES,
|
||||
header::LAST_MODIFIED,
|
||||
header::ETAG,
|
||||
header::CONTENT_DISPOSITION,
|
||||
header::CONTENT_ENCODING,
|
||||
header::ACCEPT_RANGES,
|
||||
header::ACCESS_CONTROL_ALLOW_ORIGIN,
|
||||
]
|
||||
.into_iter()
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
let builder = Response::builder();
|
||||
|
||||
let response = match resp {
|
||||
Err(e) => builder.status(StatusCode::BAD_GATEWAY).body(Body::new(e.to_string())),
|
||||
Ok(res) => {
|
||||
let mut response = builder.status(res.status());
|
||||
for (k, v) in res.headers() {
|
||||
if whitelist.contains(k) {
|
||||
response = response.header(k, v);
|
||||
}
|
||||
}
|
||||
let streams = res.bytes_stream();
|
||||
response.body(Body::from_stream(streams))
|
||||
}
|
||||
};
|
||||
//safety: all previously configured headers are taken from a valid response, ensuring the response is safe to use
|
||||
response.unwrap()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="referrer" content="no-referrer" />
|
||||
%sveltekit.head%
|
||||
</head>
|
||||
<body data-sveltekit-preload-data="hover">
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
function getAvatarUrl(): string {
|
||||
switch (type) {
|
||||
case 'upper':
|
||||
return `/image-proxy?url=${(item as UpperWithSubscriptionStatus).face}`;
|
||||
return (item as UpperWithSubscriptionStatus).face;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ export default defineConfig({
|
||||
ws: true,
|
||||
rewriteWsOrigin: true
|
||||
},
|
||||
'/api': 'http://localhost:12345',
|
||||
'/image-proxy': 'http://localhost:12345'
|
||||
'/api': 'http://localhost:12345'
|
||||
},
|
||||
host: true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user