Add function to add files to a page

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 382019c4be
commit d576c7c675
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -17,7 +17,8 @@ use crate::api_core::managing_cookies_and_http_headers::{
SetUserAgentRequest, SetUserAgentRequest,
}; };
use crate::api_core::managing_pages::{ use crate::api_core::managing_pages::{
FocusPage, FocusPageRequest, GetPageInfo, GetPageInfoResponse, GetPages, GetPagesResponse, AddFiles, AddFilesRequest, FocusPage, FocusPageRequest, GetPageInfo, GetPageInfoResponse,
GetPages, GetPagesResponse,
}; };
use crate::api_core::searching_and_fetching_files::{ use crate::api_core::searching_and_fetching_files::{
FileMetadata, FileMetadataResponse, GetFile, SearchFiles, SearchFilesResponse, FileMetadata, FileMetadataResponse, GetFile, SearchFiles, SearchFilesResponse,
@ -361,6 +362,30 @@ impl Client {
Ok(()) Ok(())
} }
/// Adds files to a page
pub async fn add_files_to_page<S: ToString>(
&self,
page_key: S,
file_ids: Vec<u64>,
hashes: Vec<String>,
) -> Result<()> {
let page_key = page_key.to_string();
log::trace!(
"Adding files with ids {:?} or hashes {:?} to page {}",
file_ids,
hashes,
page_key
);
self.post::<AddFiles>(AddFilesRequest {
page_key,
file_ids,
hashes,
})
.await?;
Ok(())
}
/// Returns all cookies for the given domain /// Returns all cookies for the given domain
pub async fn get_cookies<S: AsRef<str>>(&self, domain: S) -> Result<GetCookiesResponse> { pub async fn get_cookies<S: AsRef<str>>(&self, domain: S) -> Result<GetCookiesResponse> {
log::trace!("Getting cookies"); log::trace!("Getting cookies");

@ -49,3 +49,23 @@ impl Endpoint for FocusPage {
String::from("manage_pages/focus_page") String::from("manage_pages/focus_page")
} }
} }
#[derive(Clone, Debug, Serialize)]
pub struct AddFilesRequest {
pub page_key: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub file_ids: Vec<u64>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub hashes: Vec<String>,
}
pub struct AddFiles;
impl Endpoint for AddFiles {
type Request = AddFilesRequest;
type Response = ();
fn path() -> String {
String::from("manage_pages/add_files")
}
}

@ -24,3 +24,17 @@ async fn it_focuses_pages() {
assert!(result.is_err()); // page does not exist assert!(result.is_err()); // page does not exist
} }
#[tokio::test]
async fn it_adds_files_to_a_page() {
let client = common::get_client();
let result = client
.add_files_to_page(
"0c33d6599c22d5ec12a57b79d8c5a528ebdab7a8c2b462e6d76e2d0512e917fd",
vec![0],
vec![],
)
.await;
assert!(result.is_err()) // page does not exist
}

Loading…
Cancel
Save