use anyhow::Result;
use serde::{Deserialize, Serialize};
use crate::api::alist::{Client, JsonOrLog};
use crate::common::log::LogResult;
impl Client {
pub async fn fs_list(
&self,
path: Option<&str>,
password: Option<&str>,
refresh: Option<bool>,
) -> Result<Data> {
let url = format!("{}/fs/list", self.url);
let request = self.client.post(&url);
let request = self.auth(request)?;
let request = request.json(&Request {
page: None,
password: password.map(|s| s.to_string()),
path: path.map(|s| s.to_string()),
per_page: Some(i64::MAX),
refresh,
});
let response = request.send().await.log()?;
let response = response.error_for_status().log()?;
let response: Response = response.json_or_log().await?;
crate::ensure!(response.code == 200);
crate::ensure!(response.message == "success");
Ok(response.data)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Request {
page: Option<i64>,
password: Option<String>,
path: Option<String>,
per_page: Option<i64>,
refresh: Option<bool>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Response {
pub code: i64,
pub data: Data,
pub message: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Data {
pub content: Option<Vec<Content>>,
pub provider: String,
pub readme: String,
pub total: i64,
pub write: bool,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Content {
pub is_dir: bool,
pub modified: String,
pub name: String,
pub sign: String,
pub size: i64,
pub thumb: String,
#[serde(rename = "type")]
pub content_type: i64,
}