Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit edf36ce

Browse files
open-schnickGitea
authored andcommitted
Added actual endpoint call metadata implementation
1 parent 9cc54b3 commit edf36ce

File tree

4 files changed

+58
-14
lines changed

4 files changed

+58
-14
lines changed

api/src/ffs_api/endpoints.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::ffs_api::models::{
2-
error_response::ErrorResponse, move_resource::MoveResource, rename_resource::RenameResource,
2+
error_response::ErrorResponse, inode_timestamp_update_ressource::InodeTimestampUpdateRessource,
3+
move_resource::MoveResource, rename_resource::RenameResource,
34
};
45

56
use super::{
@@ -272,6 +273,31 @@ pub async fn download_file(
272273
Ok(Box::new(stream_reader))
273274
}
274275

276+
pub async fn set_last_modified_of_inode(
277+
api_config: &ApiConfig,
278+
token: &str,
279+
path: &Path,
280+
last_modified: i64,
281+
) -> Result<InodeResource> {
282+
let url = format!("{}/filesystem/timestamp", api_config.fss_base_url);
283+
284+
debug!("Authenticating with token '{}'", token);
285+
286+
let body = InodeTimestampUpdateRessource {
287+
path: path.to_str().unwrap().to_owned(),
288+
timestamp: last_modified,
289+
};
290+
291+
let response = reqwest::Client::new()
292+
.put(url)
293+
.bearer_auth(token)
294+
.json(&body)
295+
.send()
296+
.await?;
297+
298+
transform_response(response, StatusCode::OK).await
299+
}
300+
275301
async fn transform_response<T>(response: Response, expected_status: StatusCode) -> Result<T>
276302
where
277303
T: DeserializeOwned,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[derive(Debug, Serialize, Deserialize)]
2+
pub struct InodeTimestampUpdateRessource {
3+
pub path: String,
4+
pub timestamp: i64,
5+
}

api/src/ffs_api/models/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod contents_resource;
22
pub mod error_response;
33
pub mod folder_creation_resource;
44
pub mod inode_resource;
5+
pub mod inode_timestamp_update_ressource;
56
pub mod move_resource;
67
pub mod preflight_request_resource;
78
pub mod preflight_response_resource;

server/src/backend/storage_backend.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use chrono::NaiveDateTime;
55
use filefighter_api::ffs_api::{
66
endpoints::{
77
create_directory, delete_inode, download_file, get_contents_of_folder, get_inode,
8-
move_inode, rename_inode, upload_file,
8+
move_inode, rename_inode, set_last_modified_of_inode, upload_file,
99
},
1010
ApiConfig,
1111
ApiError::{self, ReqwestError, ResponseMalformed},
@@ -47,18 +47,30 @@ impl StorageBackend<FileFighterUser> for FileFighter {
4747
) -> Result<Self::Metadata> {
4848
let path = path.as_ref();
4949

50-
todo!()
51-
// // rclone wants to update time
52-
// if path_contains_rclone_modification_date(path)? {
53-
// } else {
54-
// // regular metadata request
55-
// let path = validate_and_normalize_path(path)?;
56-
// let inode = get_inode(&self.api_config, &path, &user.token)
57-
// .await
58-
// .map_err(transform_to_ftp_error)?;
59-
60-
// Ok(InodeMetaData::from(&inode, user.id))
61-
// }
50+
let inode = match path_contains_rclone_modification_date(path) {
51+
// rclone wants to update time
52+
Some(tuple) => {
53+
set_last_modified_of_inode(
54+
&self.api_config,
55+
&user.token,
56+
&tuple.1,
57+
tuple.0.timestamp(),
58+
)
59+
.await
60+
}
61+
// regular metadata request
62+
None => {
63+
get_inode(
64+
&self.api_config,
65+
&validate_and_normalize_path(path)?,
66+
&user.token,
67+
)
68+
.await
69+
}
70+
}
71+
.map_err(transform_to_ftp_error)?;
72+
73+
Ok(InodeMetaData::from(&inode, user.id))
6274
}
6375

6476
#[instrument(skip(self), level = "debug")]

0 commit comments

Comments
 (0)