aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--src/modules.rs3
-rw-r--r--src/modules/api.rs21
-rw-r--r--src/modules/api/sydney.rs70
4 files changed, 94 insertions, 2 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d0d8c81..c9baf8d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,7 +28,7 @@ windmark = { version = "0.1.19", features = [
"logger",
"auto-deduce-mime"
] } # Gemini Server Framework
-# reqwest = { version = "0.11.10", features = ["blocking"] } # HTTP Client
+reqwest = { version = "0.11.10", features = ["blocking", "json"] } # HTTP Client
serde_json = "1.0.79" # JSON Serialization
log = "0.4.16" # Logging Macros
pretty_env_logger = "0.4.0" # Pretty Log Printing
diff --git a/src/modules.rs b/src/modules.rs
index 652ccea..9c84a1d 100644
--- a/src/modules.rs
+++ b/src/modules.rs
@@ -22,6 +22,7 @@ mod interests;
mod random;
mod remarks;
// mod robots;
+mod api;
mod router;
pub mod search;
mod sitemap;
@@ -32,6 +33,6 @@ mod uptime;
pub fn module(router: &mut windmark::Router) {
crate::statelesses!(
router, uptime, sitemap, search, remarks, blog, random, r#static, router,
- skills, contact, interests,
+ skills, contact, interests, api,
);
}
diff --git a/src/modules/api.rs b/src/modules/api.rs
new file mode 100644
index 0000000..52b004a
--- /dev/null
+++ b/src/modules/api.rs
@@ -0,0 +1,21 @@
+// 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
+
+mod sydney;
+
+pub use sydney::module;
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)
+ }),
+ );
+}