add lastmodified in store for files

This commit is contained in:
grimhilt 2023-06-19 17:23:52 +02:00
parent e0d4c5efac
commit 5d25429546
3 changed files with 15 additions and 12 deletions

View File

@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use clap::Values; use clap::Values;
use regex::Regex; use regex::Regex;
use crate::services::api::ApiError; use crate::services::api::ApiError;
use crate::services::req_props::ReqProps; use crate::services::req_props::{ReqProps, ObjProps};
use crate::services::download_files::DownloadFiles; use crate::services::download_files::DownloadFiles;
use crate::store::object; use crate::store::object;
use crate::commands; use crate::commands;
@ -40,7 +40,7 @@ pub fn clone(remote: Values<'_>) {
}; };
let mut folders = vec![String::from("")]; let mut folders = vec![String::from("")];
let mut files: Vec<String> = vec![]; let mut files: Vec<ObjProps> = vec![];
let mut first_iter = true; let mut first_iter = true;
while folders.len() > 0 { while folders.len() > 0 {
let folder = folders.pop().unwrap(); let folder = folders.pop().unwrap();
@ -51,6 +51,7 @@ pub fn clone(remote: Values<'_>) {
let res = ReqProps::new() let res = ReqProps::new()
.set_request(folder.as_str(), &api_props) .set_request(folder.as_str(), &api_props)
.gethref() .gethref()
.getlastmodified()
.send_req_multiple() .send_req_multiple()
.await; .await;
objs = match res { objs = match res {
@ -101,7 +102,7 @@ pub fn clone(remote: Values<'_>) {
if object.href.clone().unwrap().chars().last().unwrap() == '/' { if object.href.clone().unwrap().chars().last().unwrap() == '/' {
folders.push(object.relative_s.clone().unwrap().to_string()); folders.push(object.relative_s.clone().unwrap().to_string());
} else { } else {
files.push(object.relative_s.clone().unwrap().to_string()); files.push(object.clone());
} }
} }
first_iter = false; first_iter = false;
@ -110,22 +111,25 @@ pub fn clone(remote: Values<'_>) {
download_files(ref_path.clone(), files, &api_props); download_files(ref_path.clone(), files, &api_props);
} }
fn download_files(ref_p: PathBuf, files: Vec<String>, api_props: &ApiProps) { fn download_files(ref_p: PathBuf, files: Vec<ObjProps>, api_props: &ApiProps) {
for relative_file in files { for obj in files {
dbg!(obj.clone());
tokio::runtime::Runtime::new().unwrap().block_on(async { tokio::runtime::Runtime::new().unwrap().block_on(async {
let relative_s = &obj.clone().relative_s.unwrap();
let res = DownloadFiles::new() let res = DownloadFiles::new()
.set_url(relative_file.as_str(), api_props) .set_url(&relative_s, api_props)
.save(ref_p.clone()).await; .save(ref_p.clone()).await;
match res { match res {
Ok(()) => { Ok(()) => {
let relative_p = Path::new(&relative_file); let relative_p = Path::new(&relative_s);
if let Err(_) = object::add_blob(relative_p, "tmpdate") { let last_modified = obj.clone().lastmodified.unwrap().timestamp_millis();
eprintln!("error saving reference of {}", relative_file.clone()); if let Err(_) = object::add_blob(relative_p, &last_modified.to_string()) {
eprintln!("error saving reference of {}", relative_s.clone());
} }
}, },
Err(ApiError::Unexpected(_)) => { Err(ApiError::Unexpected(_)) => {
eprintln!("error writing {}", relative_file); eprintln!("error writing {}", relative_s);
}, },
Err(ApiError::IncorrectRequest(err)) => { Err(ApiError::IncorrectRequest(err)) => {
eprintln!("fatal: {}", err.status()); eprintln!("fatal: {}", err.status());

View File

@ -6,6 +6,7 @@ use crate::services::api::{ApiBuilder, ApiError};
use crate::utils::time::parse_timestamp; use crate::utils::time::parse_timestamp;
use crate::utils::api::{get_relative_s, ApiProps}; use crate::utils::api::{get_relative_s, ApiProps};
#[derive(Debug)]
pub struct ObjProps { pub struct ObjProps {
pub href: Option<String>, pub href: Option<String>,
pub relative_s: Option<String>, pub relative_s: Option<String>,

View File

@ -93,8 +93,6 @@ pub fn add_blob(path: &Path, date: &str) -> io::Result<()> {
let mut content = name.clone().to_owned(); let mut content = name.clone().to_owned();
content.push_str(" "); content.push_str(" ");
content.push_str("tmp_hash");
content.push_str(" ");
content.push_str(date); content.push_str(date);
// create blob object // create blob object