aboutsummaryrefslogtreecommitdiff
path: root/server/src/api.rs
blob: 2b3d016f37699fcca6dd8b99460044cb56f3b675 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/
use super::ui::error::MyResult;
use rocket::{get, response::Redirect, serde::json::Json};

#[get("/api")]
pub fn r_api_root() -> Redirect {
    Redirect::moved("https://jellything.metamuffin.org/book/api.html#jellything-http-api")
}

#[get("/version")]
pub fn r_version() -> &'static str {
    env!("CARGO_PKG_VERSION")
}

// #[get("/translations")]
// pub fn r_translations(
//     lang: AcceptLanguage,
//     aj: AcceptJson,
// ) -> Either<Json<&'static HashMap<&'static str, &'static str>>, String> {
//     let AcceptLanguage(lang) = lang;
//     let table = get_translation_table(&lang);
//     if *aj {
//         Either::Left(Json(table))
//     } else {
//         let mut s = String::new();
//         for (k, v) in table {
//             s += k;
//             s += "=";
//             s += v;
//             s += "\n";
//         }
//         Either::Right(s)
//     }
// }

#[get("/nodes_modified?<since>")]
pub fn r_nodes_modified_since(session: A<Session>, since: u64) -> MyResult<Json<Vec<NodeID>>> {
    let nodes = get_nodes_modified_since(&session.0, since)?;
    Ok(Json(nodes))
}