add: /api/v0/version with query args
-use serde::Serialize;
+use serde::{Deserialize, Serialize};
use std::num::NonZeroU16;
use std::path::PathBuf;
use structopt::StructOpt;
@@ -188,7 +188,9 @@ fn serve(
.or(warp::path!("repo" / ..).and_then(not_implemented))
.or(warp::path!("stats" / ..).and_then(not_implemented))
.or(warp::path!("swarm" / ..).and_then(not_implemented))
- .or(warp::path!("version").and_then(not_implemented));
+ .or(warp::path!("version")
+ .and(warp::query::<VersionQuery>())
+ .and_then(version));
let routes = v0.and(api);
let routes = routes.with(warp::log("rust-ipfs-http-v0"));
@@ -211,6 +213,18 @@ async fn not_implemented() -> Result<impl warp::Reply, std::convert::Infallible>
Ok(warp::http::StatusCode::NOT_IMPLEMENTED)
}
+// https://docs-beta.ipfs.io/reference/http/api/#api-v0-version
+// Note: the parameter formatting is only verified, feature looks to be unimplemented for `go-ipfs
+// 0.4.23` and handled by cli. This is not compatible with `rust-ipfs-api`.
+async fn version(_query: VersionQuery) -> Result<impl warp::Reply, std::convert::Infallible> {
+ let response = VersionResponse {
+ version: env!("CARGO_PKG_VERSION"), // TODO: move over to rust-ipfs not to worry about syncing version numbers?
+ commit: env!("VERGEN_SHA_SHORT"),
+ };
+
+ Ok(warp::reply::json(&response))
+}
+
// NOTE: go-ipfs accepts an -f option for format (unsure if same with Accept: request header),
// unsure on what values -f takes, since `go-ipfs` seems to just print the value back? With plain http
// requests the `f` or `format` is ignored. Perhaps it's a cli functionality. This should return a
@@ -249,3 +263,22 @@ struct IdResponse {
// Multiaddr alike ipfs/0.1.0 ... not sure if there are plans to bump this anytime soon
protocol_version: &'static str,
}
+
+/// The /api/v0/version parses but does not change output according to these values in the query
+/// string. Defined in https://docs-beta.ipfs.io/reference/http/api/#api-v0-version. Included here
+/// mostly as experimentation on how to do query parameters.
+#[derive(Debug, Deserialize)]
+struct VersionQuery {
+ number: Option<bool>,
+ commit: Option<bool>,
+ repo: Option<bool>,
+ all: Option<bool>,
+}
+
+#[derive(Debug, Serialize)]
+#[serde(rename_all = "PascalCase")]
+struct VersionResponse {
+ version: &'static str,
+ commit: &'static str,
+ // repo is here for go-ipfs and js-ipfs but we do not have full repo at the moment
+}
