feat: add repo validation
This commit is contained in:
27
api/src/validate.rs
Normal file
27
api/src/validate.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use actix_web::web;
|
||||
|
||||
use crate::AppState;
|
||||
use crate::error::{Error, Result};
|
||||
use crate::user::RepositorySchema;
|
||||
|
||||
pub async fn validate_repo(app_state: web::Data<AppState>, repo: &RepositorySchema) -> Result<()> {
|
||||
let response = app_state
|
||||
.reqwest_client
|
||||
.get(format!(
|
||||
"https://raw.githubusercontent.com/{}/HEAD/dist/index.html",
|
||||
repo.full_name
|
||||
))
|
||||
.send()
|
||||
.await?;
|
||||
|
||||
match response.status() {
|
||||
reqwest::StatusCode::OK => Ok(()),
|
||||
reqwest::StatusCode::NOT_FOUND => Err(Error::ValidationFailed(
|
||||
"dist/index.html not found in repository".to_string(),
|
||||
)),
|
||||
status => Err(Error::ValidationFailed(format!(
|
||||
"failed to validate repository: HTTP {}",
|
||||
status
|
||||
))),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user