fix(backend): match the authenticated user into get/download/delete operations
This commit is contained in:
@@ -57,28 +57,37 @@ async fn upload_file(
|
||||
#[axum::debug_handler]
|
||||
async fn get_file(
|
||||
State(file_repository): State<FileRepository>,
|
||||
ctx: Ctx,
|
||||
Path(file_id): Path<u64>,
|
||||
) -> Result<Json<FileRecord>, LoftError> {
|
||||
let record = file_repository.get_file(file_id as i64).await?;
|
||||
let record = file_repository
|
||||
.get_file(file_id as i64, ctx.user_id())
|
||||
.await?;
|
||||
Ok(Json(record))
|
||||
}
|
||||
|
||||
#[axum::debug_handler]
|
||||
async fn download_file(
|
||||
State(file_repository): State<FileRepository>,
|
||||
ctx: Ctx,
|
||||
Path(file_id): Path<u64>,
|
||||
) -> Result<impl IntoResponse, LoftError> {
|
||||
let stream = file_repository.download_file(file_id as i64).await?;
|
||||
let stream = file_repository
|
||||
.download_file(file_id as i64, ctx.user_id())
|
||||
.await?;
|
||||
Ok(Body::from_stream(stream))
|
||||
}
|
||||
|
||||
async fn delete_file(
|
||||
State(file_repository): State<FileRepository>,
|
||||
ctx: Ctx,
|
||||
Path(file_id): Path<u64>,
|
||||
) -> Result<Json<FileRecord>, LoftError> {
|
||||
info!("handler: delete_file");
|
||||
|
||||
let file = file_repository.delete_file(file_id as i64).await?;
|
||||
let file = file_repository
|
||||
.delete_file(file_id as i64, ctx.user_id())
|
||||
.await?;
|
||||
Ok(Json(file))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user