Skip to main content

xapi_rs/lrs/resources/
about.rs

1// SPDX-License-Identifier: GPL-3.0-or-later
2
3//! About Resource (/about)
4//! ------------------------
5//! Provides a method to retrieve an [About] Object containing information
6//! about this LRS, including supported extensions and xAPI version(s).
7//!
8//! Any deviation from section [4.1.6.7 About Resource (/about)][1] of the
9//! xAPI specification is a bug.
10//!
11//! [1]: https://opensource.ieee.org/xapi/xapi-base-standard-documentation/-/blob/main/9274.1.1%20xAPI%20Base%20Standard%20for%20LRSs.md#4167-about-resource-about
12
13use crate::{
14    config::config,
15    emit_response,
16    lrs::resources::{Headers, WithResource},
17    About, DataError, Extensions, MyError, MyVersion, EXT_STATS, EXT_USERS, EXT_VERBS,
18    STATS_EXT_BASE, USERS_EXT_BASE, V200, VERBS_EXT_BASE,
19};
20use rocket::{get, routes};
21use serde_json::Value;
22use std::str::FromStr;
23use tracing::debug;
24
25#[doc(hidden)]
26pub fn routes() -> Vec<rocket::Route> {
27    routes![get]
28}
29
30// NOTE (rsn) 20250116 - do not enforce user authentication to pass the CTS.
31// NOTE (rsn) 2024097 - removed the Headers guard to allow /about calls w/o an
32// xapi version header...
33#[get("/")]
34async fn get() -> Result<WithResource<About>, MyError> {
35    debug!("----- get -----");
36
37    let x = build_about().map_err(MyError::Data)?;
38    emit_response!(Headers::default(), x => About)
39}
40
41fn build_about() -> Result<About, DataError> {
42    let versions = vec![MyVersion::from_str(V200)?];
43    let mut extensions = Extensions::default();
44    extensions.add(
45        EXT_VERBS,
46        &Value::String(config().to_external_url(VERBS_EXT_BASE)),
47    )?;
48    extensions.add(
49        EXT_STATS,
50        &Value::String(config().to_external_url(STATS_EXT_BASE)),
51    )?;
52    extensions.add(
53        EXT_USERS,
54        &Value::String(config().to_external_url(USERS_EXT_BASE)),
55    )?;
56
57    Ok(About::new(versions, extensions))
58}