mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-09-18 19:55:14 +00:00
remove unused image purge function, remove config migration
This commit is contained in:
parent
d52d44a121
commit
08181c8ccf
|
@ -11,7 +11,7 @@ use actix_web::{
|
|||
HttpResponse,
|
||||
};
|
||||
use futures::stream::{Stream, StreamExt};
|
||||
use lemmy_utils::{claims::Claims, error::LemmyError, rate_limit::RateLimit, REQWEST_TIMEOUT};
|
||||
use lemmy_utils::{claims::Claims, rate_limit::RateLimit, REQWEST_TIMEOUT};
|
||||
use lemmy_websocket::LemmyContext;
|
||||
use reqwest::Body;
|
||||
use reqwest_middleware::{ClientWithMiddleware, RequestBuilder};
|
||||
|
@ -27,8 +27,7 @@ pub fn config(cfg: &mut web::ServiceConfig, client: ClientWithMiddleware, rate_l
|
|||
)
|
||||
// This has optional query params: /image/{filename}?format=jpg&thumbnail=256
|
||||
.service(web::resource("/pictrs/image/{filename}").route(web::get().to(full_res)))
|
||||
.service(web::resource("/pictrs/image/delete/{token}/{filename}").route(web::get().to(delete)))
|
||||
.service(web::resource("/pictrs/internal/purge").route(web::post().to(purge)));
|
||||
.service(web::resource("/pictrs/image/delete/{token}/{filename}").route(web::get().to(delete)));
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
@ -200,37 +199,6 @@ async fn delete(
|
|||
Ok(HttpResponse::build(res.status()).body(BodyStream::new(res.bytes_stream())))
|
||||
}
|
||||
|
||||
async fn purge(
|
||||
web::Query(params): web::Query<PictrsPurgeParams>,
|
||||
req: HttpRequest,
|
||||
client: web::Data<ClientWithMiddleware>,
|
||||
context: web::Data<LemmyContext>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let purge_string = match params {
|
||||
PictrsPurgeParams::File(f) => format!("file={}", f),
|
||||
PictrsPurgeParams::Alias(a) => format!("alias={}", a),
|
||||
};
|
||||
|
||||
let pictrs_config = context.settings().pictrs_config()?;
|
||||
let url = format!("{}/internal/purge?{}", pictrs_config.url, &purge_string);
|
||||
|
||||
let mut client_req = adapt_request(&req, &client, url);
|
||||
|
||||
if let Some(addr) = req.head().peer_addr {
|
||||
client_req = client_req.header("X-Forwarded-For", addr.to_string())
|
||||
}
|
||||
|
||||
// Add the API token, X-Api-Token header
|
||||
let pictrs_api_key = pictrs_config
|
||||
.api_key
|
||||
.ok_or_else(|| LemmyError::from_message("pictrs_api_key_not_provided"))?;
|
||||
client_req = client_req.header("x-api-token", pictrs_api_key);
|
||||
|
||||
let res = client_req.send().await.map_err(error::ErrorBadRequest)?;
|
||||
|
||||
Ok(HttpResponse::build(res.status()).body(BodyStream::new(res.bytes_stream())))
|
||||
}
|
||||
|
||||
fn make_send<S>(mut stream: S) -> impl Stream<Item = S::Item> + Send + Unpin + 'static
|
||||
where
|
||||
S: Stream + Unpin + 'static,
|
||||
|
|
|
@ -37,10 +37,6 @@ impl Settings {
|
|||
return Err(anyhow!("Hostname variable is not set!").into());
|
||||
}
|
||||
|
||||
if config.pictrs_config.is_none() && config.pictrs_url.is_some() {
|
||||
return Err(anyhow!("Move config value pictrs_url to pictrs_config.url").into());
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
|
|
|
@ -54,11 +54,6 @@ pub struct Settings {
|
|||
#[default(None)]
|
||||
#[doku(skip)]
|
||||
pub opentelemetry_url: Option<Url>,
|
||||
|
||||
/// For migration from Lemmy 0.16 and earlier, which use this field instead of PictrsConfig struct
|
||||
#[default(None)]
|
||||
#[doku(skip)]
|
||||
pub pictrs_url: Option<Url>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
|
||||
|
|
Loading…
Reference in a new issue