Скачивание XLS документа по ссылке

This commit is contained in:
2025-03-21 23:55:16 +04:00
parent d75d3fbc97
commit 126ba23001
9 changed files with 1541 additions and 35 deletions

View File

@@ -0,0 +1,44 @@
use chrono::{DateTime, Utc};
#[derive(PartialEq, Debug)]
pub enum FetchError {
NoUrlProvided,
Unknown,
BadStatusCode,
BadContentType,
BadHeaders,
}
pub struct FetchOk {
pub etag: String,
pub uploaded_at: DateTime<Utc>,
pub requested_at: DateTime<Utc>,
pub data: Option<Vec<u8>>,
}
impl FetchOk {
pub fn head(etag: String, uploaded_at: DateTime<Utc>) -> Self {
FetchOk {
etag,
uploaded_at,
requested_at: Utc::now(),
data: None,
}
}
pub fn get(etag: String, uploaded_at: DateTime<Utc>, data: Vec<u8>) -> Self {
FetchOk {
etag,
uploaded_at,
requested_at: Utc::now(),
data: Some(data),
}
}
}
pub type FetchResult = Result<FetchOk, FetchError>;
pub trait XLSDownloader {
async fn fetch(&self, head: bool) -> FetchResult;
async fn set_url(&mut self, url: String) -> Result<(), FetchError>;
}