Реализованы все требуемые эндпоинты schedule.

Улучшена документация.
This commit is contained in:
2025-03-28 23:24:37 +04:00
parent 30c985a3d7
commit 680419ea78
32 changed files with 998 additions and 257 deletions

View File

@@ -2,7 +2,7 @@ use crate::xls_downloader::interface::{FetchError, FetchOk, FetchResult, XLSDown
use chrono::{DateTime, Utc};
pub struct BasicXlsDownloader {
url: Option<String>,
pub url: Option<String>,
}
async fn fetch_specified(url: &String, user_agent: String, head: bool) -> FetchResult {
@@ -73,14 +73,14 @@ impl XLSDownloader for BasicXlsDownloader {
}
}
async fn set_url(&mut self, url: String) -> Result<(), FetchError> {
async fn set_url(&mut self, url: String) -> FetchResult {
let result = fetch_specified(&url, "t.me/polytechnic_next".to_string(), true).await;
if let Ok(_) = result {
Ok(self.url = Some(url))
} else {
Err(result.err().unwrap())
self.url = Some(url);
}
result
}
}

View File

@@ -1,22 +1,41 @@
use chrono::{DateTime, Utc};
/// Ошибки получения данных XLS
#[derive(PartialEq, Debug)]
pub enum FetchError {
/// Не установлена ссылка на файл
NoUrlProvided,
/// Неизвестная ошибка
Unknown,
/// Сервер вернул статус код отличающийся от 200
BadStatusCode,
/// Ссылка ведёт на файл другого типа
BadContentType,
/// Сервер не вернул ожидаемые заголовки
BadHeaders,
}
/// Результат получения данных XLS
pub struct FetchOk {
/// ETag объекта
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,
@@ -26,6 +45,7 @@ impl FetchOk {
}
}
/// Полный результат
pub fn get(etag: String, uploaded_at: DateTime<Utc>, data: Vec<u8>) -> Self {
FetchOk {
etag,
@@ -39,6 +59,9 @@ impl FetchOk {
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>;
/// Установка ссылки на файл
async fn set_url(&mut self, url: String) -> FetchResult;
}