add pkgrel support
This commit is contained in:
parent
a56d990169
commit
1abc04eeb8
4 changed files with 68 additions and 25 deletions
|
@ -1,4 +1,5 @@
|
|||
use based::request::api::{FallibleApiResponse, api_error};
|
||||
use pacco::pkg::package::read_file_tar_raw;
|
||||
use rocket::tokio::io::AsyncReadExt;
|
||||
use rocket::{FromForm, State, post};
|
||||
use serde_json::json;
|
||||
|
@ -16,9 +17,6 @@ use crate::config::Config;
|
|||
|
||||
#[derive(FromForm)]
|
||||
pub struct PkgUpload<'r> {
|
||||
name: String,
|
||||
arch: String,
|
||||
version: String,
|
||||
pkg: TempFile<'r>,
|
||||
sig: Option<TempFile<'r>>,
|
||||
}
|
||||
|
@ -50,15 +48,39 @@ pub async fn upload_pkg(
|
|||
return Err(api_error("This repository is a mirror."));
|
||||
}
|
||||
|
||||
let pkg = Package::new(
|
||||
repo,
|
||||
Architecture::parse(&upload.arch).ok_or_else(|| api_error("Invalid architecture"))?,
|
||||
&upload.name,
|
||||
&upload.version,
|
||||
let pkg_file = tmp_file_to_vec(&upload.pkg).await;
|
||||
let content = read_file_tar_raw(&pkg_file, ".PKGINFO")
|
||||
.ok_or_else(|| api_error("Unable to read package file"))?;
|
||||
let pkg_info = Package::pkginfo_from_str(&content);
|
||||
|
||||
let pkg_name = pkg_info
|
||||
.iter()
|
||||
.find(|x| x.0 == "pkgname")
|
||||
.ok_or_else(|| api_error("Package has no pkgname"))?
|
||||
.1
|
||||
.as_str();
|
||||
|
||||
let (version, rel) = Package::version(
|
||||
&pkg_info
|
||||
.iter()
|
||||
.find(|x| x.0 == "pkgver")
|
||||
.ok_or_else(|| api_error("Package has no pkgver"))?
|
||||
.1,
|
||||
);
|
||||
|
||||
let arch = pkg_info
|
||||
.iter()
|
||||
.find(|x| x.0 == "pkgname")
|
||||
.ok_or_else(|| api_error("Package has no arch"))?
|
||||
.1
|
||||
.as_str();
|
||||
|
||||
let arch = Architecture::parse(&arch).ok_or_else(|| api_error("Invalid architecture"))?;
|
||||
|
||||
let pkg = Package::new(repo, arch, pkg_name, &version, rel);
|
||||
|
||||
pkg.save(
|
||||
tmp_file_to_vec(&upload.pkg).await,
|
||||
pkg_file,
|
||||
if let Some(sig) = &upload.sig {
|
||||
Some(tmp_file_to_vec(sig).await)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue