| 98 | |
| 99 | #[debug_handler] |
| 100 | pub async fn view( |
| 101 | _auth: auth::JWT, |
| 102 | Path(files_id): Path<i32>, |
| 103 | State(ctx): State<AppContext>, |
| 104 | ) -> Result<Response> { |
| 105 | // Fetch the file info from database |
| 106 | let file = files::Entity::find_by_id(files_id) |
| 107 | .one(&ctx.db) |
| 108 | .await? |
| 109 | .expect("File not found"); |
| 110 | |
| 111 | // Stream the file |
| 112 | let file = fs::File::open(format!("{UPLOAD_DIR}/{}", file.file_path)).await?; |
| 113 | let stream = ReaderStream::new(file); |
| 114 | let body = Body::from_stream(stream); |
| 115 | |
| 116 | Ok(format::render().response().body(body)?) |
| 117 | } |
| 118 | |
| 119 | pub fn routes() -> Routes { |
| 120 | // Bind the routes |