-
Notifications
You must be signed in to change notification settings - Fork 1
Rework API to reflect desired user interface #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
9798468
Use node structures
abbiemery 37d6981
Put sortings in node
abbiemery 9f0bdb7
wip
abbiemery 41d580e
Generic everything
abbiemery f2ff0d2
It might work...
abbiemery 95b8ee1
File downloading
abbiemery f73c9c8
Remove tiled
abbiemery ec62f42
Remove family specific attributes
abbiemery cff66de
Remove unused container structs
abbiemery a0f7c22
remove unused deserialised model tests
abbiemery 0c2fa18
Remove table type alias
abbiemery 4b2fdb8
Tidy model node
abbiemery 869e6fd
Remove comments and unused imports in model.rs
abbiemery c5ccd88
Remove unused tests in model.rs
abbiemery 2d8f73e
Remove comments and unused imports in client.rs
abbiemery d56c598
Remove root query and model
abbiemery 7b13e53
Underscore variable
abbiemery 8d2016b
Box large enum variant
abbiemery 251b3a6
Add table type alias
abbiemery 915e6c8
Add full table request to client
abbiemery b08967b
Get internal data in the worst way imaginable
abbiemery 419efff
Start of combined data query
tpoliaw f513cbe
Add column filters to full_table request
tpoliaw cdc1a23
Make data a single list of all data
tpoliaw 0589331
Add scan_number to run object
tpoliaw 382f1ba
Clean up clippy lints
tpoliaw cf07b8a
Add base address to context
tpoliaw e803459
Tidy up download handler
tpoliaw e2e5b95
Remove redundant Ok(_?)
tpoliaw 202e4cb
Remove empty test
tpoliaw 14efef2
Remove unused context from instrument_session
tpoliaw 912472a
Make data columns optional
tpoliaw 813dd6a
Always return node::Root from search
tpoliaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| use axum::body::Body; | ||
| use axum::extract::{Path, State}; | ||
| use axum::http::{HeaderMap, StatusCode}; | ||
| use serde_json::{Value, json}; | ||
| use tracing::{error, info}; | ||
|
|
||
| use crate::clients::TiledClient; | ||
|
|
||
| const FORWARDED_HEADERS: [&str; 4] = [ | ||
| "content-disposition", | ||
| "content-type", | ||
| "content-length", | ||
| "last-modified", | ||
| ]; | ||
|
|
||
| pub async fn download( | ||
| State(client): State<TiledClient>, | ||
| Path((run, stream, det, id)): Path<(String, String, String, u32)>, | ||
| ) -> (StatusCode, HeaderMap, Body) { | ||
| info!("Downloading {run}/{stream}/{det}/{id}"); | ||
| let req = client.download(run, stream, det, id).await; | ||
| forward_download_response(req).await | ||
| } | ||
|
|
||
| async fn forward_download_response( | ||
| response: Result<reqwest::Response, reqwest::Error>, | ||
| ) -> (StatusCode, HeaderMap, Body) { | ||
| match response { | ||
| Ok(mut resp) => match resp.status().as_u16() { | ||
| 200..300 => { | ||
| let mut headers = HeaderMap::new(); | ||
| for key in FORWARDED_HEADERS { | ||
| if let Some(value) = resp.headers_mut().remove(key) { | ||
| headers.insert(key, value); | ||
| } | ||
| } | ||
| let stream = Body::from_stream(resp.bytes_stream()); | ||
| (StatusCode::OK, headers, stream) | ||
| }, | ||
| 400..500 => ( | ||
| // Probably permission error or non-existent file - forward error to client | ||
| resp.status(), | ||
| HeaderMap::new(), | ||
| Body::from_stream(resp.bytes_stream()) | ||
| ), | ||
| 100..200 | // ??? check tiled? | ||
| 300..400 | // should have followed a redirect | ||
| 0..100 | (600..) | // who needs standards anyway | ||
| 500..600 => { | ||
| let status = resp.status().as_u16(); | ||
| let content = resp.text().await.unwrap_or_else(|e| format!("Unable to read error response: {e}")); | ||
| ( | ||
| // Whatever we got back, it wasn't what we expected so blame it on tiled | ||
| StatusCode::SERVICE_UNAVAILABLE, | ||
| HeaderMap::new(), | ||
| json!({ | ||
| "detail": "Unexpected response from tiled", | ||
| "status": status, | ||
| // Try to parse response as json before giving up and passing a string | ||
| "response": serde_json::from_str(&content) | ||
| .unwrap_or(Value::String(content)) | ||
| }).to_string().into() | ||
| ) | ||
| } | ||
| }, | ||
| Err(err) => { | ||
| error!("Error sending request to tiled: {err}"); | ||
| let (status, message) = if err.is_connect() { | ||
| ( | ||
| StatusCode::SERVICE_UNAVAILABLE, | ||
| "Could not connect to tiled", | ||
| ) | ||
| } else { | ||
| ( | ||
| StatusCode::INTERNAL_SERVER_ERROR, | ||
| "Error making request to tiled", | ||
| ) | ||
| }; | ||
|
|
||
| (status, HeaderMap::new(), message.into()) | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.