General cleanup: fix some bugs, some refactoring (#65)

* Merged mod file upload in version creation, mod creation and
  version file add to one function;  This makes sure that they are
  consistent
* Made some fields on `User` optional: `github_id`, `avatar_url`, `bio`.
    * We may not want to publicly show the `github_id` to everyone
      with access to the API
    * If we allow non-github users, some of those fields would be
      invalid; some oauth providers may not have avatars or bios
* Made CORS origins should configurable
* Made `--reconfigure-indices` and `--reset-indices` exit after
  completion instead of starting the server
This commit is contained in:
Aeledfyr
2020-10-01 00:07:52 -05:00
committed by GitHub
parent 43a791db65
commit c4fb7b7928
16 changed files with 318 additions and 561 deletions

View File

@@ -2,12 +2,12 @@ use super::ids::UserId;
pub struct User {
pub id: UserId,
pub github_id: i64,
pub github_id: Option<i64>,
pub username: String,
pub name: String,
pub email: Option<String>,
pub avatar_url: String,
pub bio: String,
pub avatar_url: Option<String>,
pub bio: Option<String>,
pub created: chrono::DateTime<chrono::Utc>,
pub role: String,
}
@@ -33,8 +33,8 @@ impl User {
&self.username,
&self.name,
self.email.as_ref(),
&self.avatar_url,
&self.bio,
self.avatar_url.as_ref(),
self.bio.as_ref(),
self.created,
)
.execute(&mut *transaction)
@@ -99,7 +99,7 @@ impl User {
if let Some(row) = result {
Ok(Some(User {
id: UserId(row.id),
github_id: github_id as i64,
github_id: Some(github_id as i64),
name: row.name,
email: row.email,
avatar_url: row.avatar_url,

View File

@@ -43,7 +43,7 @@ pub async fn run_migrations(uri: &str) -> Result<(), sqlx::Error> {
for migration in migrator.iter() {
if migration.version > version {
let elapsed = conn.apply(migration).await?;
let _elapsed = conn.apply(migration).await?;
} else {
conn.validate(migration).await?;
}