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 rusty_s3::{actions::GetObject, S3Action};
use semver::Version; use semver::Version;
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
use std::collections::BTreeSet;
use crate::{ use crate::{
error::Error, 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 { let version = match version {
VersionRequest::Latest => versions.max_by_key(|(v, _)| v.version().clone()), 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( let object_url = GetObject::new(
&app_state.s3_bucket, &app_state.s3_bucket,
Some(&app_state.s3_credentials), Some(&app_state.s3_credentials),
&s3_name(&name, v_id), &s3_name(&name, &v_id),
) )
.sign(S3_SIGN_DURATION); .sign(S3_SIGN_DURATION);
@ -93,16 +96,9 @@ pub async fn get_package_version(
Ok(HttpResponse::Ok().json(PackageResponse { Ok(HttpResponse::Ok().json(PackageResponse {
name: name.to_string(), name: name.to_string(),
version: v_id.version().to_string(), version: v_id.version().to_string(),
targets: entries targets: BTreeSet::from([entry.target.into()]),
.values()
.map(|entry| (&entry.target).into())
.collect(),
description: entry.description.clone().unwrap_or_default(), description: entry.description.clone().unwrap_or_default(),
published_at: entries published_at: entry.published_at,
.values()
.max_by_key(|entry| entry.published_at)
.unwrap()
.published_at,
license: entry.license.clone().unwrap_or_default(), license: entry.license.clone().unwrap_or_default(),
})) }))
} }

View file

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