Skip to content
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

Chrivers/licences #39

Merged
merged 2 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/routes/licenses.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use axum::response::IntoResponse;
use axum::routing::get;
use axum::{Json, Router};
use itertools::Itertools;
use serde_json::{json, Value};

use crate::server::appstate::AppState;

async fn packages() -> Json<Value> {
Json(json!([]))
}

async fn hardcoded() -> Json<Value> {
Json(json!([{
"Attributions": [],
"Package": "bifrost",
"SPDX-License-Identifiers": [
"GPL-3.0"
],
"SourceLinks": [
"https://github.com/chrivers/bifrost",
],
"Version": "0.9",
"Website": "https://github.com/chrivers/bifrost",
"licenses": {
"GPL-3.0": "gpl-3.0.txt",
}
}]))
}

async fn license() -> impl IntoResponse {
const LICENSE: &str = include_str!("../../LICENSE");

let split = LICENSE
.find("Preamble")
.expect("License file must have preamble");

/* a bit of string trickery to make license render nicely in hue app */
format!(
"{}{}",
&LICENSE[..split]
.split("\n\n ")
.map(|s| s.replace("\n ", " "))
.join("\n\n"),
&LICENSE[split..]
.split("\n\n ")
.map(|s| s.replace("\n ", "\n").replace('\n', " "))
.join("\n\n")
)
}

async fn rust_packages() -> Json<Value> {
Json(json!([]))
}

pub fn router() -> Router<AppState> {
Router::new()
.route("/packages.json", get(packages))
.route("/hardcoded.json", get(hardcoded))
.route("/rust-packages.json", get(rust_packages))
.route("/gpl-3.0.txt", get(license))
}
2 changes: 2 additions & 0 deletions src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::server::appstate::AppState;
pub mod api;
pub mod clip;
pub mod eventstream;
pub mod licenses;

impl IntoResponse for ApiError {
fn into_response(self) -> Response {
Expand All @@ -36,6 +37,7 @@ impl IntoResponse for ApiError {
pub fn router(appstate: AppState) -> Router<()> {
Router::new()
.nest("/api", api::router())
.nest("/licenses", licenses::router())
.nest("/clip/v2/resource", clip::router())
.nest("/eventstream", eventstream::router())
.with_state(appstate)
Expand Down