feat: get latest tarball from REST API
This commit is contained in:
parent
cb2dfa5e19
commit
38eb9c74ec
3 changed files with 62 additions and 1 deletions
60
src/api.rs
Normal file
60
src/api.rs
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* ForgeFlux StarChart - A federated software forge spider
|
||||||
|
* Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as
|
||||||
|
* published by the Free Software Foundation, either version 3 of the
|
||||||
|
* License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* 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 Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
use actix_web::web;
|
||||||
|
use actix_web::{HttpResponse, Responder};
|
||||||
|
use actix_web_codegen_const_routes::get;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::errors::*;
|
||||||
|
use crate::WebFederate;
|
||||||
|
|
||||||
|
pub const ROUTES: Api = Api::new();
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub struct Api {
|
||||||
|
pub get_latest: &'static str,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Api {
|
||||||
|
const fn new() -> Api {
|
||||||
|
let get_latest = "/api/v1/federated/latest";
|
||||||
|
Api { get_latest }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Clone, Debug, Eq, PartialEq)]
|
||||||
|
pub struct LatestResp {
|
||||||
|
pub latest: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LatestResp {
|
||||||
|
pub async fn new(federate: &WebFederate) -> Self {
|
||||||
|
let latest = federate.latest_tar().await.unwrap();
|
||||||
|
LatestResp { latest }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get(path = "ROUTES.get_latest")]
|
||||||
|
pub async fn lastest(federate: WebFederate) -> ServiceResult<impl Responder> {
|
||||||
|
let latest = LatestResp::new(&federate).await;
|
||||||
|
Ok(HttpResponse::Ok().json(latest))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||||
|
cfg.service(lastest);
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ use actix_web::{middleware, web::Data, App, HttpServer};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
|
|
||||||
|
pub mod api;
|
||||||
pub mod ctx;
|
pub mod ctx;
|
||||||
pub mod db;
|
pub mod db;
|
||||||
pub mod dns;
|
pub mod dns;
|
||||||
|
@ -82,7 +83,6 @@ async fn main() {
|
||||||
let crawler_fut = tokio::spawn(spider::Crawler::start(crawler.clone()));
|
let crawler_fut = tokio::spawn(spider::Crawler::start(crawler.clone()));
|
||||||
let ctx = WebCtx::new(ctx);
|
let ctx = WebCtx::new(ctx);
|
||||||
let socket_addr = settings.server.get_ip();
|
let socket_addr = settings.server.get_ip();
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(middleware::Logger::default())
|
.wrap(middleware::Logger::default())
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
crate::api::services(cfg);
|
||||||
crate::pages::services(cfg);
|
crate::pages::services(cfg);
|
||||||
crate::static_assets::services(cfg);
|
crate::static_assets::services(cfg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue