v0.9.9
This commit is contained in:
@@ -135,6 +135,8 @@ pub fn router(state: AppState) -> Router {
|
||||
.route("/flows/:id", get(index))
|
||||
.route("/lang/index.json", get(language_index))
|
||||
.route("/lang/:file", get(language_file))
|
||||
.route("/presets/index.json", get(preset_index))
|
||||
.route("/presets/:file", get(preset_file))
|
||||
.merge(protected)
|
||||
.merge(home_assistant_api);
|
||||
|
||||
|
||||
@@ -69,6 +69,18 @@ async fn language_file(Path(file): Path<String>) -> Response {
|
||||
response.headers_mut().insert(header::CONTENT_TYPE, HeaderValue::from_static("text/plain; charset=utf-8"));
|
||||
response
|
||||
}
|
||||
async fn preset_index() -> Response {
|
||||
static_response(PRESET_MANIFEST_JSON, "application/json; charset=utf-8", "no-cache")
|
||||
}
|
||||
async fn preset_file(Path(file): Path<String>) -> Response {
|
||||
if let Some((_, body)) = PRESET_ASSETS.iter().find(|(filename, _)| *filename == file) {
|
||||
return static_response(*body, "application/json; charset=utf-8", "no-cache");
|
||||
}
|
||||
let mut response = Response::new(Body::from("Preset not found"));
|
||||
*response.status_mut() = StatusCode::NOT_FOUND;
|
||||
response.headers_mut().insert(header::CONTENT_TYPE, HeaderValue::from_static("text/plain; charset=utf-8"));
|
||||
response
|
||||
}
|
||||
fn static_response(body: &'static str, content_type: &'static str, cache: &'static str) -> Response {
|
||||
let mut response = Response::new(Body::from(body));
|
||||
response.headers_mut().insert(header::CONTENT_TYPE, HeaderValue::from_static(content_type));
|
||||
|
||||
Reference in New Issue
Block a user