2024-07-30 11:37:54 +01:00
|
|
|
use chrono::{DateTime, Utc};
|
|
|
|
use pesde::{
|
|
|
|
manifest::target::{Target, TargetKind},
|
|
|
|
names::PackageName,
|
|
|
|
source::version_id::VersionId,
|
|
|
|
};
|
|
|
|
use serde::Serialize;
|
2024-08-13 19:14:41 +01:00
|
|
|
use std::{collections::BTreeSet, time::Duration};
|
2024-07-30 11:37:54 +01:00
|
|
|
|
2024-08-14 18:55:58 +01:00
|
|
|
pub const S3_SIGN_DURATION: Duration = Duration::from_secs(60 * 3);
|
2024-07-30 11:37:54 +01:00
|
|
|
|
2024-08-14 18:55:58 +01:00
|
|
|
pub fn s3_name(name: &PackageName, version_id: &VersionId, is_readme: bool) -> String {
|
|
|
|
format!(
|
2024-09-02 15:49:40 +01:00
|
|
|
"{name}/{}/{}/{}.gz",
|
|
|
|
version_id.version(),
|
|
|
|
version_id.target(),
|
|
|
|
if is_readme { "readme" } else { "pkg.tar" },
|
2024-08-14 18:55:58 +01:00
|
|
|
)
|
2024-07-30 11:37:54 +01:00
|
|
|
}
|
|
|
|
|
2024-09-02 15:49:40 +01:00
|
|
|
pub fn s3_doc_name(doc_hash: &str) -> String {
|
|
|
|
format!("doc/{}.gz", doc_hash)
|
|
|
|
}
|
|
|
|
|
2024-08-13 19:14:41 +01:00
|
|
|
#[derive(Debug, Serialize, Eq, PartialEq)]
|
2024-07-30 11:37:54 +01:00
|
|
|
pub struct TargetInfo {
|
|
|
|
kind: TargetKind,
|
|
|
|
lib: bool,
|
|
|
|
bin: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Target> for TargetInfo {
|
|
|
|
fn from(target: Target) -> Self {
|
2024-08-14 18:55:58 +01:00
|
|
|
(&target).into()
|
2024-07-30 11:37:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-13 19:14:41 +01:00
|
|
|
impl From<&Target> for TargetInfo {
|
|
|
|
fn from(target: &Target) -> Self {
|
|
|
|
TargetInfo {
|
|
|
|
kind: target.kind(),
|
|
|
|
lib: target.lib_path().is_some(),
|
|
|
|
bin: target.bin_path().is_some(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ord for TargetInfo {
|
|
|
|
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
|
|
|
self.kind.cmp(&other.kind)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PartialOrd for TargetInfo {
|
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
|
|
Some(self.cmp(other))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-30 11:37:54 +01:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct PackageResponse {
|
|
|
|
pub name: String,
|
|
|
|
pub version: String,
|
2024-08-13 19:14:41 +01:00
|
|
|
pub targets: BTreeSet<TargetInfo>,
|
2024-07-30 11:37:54 +01:00
|
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
|
|
pub description: String,
|
|
|
|
pub published_at: DateTime<Utc>,
|
|
|
|
#[serde(skip_serializing_if = "String::is_empty")]
|
|
|
|
pub license: String,
|
2024-08-14 18:55:58 +01:00
|
|
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
|
|
|
pub authors: Vec<String>,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub repository: Option<String>,
|
2024-07-30 11:37:54 +01:00
|
|
|
}
|