fix: correct endpoint data

This commit is contained in:
daimond113 2024-08-13 21:26:02 +02:00
parent 2ae368d97e
commit 159d0bafc1
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
3 changed files with 28 additions and 22 deletions

View file

@ -2,6 +2,7 @@ use actix_web::{http::header::ACCEPT, web, HttpRequest, HttpResponse, Responder}
use rusty_s3::{actions::GetObject, S3Action};
use semver::Version;
use serde::{Deserialize, Deserializer};
use std::collections::BTreeSet;
use crate::{
error::Error,
@ -54,7 +55,9 @@ pub async fn get_package_version(
}
};
let mut versions = entries.iter().filter(|(v_id, _)| *v_id.target() == target);
let mut versions = entries
.into_iter()
.filter(|(v_id, _)| *v_id.target() == target);
let version = match version {
VersionRequest::Latest => versions.max_by_key(|(v, _)| v.version().clone()),
@ -74,7 +77,7 @@ pub async fn get_package_version(
let object_url = GetObject::new(
&app_state.s3_bucket,
Some(&app_state.s3_credentials),
&s3_name(&name, v_id),
&s3_name(&name, &v_id),
)
.sign(S3_SIGN_DURATION);
@ -93,16 +96,9 @@ pub async fn get_package_version(
Ok(HttpResponse::Ok().json(PackageResponse {
name: name.to_string(),
version: v_id.version().to_string(),
targets: entries
.values()
.map(|entry| (&entry.target).into())
.collect(),
targets: BTreeSet::from([entry.target.into()]),
description: entry.description.clone().unwrap_or_default(),
published_at: entries
.values()
.max_by_key(|entry| entry.published_at)
.unwrap()
.published_at,
published_at: entry.published_at,
license: entry.license.clone().unwrap_or_default(),
}))
}

View file

@ -1,12 +1,14 @@
use actix_web::{web, HttpResponse, Responder};
use std::collections::BTreeSet;
use std::collections::{BTreeMap, BTreeSet};
use actix_web::{web, HttpResponse, Responder};
use crate::{error::Error, package::PackageResponse, AppState};
use pesde::{
names::PackageName,
source::{git_index::GitBasedSource, pesde::IndexFile},
};
use crate::{error::Error, package::PackageResponse, AppState};
pub async fn get_package_versions(
app_state: web::Data<AppState>,
path: web::Path<PackageName>,
@ -22,17 +24,23 @@ pub async fn get_package_versions(
None => return Ok(HttpResponse::NotFound().finish()),
};
Ok(HttpResponse::Ok().json(
versions
.into_iter()
.map(|(v_id, entry)| PackageResponse {
let mut responses = BTreeMap::new();
for (v_id, entry) in versions {
let info = responses
.entry(v_id.version().clone())
.or_insert_with(|| PackageResponse {
name: name.to_string(),
version: v_id.version().to_string(),
targets: BTreeSet::from([entry.target.into()]),
targets: BTreeSet::new(),
description: entry.description.unwrap_or_default(),
published_at: entry.published_at,
license: entry.license.unwrap_or_default(),
})
.collect::<Vec<_>>(),
))
});
info.targets.insert(entry.target.into());
info.published_at = info.published_at.max(entry.published_at);
}
Ok(HttpResponse::Ok().json(responses.into_values().collect::<Vec<_>>()))
}

View file

@ -214,6 +214,8 @@ pub async fn publish_package(
if let Some(this_version) = this_version {
let other_entry = entries.get(this_version).unwrap();
// TODO: should different licenses be allowed?
// description cannot be different - which one to render in the "Recently published" list?
if other_entry.description != new_entry.description
|| other_entry.license != new_entry.license
{