|
| 1 | +/* |
| 2 | + * Parseable Server (C) 2022 - 2023 Parseable, Inc. |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU Affero General Public License as |
| 6 | + * published by the Free Software Foundation, either version 3 of the |
| 7 | + * License, or (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU Affero General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU Affero General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + * |
| 17 | + */ |
| 18 | + |
| 19 | +use actix_web::web::Json; |
| 20 | +use serde_json::json; |
| 21 | + |
| 22 | +use crate::{about, option::CONFIG, storage::StorageMetadata, utils::update}; |
| 23 | + |
| 24 | +pub async fn about() -> Json<serde_json::Value> { |
| 25 | + let meta = StorageMetadata::global(); |
| 26 | + |
| 27 | + let current_release = about::current(); |
| 28 | + let latest_release = update::get_latest(&meta.deployment_id).await; |
| 29 | + |
| 30 | + let (update_available, latest_release) = match latest_release { |
| 31 | + Ok(latest_release) => ( |
| 32 | + latest_release.version > current_release.released_version, |
| 33 | + Some(format!("v{}", latest_release.version)), |
| 34 | + ), |
| 35 | + Err(_) => (false, None), |
| 36 | + }; |
| 37 | + |
| 38 | + let current_version = format!("v{}", current_release.released_version); |
| 39 | + let commit = current_release.commit_hash; |
| 40 | + let deployment_id = meta.deployment_id.to_string(); |
| 41 | + let mode = CONFIG.mode_string(); |
| 42 | + let staging = CONFIG.staging_dir(); |
| 43 | + let store = CONFIG.storage().get_endpoint(); |
| 44 | + |
| 45 | + Json(json!({ |
| 46 | + "version": current_version, |
| 47 | + "commit": commit, |
| 48 | + "deploymentId": deployment_id, |
| 49 | + "updateAvailable": update_available, |
| 50 | + "latestVersion": latest_release, |
| 51 | + "license": "AGPL-3.0-only", |
| 52 | + "mode": mode, |
| 53 | + "staging": staging, |
| 54 | + "store": store |
| 55 | + })) |
| 56 | +} |
0 commit comments