diff options
| author | Fuwn <[email protected]> | 2022-07-17 20:33:49 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-07-17 20:33:49 -0700 |
| commit | cd6ecdd3b7eee6f1e792f78739695524b24e93fb (patch) | |
| tree | 2a8d07ddfb21e42370165526b0df26088a277ec6 /src/modules/api | |
| parent | feat(static): update index content (diff) | |
| download | locus-cd6ecdd3b7eee6f1e792f78739695524b24e93fb.tar.xz locus-cd6ecdd3b7eee6f1e792f78739695524b24e93fb.zip | |
feat(api): sydney version api
Diffstat (limited to 'src/modules/api')
| -rw-r--r-- | src/modules/api/sydney.rs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/modules/api/sydney.rs b/src/modules/api/sydney.rs new file mode 100644 index 0000000..1a5e2ae --- /dev/null +++ b/src/modules/api/sydney.rs @@ -0,0 +1,70 @@ +// This file is part of Locus <https://github.com/gemrest/locus>. +// Copyright (C) 2022-2022 Fuwn <[email protected]> +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// +// Copyright (C) 2022-2022 Fuwn <[email protected]> +// SPDX-License-Identifier: GPL-3.0-only + +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +struct Commit { + sha: String, + url: String, +} + +#[derive(Serialize, Deserialize)] +struct Tags { + pub name: String, + zipball_url: String, + tarball_url: String, + commit: Commit, + node_id: String, +} + +pub fn module(router: &mut windmark::Router) { + crate::route::track_mount( + router, + "/api/sydney/version", + "Sydney's version", + Box::new(move |context| { + let mut content = "0.0.0".to_string(); + + if let Ok(response) = reqwest::blocking::Client::new() + .get("https://api.github.com/repos/gemrest/sydney/tags") + .header( + "User-Agent", + format!("{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")), + ) + .send() + { + if let Ok(response_content) = response.json::<Vec<Tags>>() { + let response_content: Vec<Tags> = response_content; + + if let Some(first_tag) = response_content.get(0) { + content = first_tag.name.clone(); + } + + if let Some(just_tag) = content.get(1..) { + content = just_tag.to_string(); + } + } + } + + crate::route::cache(&context, &content); + + windmark::Response::Success(content) + }), + ); +} |