Skip to content

Commit

Permalink
feat(codeberg): introduce codeberg api endpoint
Browse files Browse the repository at this point in the history
The `/v1/codeberg` API endpoint supports `codeberg.org`, which runs
Forgejo (a Gitea soft-fork), so it simply redirects all requests to
`/v1/gitea/codeberg.org`.

Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
  • Loading branch information
algernon committed Oct 28, 2023
1 parent eb3df3b commit 0d6337d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/api/v1/gitea/endpoints/codeberg_redirect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: 2023 Gergely Nagy
// SPDX-FileContributor: Gergely Nagy
//
// SPDX-License-Identifier: AGPL-3.0-only

use axum::{
extract::Path,
response::{IntoResponse, Redirect},
};

#[allow(unused)]
use log::{debug, error, info, trace, warn};

pub async fn codeberg_redirect(Path(url): Path<String>) -> impl IntoResponse {
let target = format!("/v1/gitea/codeberg.org/{}", url);
trace!("{target:#?}");
Redirect::to(&target).into_response()
}
2 changes: 2 additions & 0 deletions src/api/v1/gitea/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

mod codeberg_redirect;
pub use self::codeberg_redirect::codeberg_redirect;
mod get_repo;
pub use self::get_repo::get_repo;
mod get_repo_ref;
Expand Down
3 changes: 2 additions & 1 deletion src/api/v1/gitea/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// SPDX-License-Identifier: AGPL-3.0-only

use super::endpoints::{get_repo, get_repo_ref};
use super::endpoints::{codeberg_redirect, get_repo, get_repo_ref};

use axum::{routing::get, Router};

Expand All @@ -25,4 +25,5 @@ pub fn get_routes() -> Router {
get(get_repo_ref),
)
.route("/v1/gitea/:host/:user/:repo", get(get_repo))
.route("/v1/codeberg/*req", get(codeberg_redirect))
}

0 comments on commit 0d6337d

Please sign in to comment.