remove b64 imgs
This commit is contained in:
parent
b12f02a5e3
commit
028026bfdc
12 changed files with 64 additions and 27 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -70,16 +70,6 @@ dependencies = [
|
|||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-client-ip"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddfb5a3ddd6367075d50629546fb46710584016ae7704cd03b6d41cb5be82e5a"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"forwarded-header-value",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "axum-core"
|
||||
version = "0.3.2"
|
||||
|
@ -1724,7 +1714,6 @@ name = "xssbook"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-client-ip",
|
||||
"bytes",
|
||||
"image",
|
||||
"lazy_static",
|
||||
|
|
|
@ -6,7 +6,6 @@ edition = "2021"
|
|||
[dependencies]
|
||||
tokio = { version = "1.23.0", features = ["full"] }
|
||||
axum = { version = "0.6.4", features = ["headers", "query"] }
|
||||
axum-client-ip = "0.3.1"
|
||||
tower-http = { version = "0.3.5", features = ["fs"] }
|
||||
tower_governor = "0.0.4"
|
||||
tower-cookies = "0.8.0"
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -188,7 +188,7 @@ select {
|
|||
border: 1px solid var(--light);
|
||||
color: var(--extreme);
|
||||
font-size: 15px;
|
||||
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYAgMAAACdGdVrAAAADFBMVEVMaXEFBQUFBQUFBQXG+MOgAAAAA3RSTlMAn3BcqiM3AAAAOUlEQVQIW53BsQ2AMAwAMJelV6C80qPYw4k9JmskbqA2px5uNIlcoxF7FmbFxuhckA2iwNzgev3wAR4FDUQbc/qhAAAAAElFTkSuQmCC");
|
||||
background-image: url("/image/arrow.png");
|
||||
background-position: right 10px center;
|
||||
background-repeat: no-repeat;
|
||||
background-size: 15px;
|
||||
|
@ -291,7 +291,7 @@ footer {
|
|||
cursor: pointer;
|
||||
background-size: 20px;
|
||||
background-position: right;
|
||||
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYAgMAAACdGdVrAAAADFBMVEVgZ3FHcExgZ3FgZ3Fd28LEAAAAA3RSTlOfAHBcPEovAAAASklEQVQIW2MIBQMG7FRmaGgmUG5PaKgdkNovGvIPSPkfDf4IpII/+h8FUiF/7EVB2u3/gE3x/4hMQQShSqAaoNqhhkGNhlqE2y0A1E85Y0JErBoAAAAASUVORK5CYII=');
|
||||
background-image: url('/image/close.png');
|
||||
}
|
||||
|
||||
.hidden {
|
||||
|
|
File diff suppressed because one or more lines are too long
BIN
public/image/arrow.png
Normal file
BIN
public/image/arrow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 153 B |
BIN
public/image/change.png
Normal file
BIN
public/image/change.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6 KiB |
BIN
public/image/close.png
Normal file
BIN
public/image/close.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 170 B |
BIN
public/image/icons.png
Normal file
BIN
public/image/icons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6 KiB |
|
@ -33,11 +33,11 @@ function remove(id) {
|
|||
}
|
||||
|
||||
function pfp(id) {
|
||||
return `<img src="/image/avatar?user_id=${id}">`
|
||||
return `<img src="/cdn/avatar?user_id=${id}">`
|
||||
}
|
||||
|
||||
function banner(id) {
|
||||
return `<img src="/image/banner?user_id=${id}" onerror="this.remove()" >`
|
||||
return `<img src="/cdn/banner?user_id=${id}" onerror="this.remove()" >`
|
||||
}
|
||||
|
||||
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||
|
|
|
@ -5,14 +5,13 @@ use axum::{
|
|||
response::Response,
|
||||
RequestExt, Router, extract::DefaultBodyLimit,
|
||||
};
|
||||
use axum_client_ip::ClientIp;
|
||||
use std::{net::SocketAddr, process::exit, fs};
|
||||
use tower_cookies::CookieManagerLayer;
|
||||
use tracing::{error, info, metadata::LevelFilter};
|
||||
use tracing_subscriber::{
|
||||
filter::filter_fn, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer,
|
||||
};
|
||||
use types::http::ResponseCode;
|
||||
use types::{http::ResponseCode, extract::RequestIp};
|
||||
|
||||
use crate::api::{pages, image};
|
||||
|
||||
|
@ -38,7 +37,7 @@ async fn log<B>(mut req: Request<B>, next: Next<B>) -> Response
|
|||
where
|
||||
B: Send + Sync + 'static + HttpBody,
|
||||
{
|
||||
let Ok(ClientIp(ip)) = req.extract_parts::<ClientIp>().await else {
|
||||
let Ok(RequestIp(ip)) = req.extract_parts::<RequestIp>().await else {
|
||||
return next.run(req).await
|
||||
};
|
||||
|
||||
|
@ -79,7 +78,7 @@ async fn main() {
|
|||
.layer(middleware::from_fn(serve))
|
||||
.nest("/", pages::router())
|
||||
.nest("/api", api::router())
|
||||
.nest("/image", image::router())
|
||||
.nest("/cdn", image::router())
|
||||
.layer(CookieManagerLayer::new())
|
||||
.layer(DefaultBodyLimit::max(512_000));
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
use std::io::{Read, Cursor};
|
||||
use std::{io::{Read, Cursor}, net::{IpAddr, SocketAddr}};
|
||||
|
||||
use axum::{
|
||||
async_trait,
|
||||
body::HttpBody,
|
||||
extract::{FromRequest, FromRequestParts},
|
||||
extract::{FromRequest, FromRequestParts, ConnectInfo},
|
||||
http::{request::Parts, Request},
|
||||
response::Response,
|
||||
BoxError, RequestExt,
|
||||
};
|
||||
use axum_client_ip::ClientIp;
|
||||
use bytes::Bytes;
|
||||
use image::{io::Reader, ImageFormat, DynamicImage};
|
||||
use serde::de::DeserializeOwned;
|
||||
|
@ -23,6 +22,57 @@ use crate::{
|
|||
},
|
||||
};
|
||||
|
||||
pub struct RequestIp(pub IpAddr);
|
||||
|
||||
#[async_trait]
|
||||
impl<S> FromRequestParts<S> for RequestIp
|
||||
where
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = Response;
|
||||
|
||||
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self> {
|
||||
|
||||
let headers = &parts.headers;
|
||||
|
||||
let forwardedfor = headers.get("x-forwarded-for")
|
||||
.and_then(|h| h.to_str().ok())
|
||||
.and_then(|h|
|
||||
h.split(',')
|
||||
.rev()
|
||||
.find_map(|s| s.trim().parse::<IpAddr>().ok())
|
||||
);
|
||||
|
||||
if let Some(forwardedfor) = forwardedfor {
|
||||
return Ok(RequestIp(forwardedfor))
|
||||
}
|
||||
|
||||
let realip = headers.get("x-real-ip")
|
||||
.and_then(|hv| hv.to_str().ok())
|
||||
.and_then(|s| s.parse::<IpAddr>().ok());
|
||||
|
||||
if let Some(realip) = realip {
|
||||
return Ok(RequestIp(realip))
|
||||
}
|
||||
|
||||
let realip = headers.get("x-real-ip")
|
||||
.and_then(|hv| hv.to_str().ok())
|
||||
.and_then(|s| s.parse::<IpAddr>().ok());
|
||||
|
||||
if let Some(realip) = realip {
|
||||
return Ok(RequestIp(realip))
|
||||
}
|
||||
|
||||
let info = parts.extensions.get::<ConnectInfo<SocketAddr>>();
|
||||
|
||||
if let Some(info) = info {
|
||||
return Ok(RequestIp(info.0.ip()))
|
||||
}
|
||||
|
||||
Err(ResponseCode::Forbidden.text("You have no ip"))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AuthorizedUser(pub User);
|
||||
|
||||
#[async_trait]
|
||||
|
@ -189,7 +239,7 @@ where
|
|||
S: Send + Sync,
|
||||
{
|
||||
|
||||
let Ok(ClientIp(ip)) = req.extract_parts::<ClientIp>().await else {
|
||||
let Ok(RequestIp(ip)) = req.extract_parts::<RequestIp>().await else {
|
||||
tracing::error!("Failed to read client ip");
|
||||
return Err(ResponseCode::InternalServerError.text("Failed to read client ip"));
|
||||
};
|
||||
|
@ -224,7 +274,7 @@ where
|
|||
B::Error: Into<BoxError>,
|
||||
S: Send + Sync,
|
||||
{
|
||||
let Ok(ClientIp(ip)) = req.extract_parts::<ClientIp>().await else {
|
||||
let Ok(RequestIp(ip)) = req.extract_parts::<RequestIp>().await else {
|
||||
tracing::error!("Failed to read client ip");
|
||||
return Err(ResponseCode::InternalServerError.text("Failed to read client ip"));
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue