mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-09-06 07:57:12 +08:00
chore: 移除不必要的 image-proxy (#451)
This commit is contained in:
@@ -81,11 +81,6 @@ pub struct InsertSubmissionRequest {
|
|||||||
pub path: String,
|
pub path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct ImageProxyParams {
|
|
||||||
pub url: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Validate)]
|
#[derive(Deserialize, Validate)]
|
||||||
pub struct UpdateVideoSourceRequest {
|
pub struct UpdateVideoSourceRequest {
|
||||||
#[validate(custom(function = "crate::utils::validation::validate_path"))]
|
#[validate(custom(function = "crate::utils::validation::validate_path"))]
|
||||||
|
|||||||
@@ -1,20 +1,13 @@
|
|||||||
use std::collections::HashSet;
|
use axum::extract::Request;
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use axum::body::Body;
|
|
||||||
use axum::extract::{Extension, Query, Request};
|
|
||||||
use axum::http::HeaderMap;
|
use axum::http::HeaderMap;
|
||||||
use axum::middleware::Next;
|
use axum::middleware::Next;
|
||||||
use axum::response::{IntoResponse, Response};
|
use axum::response::{IntoResponse, Response};
|
||||||
use axum::routing::get;
|
|
||||||
use axum::{Router, middleware};
|
use axum::{Router, middleware};
|
||||||
use base64::Engine;
|
use base64::Engine;
|
||||||
use base64::prelude::BASE64_URL_SAFE_NO_PAD;
|
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::api::wrapper::ApiResponse;
|
||||||
use crate::bilibili::BiliClient;
|
|
||||||
use crate::config::VersionedConfig;
|
use crate::config::VersionedConfig;
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
@@ -27,7 +20,7 @@ mod ws;
|
|||||||
pub use ws::{LogHelper, MAX_HISTORY_LOGS};
|
pub use ws::{LogHelper, MAX_HISTORY_LOGS};
|
||||||
|
|
||||||
pub fn router() -> Router {
|
pub fn router() -> Router {
|
||||||
Router::new().route("/image-proxy", get(image_proxy)).nest(
|
Router::new().nest(
|
||||||
"/api",
|
"/api",
|
||||||
config::router()
|
config::router()
|
||||||
.merge(me::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())
|
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" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta name="referrer" content="no-referrer" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body data-sveltekit-preload-data="hover">
|
<body data-sveltekit-preload-data="hover">
|
||||||
|
|||||||
@@ -125,7 +125,7 @@
|
|||||||
function getAvatarUrl(): string {
|
function getAvatarUrl(): string {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'upper':
|
case 'upper':
|
||||||
return `/image-proxy?url=${(item as UpperWithSubscriptionStatus).face}`;
|
return (item as UpperWithSubscriptionStatus).face;
|
||||||
default:
|
default:
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -11,8 +11,7 @@ export default defineConfig({
|
|||||||
ws: true,
|
ws: true,
|
||||||
rewriteWsOrigin: true
|
rewriteWsOrigin: true
|
||||||
},
|
},
|
||||||
'/api': 'http://localhost:12345',
|
'/api': 'http://localhost:12345'
|
||||||
'/image-proxy': 'http://localhost:12345'
|
|
||||||
},
|
},
|
||||||
host: true
|
host: true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user