Skip to content

Commit

Permalink
delete dead code
Browse files Browse the repository at this point in the history
Signed-off-by: bokket <[email protected]>
  • Loading branch information
bokket committed Jan 18, 2024
1 parent 1fdb8d0 commit 572d7c9
Showing 1 changed file with 28 additions and 71 deletions.
99 changes: 28 additions & 71 deletions core/src/services/icloud/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,13 @@ impl PathQuery for IcloudPathQuery {

// Retrieves the root directory within the icloud Drive.
async fn query(&self, parent_id: &str, name: &str) -> Result<Option<String>> {
let mut core = self.signer.lock().await;
let drive_url = core
let mut signer = self.signer.lock().await;
let drive_url = signer
.get_service_info(String::from("drive"))
.unwrap()
.ok_or(Error::new(
ErrorKind::NotFound,
"drive service info drivews not found",
))?
.clone()
.url;

Expand All @@ -373,7 +376,7 @@ impl PathQuery for IcloudPathQuery {

let async_body = AsyncBody::Bytes(bytes::Bytes::from(body));

let response = core.sign(Method::POST, uri, async_body).await?;
let response = signer.sign(Method::POST, uri, async_body).await?;

if response.status() == StatusCode::OK {
let body = &response.into_body().bytes().await?;
Expand All @@ -394,11 +397,14 @@ impl PathQuery for IcloudPathQuery {
}

async fn create_dir(&self, parent_id: &str, name: &str) -> Result<String> {
let mut core = self.signer.lock().await;
let client_id = core.get_client_id();
let drive_url = core
let mut signer = self.signer.lock().await;
let client_id = signer.get_client_id();
let drive_url = signer
.get_service_info(String::from("drive"))
.unwrap()
.ok_or(Error::new(
ErrorKind::NotFound,
"drive service info drivews not found",
))?
.url
.clone();

Expand All @@ -417,7 +423,7 @@ impl PathQuery for IcloudPathQuery {
.to_string();

let async_body = AsyncBody::Bytes(bytes::Bytes::from(body));
let response = core.sign(Method::POST, uri, async_body).await?;
let response = signer.sign(Method::POST, uri, async_body).await?;

match response.status() {
StatusCode::OK => {
Expand All @@ -436,19 +442,20 @@ impl PathQuery for IcloudPathQuery {
impl IcloudCore {
// Logs into icloud using the provided credentials.
pub async fn login(&self) -> Result<()> {
let mut core = self.signer.lock().await;
let mut signer = self.signer.lock().await;

core.signer().await
signer.signer().await
}

//Apple Drive
pub async fn drive(&self) -> Option<DriveService> {
let clone = self.signer.clone();
let core = self.signer.lock().await;
let signer = self.signer.lock().await;

let docw = core.get_service_info(String::from("docw")).unwrap();
core.get_service_info(String::from("drive"))
.map(|s| DriveService::new(clone, s.url.clone(), docw.url.clone()))
let docws = signer.get_service_info(String::from("docw")).unwrap();
signer
.get_service_info(String::from("drive"))
.map(|s| DriveService::new(clone, s.url.clone(), docws.url.clone()))
}

pub async fn read(&self, path: &str, args: &OpRead) -> Result<Response<IncomingAsyncBody>> {
Expand Down Expand Up @@ -508,14 +515,8 @@ impl IcloudCore {

let node = drive.get_root(&folder_id).await?;

match node.items() {
Some(items) => match items.iter().find(|it| it.drivewsid == file_id.clone()) {
Some(it) => Ok(it.clone()),
_ => Err(Error::new(
ErrorKind::NotFound,
"icloud DriveService stat parent items don't have same drivewsid",
)),
},
match node.items.iter().find(|it| it.drivewsid == file_id.clone()) {
Some(it) => Ok(it.clone()),
None => Err(Error::new(
ErrorKind::NotFound,
"icloud DriveService stat get parent items error",
Expand All @@ -524,50 +525,6 @@ impl IcloudCore {
}
}

#[derive(Clone)]
pub struct File {
pub id: Option<String>,
pub name: String,
pub size: u64,
pub date_created: Option<String>,
pub date_modified: Option<String>,
pub mime_type: String,
}

// A directory in icloud Drive.
#[derive(Clone)]
pub struct Folder {
pub id: Option<String>,
pub name: String,
pub date_created: Option<String>,
pub items: Vec<IcloudItem>,
pub mime_type: String,
}

// A node within the icloud Drive filesystem.
#[derive(Clone)]
pub enum DriveNode {
Folder(Folder),
}

impl DriveNode {
fn new_root(value: &IcloudRoot) -> Result<DriveNode> {
Ok(DriveNode::Folder(Folder {
id: Some(value.drivewsid.to_string()),
name: value.name.to_string(),
date_created: Some(value.date_created.clone()),
items: value.items.clone(),
mime_type: "Folder".to_string(),
}))
}

pub fn items(&self) -> Option<Vec<IcloudItem>> {
match self {
DriveNode::Folder(folder) => Some(folder.items.clone()),
}
}
}

pub struct DriveService {
signer: Arc<Mutex<IcloudSigner>>,
drive_url: String,
Expand All @@ -590,7 +547,7 @@ impl DriveService {

// Retrieves a root within the icloud Drive.
// "FOLDER::com.apple.CloudDocs::root"
pub async fn get_root(&self, id: &str) -> Result<DriveNode> {
pub async fn get_root(&self, id: &str) -> Result<IcloudRoot> {
let uri = format!("{}/retrieveItemDetailsInFolders", self.drive_url);

let body = json!([
Expand All @@ -612,7 +569,7 @@ impl DriveService {
let drive_node: Vec<IcloudRoot> =
serde_json::from_slice(body.chunk()).map_err(new_json_deserialize_error)?;

Ok(DriveNode::new_root(&drive_node[0])?)
Ok(drive_node[0].clone())
} else {
Err(parse_error(response).await?)
}
Expand Down Expand Up @@ -651,7 +608,7 @@ impl DriveService {

let range = args.range();
if !range.is_full() {
request_builder = request_builder.header(http::header::RANGE, range.to_header())
request_builder = request_builder.header(header::RANGE, range.to_header())
}

if let Some(if_none_match) = args.if_none_match() {
Expand Down Expand Up @@ -815,7 +772,7 @@ pub struct IcloudCreateFolder {

#[cfg(test)]
mod tests {
use crate::services::icloud::core::{IcloudRoot, IcloudWebservicesResponse};
use super::{IcloudRoot, IcloudWebservicesResponse};

#[test]
fn test_parse_icloud_drive_root_json() {
Expand Down

0 comments on commit 572d7c9

Please sign in to comment.