-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
680f360
commit d0796c2
Showing
92 changed files
with
2,010 additions
and
881 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use derive_builder::Builder; | ||
use http::version; | ||
use sqlx::{types::Json, Execute, PgPool, QueryBuilder}; | ||
use tracing::{info, instrument, warn}; | ||
|
||
use crate::repository::project::{ReleaseType, VersionData}; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Default)] | ||
pub struct UpdateProjectVersion { | ||
pub release_type: Option<ReleaseType>, | ||
//#[builder(default)] | ||
//pub publisher: Option<i32>, | ||
//#[builder(default)] | ||
//pub version_page: Option<String>, | ||
pub extra: Option<VersionData>, | ||
} | ||
|
||
impl UpdateProjectVersion { | ||
#[instrument(name = "UpdateProjectVersion::update")] | ||
pub async fn update(self, version_id: i32, db: &PgPool) -> Result<(), sqlx::Error> { | ||
let mut query = QueryBuilder::new("UPDATE project_versions SET updated_at = NOW(), "); | ||
let mut separated = query.separated(", "); | ||
if let Some(release_type) = self.release_type { | ||
separated.push("release_type = "); | ||
separated.push_bind_unseparated(release_type); | ||
} | ||
//if let Some(version_page) = self.version_page { | ||
// separated.push("user_manager = "); | ||
// separated.push_bind_unseparated(version_page); | ||
//} | ||
if let Some(extra) = self.extra { | ||
separated.push("extra = "); | ||
separated.push_bind_unseparated(Json(extra)); | ||
} | ||
query.push(" WHERE id = "); | ||
query.push_bind(version_id); | ||
let query: sqlx::query::Query<sqlx::Postgres, sqlx::postgres::PgArguments> = query.build(); | ||
info!( | ||
"Updating project_version for version_id {} {}", | ||
version_id, | ||
query.sql() | ||
); | ||
let result = query.execute(db).await?; | ||
if result.rows_affected() == 0 { | ||
warn!( | ||
"No rows affected when updating project_version for version_id {}", | ||
version_id | ||
); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::fmt::Display; | ||
|
||
use derive_more::derive::{AsRef, Deref}; | ||
use schemars::JsonSchema; | ||
use serde::Serialize; | ||
use tracing::{instrument, trace}; | ||
use url::Url; | ||
|
||
use crate::storage::StoragePath; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, JsonSchema, Deref, AsRef)] | ||
pub struct ProxyURL(String); | ||
|
||
impl Serialize for ProxyURL { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
self.0.serialize(serializer) | ||
} | ||
} | ||
|
||
impl<'de> serde::Deserialize<'de> for ProxyURL { | ||
fn deserialize<D>(deserializer: D) -> Result<ProxyURL, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
let s = String::deserialize(deserializer)?; | ||
|
||
Ok(ProxyURL::try_from(s).map_err(serde::de::Error::custom)?) | ||
} | ||
} | ||
|
||
impl TryFrom<String> for ProxyURL { | ||
type Error = url::ParseError; | ||
|
||
fn try_from(value: String) -> Result<Self, Self::Error> { | ||
let mut s = value; | ||
if s.ends_with("/") { | ||
s.pop(); | ||
} | ||
let url = url::Url::parse(&s)?; | ||
trace!(url = %url, "Parsed URL"); | ||
Ok(ProxyURL(s)) | ||
} | ||
} | ||
impl Display for ProxyURL { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
self.0.fmt(f) | ||
} | ||
} | ||
impl From<ProxyURL> for String { | ||
fn from(url: ProxyURL) -> String { | ||
url.0 | ||
} | ||
} | ||
impl ProxyURL { | ||
/// Creates a URL from a proxyURL and a path | ||
#[instrument] | ||
pub fn add_storage_path(&self, path: StoragePath) -> Result<Url, url::ParseError> { | ||
let mut path = path.to_string(); | ||
if path.starts_with("/") { | ||
path = path[1..].to_string(); | ||
} | ||
let raw_url = format!("{}/{}", self.0, path); | ||
trace!(url = %raw_url, "Creating URL"); | ||
let url = Url::parse(&format!("{}/{}", self.0, path))?; | ||
Ok(url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.