refactor(backend): return concrete FuturesByteStream instead of impl Stream
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use axum::{body::Bytes, extract::multipart::MultipartError};
|
||||
use futures_util::{Stream, StreamExt};
|
||||
use opendal::{Operator, layers::LoggingLayer, services};
|
||||
use opendal::{FuturesBytesStream, Operator, layers::LoggingLayer, services};
|
||||
use serde::Serialize;
|
||||
use sqlx::{PgPool, prelude::FromRow};
|
||||
|
||||
@@ -80,22 +80,14 @@ impl FileRepository {
|
||||
Ok(record)
|
||||
}
|
||||
|
||||
pub async fn download_file(
|
||||
&self,
|
||||
file_id: i64,
|
||||
user_id: i64,
|
||||
) -> Result<impl Stream<Item = std::io::Result<Bytes>> + use<>> {
|
||||
pub async fn download_file(&self, file_id: i64, user_id: i64) -> Result<FuturesBytesStream> {
|
||||
let record = self.get_file(file_id, user_id).await?;
|
||||
let reader = self.op.reader(&record.storage_key).await?;
|
||||
let stream = reader.into_bytes_stream(0..).await?;
|
||||
Ok(stream)
|
||||
}
|
||||
|
||||
pub async fn thumbnail(
|
||||
&self,
|
||||
file_id: i64,
|
||||
user_id: i64,
|
||||
) -> Result<impl Stream<Item = std::io::Result<Bytes>> + use<>> {
|
||||
pub async fn thumbnail(&self, file_id: i64, user_id: i64) -> Result<FuturesBytesStream> {
|
||||
let record = self.get_file(file_id, user_id).await?;
|
||||
let path = format!("thumbnail/{}", &record.storage_key);
|
||||
let reader = self.op.reader(&path).await?;
|
||||
@@ -109,7 +101,7 @@ impl FileRepository {
|
||||
user_id: i64,
|
||||
from: u64,
|
||||
to: u64,
|
||||
) -> Result<impl Stream<Item = std::io::Result<Bytes>> + use<>> {
|
||||
) -> Result<FuturesBytesStream> {
|
||||
let record = self.get_file(file_id, user_id).await?;
|
||||
let reader = self.op.reader(&record.storage_key).await?;
|
||||
let stream = reader.into_bytes_stream(from..to).await?;
|
||||
@@ -435,7 +427,7 @@ mod tests {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(record.thumbnail_storage_path, None);
|
||||
assert_eq!(record.thumbnail_storage_path, None);
|
||||
|
||||
let path = "thumbnail/a.png-uuid";
|
||||
file_repository
|
||||
|
||||
Reference in New Issue
Block a user