This commit is contained in:
parent
27f7e8f35c
commit
12a3d66b6f
@ -114,6 +114,10 @@ fn main() -> Result<()> {
|
||||
"/github/{user}/{repo}/{commit}/{file:.*}",
|
||||
web::get().to_async(handle_request::<Github>),
|
||||
)
|
||||
.route(
|
||||
"/bitbucket/{user}/{repo}/{commit}/{file:.*}",
|
||||
web::get().to_async(handle_request::<Bitbucket>),
|
||||
)
|
||||
// .default_service(web::resource("").route(web::get().to_async(p404)))
|
||||
})
|
||||
// .workers(OPT.workers)
|
||||
|
@ -15,6 +15,22 @@ impl ApiResponse for GitHubApiResponse {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(crate) struct BitbucketApiResponse {
|
||||
values: Vec<BitbucketEntry>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub(crate) struct BitbucketEntry {
|
||||
pub(crate) hash: String,
|
||||
}
|
||||
|
||||
impl ApiResponse for BitbucketApiResponse {
|
||||
fn commit_ref(&self) -> &str {
|
||||
&self.values[0].hash
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait Service {
|
||||
type Response: for<'de> serde::Deserialize<'de> + ApiResponse + 'static;
|
||||
fn raw_url(user: &str, repo: &str, commit: &str, file: &str) -> String;
|
||||
@ -45,3 +61,27 @@ impl Service for Github {
|
||||
format!("/github/{}/{}/{}/{}", user, repo, commit, file)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Bitbucket;
|
||||
|
||||
impl Service for Bitbucket {
|
||||
type Response = BitbucketApiResponse;
|
||||
|
||||
fn raw_url(user: &str, repo: &str, commit: &str, file: &str) -> String {
|
||||
format!(
|
||||
"https://bitbucket.org/{}/{}/raw/{}/{}",
|
||||
user, repo, commit, file
|
||||
)
|
||||
}
|
||||
|
||||
fn api_url(path: &FilePath) -> String {
|
||||
format!(
|
||||
"https://api.bitbucket.org/2.0/repositories/{}/{}/commits/{}?pagelen=1",
|
||||
path.user, path.repo, path.commit
|
||||
)
|
||||
}
|
||||
|
||||
fn redirect_url(user: &str, repo: &str, commit: &str, file: &str) -> String {
|
||||
format!("/bitbucket/{}/{}/{}/{}", user, repo, commit, file)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user