From 55434f87ff252c784e5e00b4775b9555da31ebb0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 13 May 2025 12:50:04 +0200 Subject: translation endpoint --- server/src/api.rs | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'server/src/api.rs') diff --git a/server/src/api.rs b/server/src/api.rs index 5ec3c5c..6c22010 100644 --- a/server/src/api.rs +++ b/server/src/api.rs @@ -4,7 +4,7 @@ Copyright (C) 2025 metamuffin */ use super::ui::error::MyResult; -use crate::helper::A; +use crate::{helper::A, locale::AcceptLanguage}; use jellycommon::{user::CreateSessionParams, NodeID, Visibility}; use jellyimport::asset_token::AssetInner; use jellylogic::{ @@ -12,6 +12,7 @@ use jellylogic::{ session::{AdminSession, Session}, Database, }; +use jellyui::locale::get_translation_table; use rocket::{ get, http::MediaType, @@ -20,21 +21,42 @@ use rocket::{ request::{self, FromRequest}, response::Redirect, serde::json::Json, - Request, State, + Either, Request, State, }; use serde_json::{json, Value}; -use std::ops::Deref; +use std::{collections::HashMap, ops::Deref}; #[get("/api")] pub fn r_api_root() -> Redirect { Redirect::moved("https://jellything.metamuffin.org/book/api.html#jellything-http-api") } -#[get("/api/version")] -pub fn r_api_version() -> &'static str { +#[get("/version")] +pub fn r_version() -> &'static str { env!("CARGO_PKG_VERSION") } +#[get("/translations")] +pub fn r_translations( + lang: AcceptLanguage, + aj: AcceptJson, +) -> Either>, 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) + } +} + #[post("/api/create_session", data = "")] pub fn r_api_account_login( database: &State, @@ -55,8 +77,8 @@ pub fn r_api_asset_token_raw(_admin: A, token: &str) -> MyResult")] -pub fn r_api_nodes_modified_since( +#[get("/nodes_modified?")] +pub fn r_nodes_modified_since( _session: A, database: &State, since: u64, -- cgit v1.2.3-70-g09d2