fixed problem with official images

This commit is contained in:
Thomas Eppers 2021-09-02 01:00:09 +02:00
parent 7b1501f4d8
commit db5216b100
2 changed files with 19 additions and 18 deletions

View File

@ -29,6 +29,7 @@ pub struct Tags {
pub results: Vec<Images>,
}
#[derive(Debug)]
pub enum Error {
InvalidCharacter(char),
Fetching(String),
@ -37,13 +38,9 @@ pub enum Error {
impl Tags {
pub fn new(repo: String) -> Result<Self, Error> {
// let repo = Self::check_repo(repo)?;
let request = format!("https://hub.docker.com/v2/repositories/{}/tags", repo);
//check for right set of characters
if request.bytes().any(|c| !c.is_ascii()) {
return Err(Error::InvalidCharacter('a'));
}
//get response
let res = match reqwest::blocking::get(request) {
Ok(result) => result,
@ -60,14 +57,18 @@ impl Tags {
Ok(tags)
}
pub fn get_images(&self) -> &Vec<Images> {
&self.results
pub fn check_repo(mut name: String) -> Result<String, Error> {
//check for right set of characters
if name.bytes().any(|c| !c.is_ascii()) {
return Err(Error::InvalidCharacter('a'));
}
}
impl Images {
pub fn get_name(&self) -> &str {
&self.tag_name
//check if need to inject "library" of given repo
let regex = regex::Regex::new(r".*/.*").unwrap();
if !regex.is_match(&name) {
name.insert_str(0, "library/");
}
Ok(name)
}
}

View File

@ -93,10 +93,7 @@ impl Ui {
ui.tags = tag_list::TagList::with_repo(ui.repo.get());
}
State::SelectTag => {
let mut repo = match ui.services.extract_repo() {
Err(_) => continue,
Ok(s) => s,
};
let mut repo = ui.repo.get();
let tag = match ui.tags.get_selected() {
Err(_) => continue,
Ok(tag) => tag,
@ -136,8 +133,11 @@ impl Ui {
match ui.services.extract_repo() {
Err(_) => ui.tags = tag_list::TagList::with_status("No image found"),
Ok(s) => {
ui.repo.set(s);
ui.tags = tag_list::TagList::with_repo(ui.repo.get());
let repo = match crate::tags::Tags::check_repo(s) {
Err(_) => continue,
Ok(s) => s,
};
ui.repo.set(repo);
}
}
}