fix(services/january): remove image if video present and hence fix logic error
refactor(services/january): throw an error if embed fails to generate
This commit is contained in:
@@ -80,6 +80,7 @@ impl IntoResponse for Error {
|
|||||||
ErrorType::FileTooLarge { .. } => StatusCode::UNPROCESSABLE_ENTITY,
|
ErrorType::FileTooLarge { .. } => StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
ErrorType::FileTypeNotAllowed => StatusCode::BAD_REQUEST,
|
ErrorType::FileTypeNotAllowed => StatusCode::BAD_REQUEST,
|
||||||
ErrorType::ImageProcessingFailed => StatusCode::INTERNAL_SERVER_ERROR,
|
ErrorType::ImageProcessingFailed => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
ErrorType::NoEmbedData => StatusCode::BAD_REQUEST,
|
||||||
};
|
};
|
||||||
|
|
||||||
(status, Json(&self)).into_response()
|
(status, Json(&self)).into_response()
|
||||||
|
|||||||
@@ -163,6 +163,7 @@ pub enum ErrorType {
|
|||||||
},
|
},
|
||||||
FileTypeNotAllowed,
|
FileTypeNotAllowed,
|
||||||
ImageProcessingFailed,
|
ImageProcessingFailed,
|
||||||
|
NoEmbedData,
|
||||||
|
|
||||||
// ? Legacy errors
|
// ? Legacy errors
|
||||||
VosoUnavailable,
|
VosoUnavailable,
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ impl<'r> Responder<'r, 'static> for Error {
|
|||||||
ErrorType::FileTooLarge { .. } => Status::UnprocessableEntity,
|
ErrorType::FileTooLarge { .. } => Status::UnprocessableEntity,
|
||||||
ErrorType::FileTypeNotAllowed => Status::BadRequest,
|
ErrorType::FileTypeNotAllowed => Status::BadRequest,
|
||||||
ErrorType::ImageProcessingFailed => Status::InternalServerError,
|
ErrorType::ImageProcessingFailed => Status::InternalServerError,
|
||||||
|
ErrorType::NoEmbedData => Status::BadRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Serialize the error data structure into JSON.
|
// Serialize the error data structure into JSON.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use axum::{extract::Query, response::IntoResponse, routing::get, Json, Router};
|
use axum::{extract::Query, response::IntoResponse, routing::get, Json, Router};
|
||||||
use reqwest::header;
|
use reqwest::header;
|
||||||
use revolt_result::Result;
|
use revolt_models::v0::Embed;
|
||||||
|
use revolt_result::{create_error, Result};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use utoipa::ToSchema;
|
use utoipa::ToSchema;
|
||||||
|
|
||||||
@@ -87,5 +88,9 @@ async fn embed(
|
|||||||
Query(UrlQuery { url }): Query<UrlQuery>,
|
Query(UrlQuery { url }): Query<UrlQuery>,
|
||||||
// TypedHeader(Authorization(_bearer)): TypedHeader<Authorization<Bearer>>,
|
// TypedHeader(Authorization(_bearer)): TypedHeader<Authorization<Bearer>>,
|
||||||
) -> Result<impl IntoResponse> {
|
) -> Result<impl IntoResponse> {
|
||||||
Request::generate_embed(url).await.map(Json)
|
match Request::generate_embed(url).await {
|
||||||
|
Ok(Embed::None) => Err(create_error!(NoEmbedData)),
|
||||||
|
result => result,
|
||||||
|
}
|
||||||
|
.map(Json)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,8 +156,13 @@ pub async fn create_website_embed(original_url: &str, document: &str) -> Option<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remove image if video exists
|
||||||
|
if metadata.video.is_some() {
|
||||||
|
metadata.image.take();
|
||||||
|
}
|
||||||
|
|
||||||
// fetch image size if missing
|
// fetch image size if missing
|
||||||
if metadata.special.is_none() && metadata.image.is_none() {
|
if metadata.special.is_none() {
|
||||||
if let Some(Image {
|
if let Some(Image {
|
||||||
width, height, url, ..
|
width, height, url, ..
|
||||||
}) = &metadata.image
|
}) = &metadata.image
|
||||||
|
|||||||
Reference in New Issue
Block a user