2021-05-30 15:02:07 -07:00
|
|
|
mod v1;
|
|
|
|
|
pub use v1::v1_config;
|
|
|
|
|
|
2020-09-26 22:49:16 -07:00
|
|
|
mod auth;
|
2021-10-12 11:26:59 +08:00
|
|
|
mod health;
|
2020-05-14 22:53:22 -07:00
|
|
|
mod index;
|
2021-03-29 11:36:55 +03:00
|
|
|
mod maven;
|
2020-11-15 19:58:11 -07:00
|
|
|
mod moderation;
|
2020-06-30 19:23:52 +02:00
|
|
|
mod not_found;
|
2021-03-04 20:35:23 -07:00
|
|
|
mod notifications;
|
2021-10-12 11:26:59 +08:00
|
|
|
pub(crate) mod project_creation;
|
2021-05-30 15:02:07 -07:00
|
|
|
mod projects;
|
2021-02-13 12:11:13 -07:00
|
|
|
mod reports;
|
2020-08-12 14:54:03 -05:00
|
|
|
mod tags;
|
2020-10-21 12:30:35 -07:00
|
|
|
mod teams;
|
2020-09-28 22:30:13 -07:00
|
|
|
mod users;
|
2020-08-12 11:05:49 -07:00
|
|
|
mod version_creation;
|
2021-05-30 15:02:07 -07:00
|
|
|
mod version_file;
|
2020-08-12 14:54:03 -05:00
|
|
|
mod versions;
|
|
|
|
|
|
2020-09-26 22:49:16 -07:00
|
|
|
pub use auth::config as auth_config;
|
2020-09-28 21:05:42 -07:00
|
|
|
pub use tags::config as tags_config;
|
2020-05-14 22:53:22 -07:00
|
|
|
|
2021-09-21 06:26:16 +02:00
|
|
|
pub use self::health::health_get;
|
2021-10-12 11:26:59 +08:00
|
|
|
pub use self::index::index_get;
|
2020-06-30 19:23:52 +02:00
|
|
|
pub use self::not_found::not_found;
|
2020-11-15 19:58:11 -07:00
|
|
|
use crate::file_hosting::FileHostingError;
|
2021-10-12 11:26:59 +08:00
|
|
|
use actix_web::web;
|
2020-08-12 14:54:03 -05:00
|
|
|
|
2021-05-30 15:02:07 -07:00
|
|
|
pub fn v2_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(
|
|
|
|
|
web::scope("/v2/")
|
|
|
|
|
.configure(auth_config)
|
|
|
|
|
.configure(tags_config)
|
|
|
|
|
.configure(projects_config)
|
|
|
|
|
.configure(versions_config)
|
|
|
|
|
.configure(teams_config)
|
|
|
|
|
.configure(users_config)
|
|
|
|
|
.configure(moderation_config)
|
|
|
|
|
.configure(reports_config)
|
|
|
|
|
.configure(notifications_config),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn projects_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(projects::project_search);
|
|
|
|
|
cfg.service(projects::projects_get);
|
|
|
|
|
cfg.service(project_creation::project_create);
|
2020-08-12 14:54:03 -05:00
|
|
|
|
|
|
|
|
cfg.service(
|
2021-05-30 15:02:07 -07:00
|
|
|
web::scope("project")
|
|
|
|
|
.service(projects::project_get)
|
|
|
|
|
.service(projects::project_delete)
|
|
|
|
|
.service(projects::project_edit)
|
|
|
|
|
.service(projects::project_icon_edit)
|
2021-07-27 16:50:07 -07:00
|
|
|
.service(projects::delete_project_icon)
|
|
|
|
|
.service(projects::add_gallery_item)
|
|
|
|
|
.service(projects::edit_gallery_item)
|
|
|
|
|
.service(projects::delete_gallery_item)
|
2021-05-30 15:02:07 -07:00
|
|
|
.service(projects::project_follow)
|
|
|
|
|
.service(projects::project_unfollow)
|
2021-06-02 18:33:11 -07:00
|
|
|
.service(teams::team_members_get_project)
|
2021-07-27 16:50:07 -07:00
|
|
|
.service(
|
|
|
|
|
web::scope("{project_id}")
|
|
|
|
|
.service(versions::version_list)
|
|
|
|
|
.service(projects::dependency_list),
|
|
|
|
|
),
|
2020-08-12 14:54:03 -05:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-29 11:36:55 +03:00
|
|
|
pub fn maven_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(maven::maven_metadata);
|
|
|
|
|
cfg.service(maven::version_file);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 14:54:03 -05:00
|
|
|
pub fn versions_config(cfg: &mut web::ServiceConfig) {
|
2020-10-05 14:25:32 -07:00
|
|
|
cfg.service(versions::versions_get);
|
2020-10-25 13:51:07 -07:00
|
|
|
cfg.service(version_creation::version_create);
|
2020-10-05 14:25:32 -07:00
|
|
|
cfg.service(
|
|
|
|
|
web::scope("version")
|
|
|
|
|
.service(versions::version_get)
|
|
|
|
|
.service(versions::version_delete)
|
2020-11-15 19:58:11 -07:00
|
|
|
.service(version_creation::upload_file_to_version)
|
|
|
|
|
.service(versions::version_edit),
|
|
|
|
|
);
|
|
|
|
|
cfg.service(
|
|
|
|
|
web::scope("version_file")
|
2021-05-30 15:02:07 -07:00
|
|
|
.service(version_file::delete_file)
|
|
|
|
|
.service(version_file::get_version_from_hash)
|
|
|
|
|
.service(version_file::download_version)
|
|
|
|
|
.service(version_file::get_update_from_hash),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
cfg.service(
|
|
|
|
|
web::scope("version_files")
|
|
|
|
|
.service(version_file::get_versions_from_hashes)
|
|
|
|
|
.service(version_file::download_files)
|
|
|
|
|
.service(version_file::update_files),
|
2020-10-05 14:25:32 -07:00
|
|
|
);
|
2020-08-12 14:54:03 -05:00
|
|
|
}
|
|
|
|
|
|
2020-09-28 22:30:13 -07:00
|
|
|
pub fn users_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(users::user_auth_get);
|
|
|
|
|
|
2020-10-05 14:25:32 -07:00
|
|
|
cfg.service(users::users_get);
|
2020-09-28 22:30:13 -07:00
|
|
|
cfg.service(
|
|
|
|
|
web::scope("user")
|
|
|
|
|
.service(users::user_get)
|
2021-05-30 15:02:07 -07:00
|
|
|
.service(users::projects_list)
|
2020-11-09 19:39:23 -07:00
|
|
|
.service(users::user_delete)
|
2020-11-27 10:57:04 -07:00
|
|
|
.service(users::user_edit)
|
2021-03-06 13:47:49 -07:00
|
|
|
.service(users::user_icon_edit)
|
2021-03-07 18:53:38 -07:00
|
|
|
.service(users::user_notifications)
|
2021-03-06 13:47:49 -07:00
|
|
|
.service(users::user_follows),
|
2020-09-28 22:30:13 -07:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:30:35 -07:00
|
|
|
pub fn teams_config(cfg: &mut web::ServiceConfig) {
|
2020-11-09 19:39:23 -07:00
|
|
|
cfg.service(
|
|
|
|
|
web::scope("team")
|
|
|
|
|
.service(teams::team_members_get)
|
|
|
|
|
.service(teams::edit_team_member)
|
2021-07-27 16:50:07 -07:00
|
|
|
.service(teams::transfer_ownership)
|
2020-11-09 19:39:23 -07:00
|
|
|
.service(teams::add_team_member)
|
|
|
|
|
.service(teams::join_team)
|
|
|
|
|
.service(teams::remove_team_member),
|
|
|
|
|
);
|
2020-10-21 12:30:35 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-06 13:47:49 -07:00
|
|
|
pub fn notifications_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(notifications::notifications_get);
|
2021-11-13 15:46:08 -07:00
|
|
|
cfg.service(notifications::notifications_delete);
|
2021-03-06 13:47:49 -07:00
|
|
|
|
|
|
|
|
cfg.service(
|
|
|
|
|
web::scope("notification")
|
|
|
|
|
.service(notifications::notification_get)
|
|
|
|
|
.service(notifications::notification_delete),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-15 21:47:45 -06:00
|
|
|
pub fn moderation_config(cfg: &mut web::ServiceConfig) {
|
2021-05-30 15:02:07 -07:00
|
|
|
cfg.service(web::scope("moderation").service(moderation::get_projects));
|
2020-11-15 21:47:45 -06:00
|
|
|
}
|
|
|
|
|
|
2021-02-13 12:11:13 -07:00
|
|
|
pub fn reports_config(cfg: &mut web::ServiceConfig) {
|
|
|
|
|
cfg.service(reports::reports);
|
|
|
|
|
cfg.service(reports::report_create);
|
|
|
|
|
cfg.service(reports::delete_report);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-12 14:54:03 -05:00
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
|
|
pub enum ApiError {
|
2020-11-27 10:57:04 -07:00
|
|
|
#[error("Environment Error")]
|
|
|
|
|
EnvError(#[from] dotenv::Error),
|
2020-11-15 19:58:11 -07:00
|
|
|
#[error("Error while uploading file")]
|
|
|
|
|
FileHostingError(#[from] FileHostingError),
|
2021-05-30 15:02:07 -07:00
|
|
|
#[error("Database Error: {0}")]
|
2020-08-12 14:54:03 -05:00
|
|
|
DatabaseError(#[from] crate::database::models::DatabaseError),
|
2021-05-30 15:02:07 -07:00
|
|
|
#[error("Database Error: {0}")]
|
|
|
|
|
SqlxDatabaseError(#[from] sqlx::Error),
|
2021-03-29 11:36:55 +03:00
|
|
|
#[error("Internal server error: {0}")]
|
|
|
|
|
XmlError(String),
|
2020-10-05 14:25:32 -07:00
|
|
|
#[error("Deserialization error: {0}")]
|
|
|
|
|
JsonError(#[from] serde_json::Error),
|
2020-11-09 19:39:23 -07:00
|
|
|
#[error("Authentication Error: {0}")]
|
2021-06-16 09:05:35 -07:00
|
|
|
AuthenticationError(#[from] crate::util::auth::AuthenticationError),
|
2020-11-09 19:39:23 -07:00
|
|
|
#[error("Authentication Error: {0}")]
|
|
|
|
|
CustomAuthenticationError(String),
|
|
|
|
|
#[error("Invalid Input: {0}")]
|
|
|
|
|
InvalidInputError(String),
|
2021-05-30 15:02:07 -07:00
|
|
|
#[error("Error while validating input: {0}")]
|
2021-06-16 09:05:35 -07:00
|
|
|
ValidationError(String),
|
2020-10-19 14:23:05 -07:00
|
|
|
#[error("Search Error: {0}")]
|
|
|
|
|
SearchError(#[from] meilisearch_sdk::errors::Error),
|
2020-12-02 10:24:20 -07:00
|
|
|
#[error("Indexing Error: {0}")]
|
|
|
|
|
IndexingError(#[from] crate::search::indexing::IndexingError),
|
2020-08-12 14:54:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl actix_web::ResponseError for ApiError {
|
|
|
|
|
fn status_code(&self) -> actix_web::http::StatusCode {
|
|
|
|
|
match self {
|
2020-11-27 10:57:04 -07:00
|
|
|
ApiError::EnvError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
|
2020-08-12 14:54:03 -05:00
|
|
|
ApiError::DatabaseError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
|
2021-05-30 15:02:07 -07:00
|
|
|
ApiError::SqlxDatabaseError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
|
2020-11-09 19:39:23 -07:00
|
|
|
ApiError::AuthenticationError(..) => actix_web::http::StatusCode::UNAUTHORIZED,
|
|
|
|
|
ApiError::CustomAuthenticationError(..) => actix_web::http::StatusCode::UNAUTHORIZED,
|
2021-03-29 11:36:55 +03:00
|
|
|
ApiError::XmlError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
|
2020-10-05 14:25:32 -07:00
|
|
|
ApiError::JsonError(..) => actix_web::http::StatusCode::BAD_REQUEST,
|
2020-10-19 14:23:05 -07:00
|
|
|
ApiError::SearchError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
|
2020-12-02 10:24:20 -07:00
|
|
|
ApiError::IndexingError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
|
2020-11-15 19:58:11 -07:00
|
|
|
ApiError::FileHostingError(..) => actix_web::http::StatusCode::INTERNAL_SERVER_ERROR,
|
2020-11-09 19:39:23 -07:00
|
|
|
ApiError::InvalidInputError(..) => actix_web::http::StatusCode::BAD_REQUEST,
|
2021-05-30 15:02:07 -07:00
|
|
|
ApiError::ValidationError(..) => actix_web::http::StatusCode::BAD_REQUEST,
|
2020-08-12 14:54:03 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn error_response(&self) -> actix_web::web::HttpResponse {
|
|
|
|
|
actix_web::web::HttpResponse::build(self.status_code()).json(
|
|
|
|
|
crate::models::error::ApiError {
|
|
|
|
|
error: match self {
|
2020-11-27 10:57:04 -07:00
|
|
|
ApiError::EnvError(..) => "environment_error",
|
2021-05-30 15:02:07 -07:00
|
|
|
ApiError::SqlxDatabaseError(..) => "database_error",
|
2020-08-12 14:54:03 -05:00
|
|
|
ApiError::DatabaseError(..) => "database_error",
|
2020-11-09 19:39:23 -07:00
|
|
|
ApiError::AuthenticationError(..) => "unauthorized",
|
|
|
|
|
ApiError::CustomAuthenticationError(..) => "unauthorized",
|
2021-03-29 11:36:55 +03:00
|
|
|
ApiError::XmlError(..) => "xml_error",
|
2020-10-05 14:25:32 -07:00
|
|
|
ApiError::JsonError(..) => "json_error",
|
2020-10-19 14:23:05 -07:00
|
|
|
ApiError::SearchError(..) => "search_error",
|
2020-12-02 10:24:20 -07:00
|
|
|
ApiError::IndexingError(..) => "indexing_error",
|
2020-11-15 19:58:11 -07:00
|
|
|
ApiError::FileHostingError(..) => "file_hosting_error",
|
2020-11-09 19:39:23 -07:00
|
|
|
ApiError::InvalidInputError(..) => "invalid_input",
|
2021-05-30 15:02:07 -07:00
|
|
|
ApiError::ValidationError(..) => "invalid_input",
|
2020-08-12 14:54:03 -05:00
|
|
|
},
|
|
|
|
|
description: &self.to_string(),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|