MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / view

Function view

examples/react_admin/backend/src/controllers/files.rs:100–117  ·  view source on GitHub ↗
(
    _auth: auth::JWT,
    Path(files_id): Path<i32>,
    State(ctx): State<AppContext>,
)

Source from the content-addressed store, hash-verified

98
99#[debug_handler]
100pub 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
119pub fn routes() -> Routes {
120 // Bind the routes

Callers

nothing calls this directly

Calls 2

newFunction · 0.50
oneMethod · 0.45

Tested by

no test coverage detected