fix: room attachment upload (Set Uuid::nil, NotFound with msg, Ok wrapper) and silence dead_code warnings
This commit is contained in:
parent
43e2d26ea2
commit
d1e5245e4e
@ -125,7 +125,7 @@ pub async fn upload(
|
|||||||
let key = format!("rooms/{}/{}", room_id, unique_name);
|
let key = format!("rooms/{}/{}", room_id, unique_name);
|
||||||
let file_size = file_data.len() as i64;
|
let file_size = file_data.len() as i64;
|
||||||
|
|
||||||
let url = storage
|
let _url = storage
|
||||||
.upload(&key, file_data)
|
.upload(&key, file_data)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
@ -139,7 +139,7 @@ pub async fn upload(
|
|||||||
let attachment: room_attachment::ActiveModel = room_attachment::ActiveModel {
|
let attachment: room_attachment::ActiveModel = room_attachment::ActiveModel {
|
||||||
id: Set(attachment_id),
|
id: Set(attachment_id),
|
||||||
room: Set(room_id),
|
room: Set(room_id),
|
||||||
message: Set(None),
|
message: Set(Uuid::nil()),
|
||||||
uploader: Set(user_id),
|
uploader: Set(user_id),
|
||||||
file_name: Set(file_name.clone()),
|
file_name: Set(file_name.clone()),
|
||||||
file_size: Set(file_size),
|
file_size: Set(file_size),
|
||||||
@ -206,11 +206,11 @@ pub async fn get_attachment(
|
|||||||
.one(&service.db)
|
.one(&service.db)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| crate::error::ApiError(service::error::AppError::InternalServerError(e.to_string())))?
|
.map_err(|e| crate::error::ApiError(service::error::AppError::InternalServerError(e.to_string())))?
|
||||||
.ok_or_else(|| crate::error::ApiError(service::error::AppError::NotFound))?;
|
.ok_or_else(|| crate::error::ApiError(service::error::AppError::NotFound("attachment not found".into())))?;
|
||||||
|
|
||||||
// Ensure the attachment belongs to the requested room
|
// Ensure the attachment belongs to the requested room
|
||||||
if attachment.room != room_id {
|
if attachment.room != room_id {
|
||||||
return Err(crate::error::ApiError(service::error::AppError::NotFound));
|
return Err(crate::error::ApiError(service::error::AppError::NotFound("attachment not found".into())));
|
||||||
}
|
}
|
||||||
|
|
||||||
let storage = service
|
let storage = service
|
||||||
@ -223,8 +223,8 @@ pub async fn get_attachment(
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| crate::error::ApiError(service::error::AppError::InternalServerError(e.to_string())))?;
|
.map_err(|e| crate::error::ApiError(service::error::AppError::InternalServerError(e.to_string())))?;
|
||||||
|
|
||||||
HttpResponse::Ok()
|
Ok(HttpResponse::Ok()
|
||||||
.content_type(content_type)
|
.content_type(content_type.clone())
|
||||||
.insert_header((
|
.insert_header((
|
||||||
CONTENT_TYPE,
|
CONTENT_TYPE,
|
||||||
content_type,
|
content_type,
|
||||||
@ -233,5 +233,5 @@ pub async fn get_attachment(
|
|||||||
CONTENT_DISPOSITION,
|
CONTENT_DISPOSITION,
|
||||||
format!("inline; filename=\"{}\"", attachment.file_name),
|
format!("inline; filename=\"{}\"", attachment.file_name),
|
||||||
))
|
))
|
||||||
.body(data)
|
.body(data))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,7 @@ struct ArxivAuthor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
#[allow(dead_code)]
|
||||||
struct ArxivLink {
|
struct ArxivLink {
|
||||||
#[serde(rename = "type", default)]
|
#[serde(rename = "type", default)]
|
||||||
link_type: String,
|
link_type: String,
|
||||||
|
|||||||
@ -41,6 +41,7 @@ async fn require_admin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
fn serde_user(u: &UserModel) -> serde_json::Value {
|
fn serde_user(u: &UserModel) -> serde_json::Value {
|
||||||
serde_json::json!({
|
serde_json::json!({
|
||||||
"id": u.uid.to_string(),
|
"id": u.uid.to_string(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user