This commit is contained in:
parent
5763c8a1c4
commit
67c31725c1
4 changed files with 23 additions and 5 deletions
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod pkg;
|
|
@ -9,11 +9,10 @@ use based::get_pg;
|
||||||
use based::page::{Shell, render_page};
|
use based::page::{Shell, render_page};
|
||||||
use based::request::{RequestContext, StringResponse};
|
use based::request::{RequestContext, StringResponse};
|
||||||
use maud::html;
|
use maud::html;
|
||||||
use pkg::Repository;
|
use pacco::pkg::Repository;
|
||||||
use rocket::get;
|
use rocket::get;
|
||||||
use rocket::routes;
|
use rocket::routes;
|
||||||
|
|
||||||
pub mod pkg;
|
|
||||||
pub mod routes;
|
pub mod routes;
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
|
|
|
@ -27,6 +27,24 @@ impl Package {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract values from a package filename
|
/// Extract values from a package filename
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use pacco::pkg::Package;
|
||||||
|
///
|
||||||
|
/// let (name, version, rel, arch) = Package::extract_pkg_name("pkg-ver-rel-x86_64.pkg.tar.zst").unwrap();
|
||||||
|
/// assert_eq!(name, "pkg");
|
||||||
|
/// assert_eq!(version, "ver");
|
||||||
|
/// assert_eq!(rel, "rel");
|
||||||
|
/// assert_eq!(arch, pacco::pkg::arch::Architecture::x86_64);
|
||||||
|
///
|
||||||
|
/// let (name, version, rel, arch) = Package::extract_pkg_name("my-pkg-ver-rel-x86_64.pkg.tar.zst").unwrap();
|
||||||
|
/// assert_eq!(name, "my-pkg");
|
||||||
|
/// assert_eq!(version, "ver");
|
||||||
|
/// assert_eq!(rel, "rel");
|
||||||
|
/// assert_eq!(arch, pacco::pkg::arch::Architecture::x86_64);
|
||||||
|
/// ```
|
||||||
pub fn extract_pkg_name(file_name: &str) -> Option<(String, String, String, Architecture)> {
|
pub fn extract_pkg_name(file_name: &str) -> Option<(String, String, String, Architecture)> {
|
||||||
// Extract (assuming the filename is "<pkg_name>-<version>-<relation>-<arch>.pkg.tar.zst")
|
// Extract (assuming the filename is "<pkg_name>-<version>-<relation>-<arch>.pkg.tar.zst")
|
||||||
let mut splitted = file_name.split('-').collect::<Vec<&str>>();
|
let mut splitted = file_name.split('-').collect::<Vec<&str>>();
|
||||||
|
@ -38,7 +56,7 @@ impl Package {
|
||||||
let relation = splitted.pop()?;
|
let relation = splitted.pop()?;
|
||||||
let version = splitted.pop()?;
|
let version = splitted.pop()?;
|
||||||
|
|
||||||
let pkg_name = splitted.join(" ");
|
let pkg_name = splitted.join("-");
|
||||||
|
|
||||||
return Some((
|
return Some((
|
||||||
pkg_name,
|
pkg_name,
|
||||||
|
|
|
@ -5,8 +5,8 @@ use rocket::tokio::io::AsyncReadExt;
|
||||||
use rocket::{FromForm, get, post};
|
use rocket::{FromForm, get, post};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::pkg::arch::Architecture;
|
use pacco::pkg::arch::Architecture;
|
||||||
use crate::pkg::{Package, Repository};
|
use pacco::pkg::{Package, Repository};
|
||||||
|
|
||||||
// /pkg/<repo>/<arch>/<pkg_name>
|
// /pkg/<repo>/<arch>/<pkg_name>
|
||||||
// /pkg/<repo>/<arch>/
|
// /pkg/<repo>/<arch>/
|
||||||
|
|
Loading…
Add table
Reference in a new issue