Add repository file browser
This commit is contained in:
@@ -222,6 +222,51 @@ pub async fn load_branches(
|
||||
Ok(branches)
|
||||
}
|
||||
|
||||
pub async fn load_repository_contents(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
path: &str,
|
||||
) -> Result<Vec<models::ContentsResponse>, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
let configuration = client.configuration();
|
||||
if path.is_empty() {
|
||||
apis::repository_api::repo_get_contents_list(&configuration, owner, repository, None)
|
||||
.await
|
||||
.map_err(|error| error.to_string())
|
||||
} else {
|
||||
apis::repository_api::repo_get_contents_ext(
|
||||
&configuration,
|
||||
owner,
|
||||
repository,
|
||||
path,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map(|contents| contents.dir_contents.unwrap_or_default())
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn load_repository_file(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
path: &str,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
let client =
|
||||
Client::new(&server.url, Some(&server.token)).map_err(|error| error.to_string())?;
|
||||
apis::repository_api::repo_get_raw_file(&client.configuration(), owner, repository, path, None)
|
||||
.await
|
||||
.map_err(|error| error.to_string())?
|
||||
.bytes()
|
||||
.await
|
||||
.map(|bytes| bytes.to_vec())
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
pub async fn load_branch_commits(
|
||||
server: &Server,
|
||||
owner: &str,
|
||||
|
||||
Reference in New Issue
Block a user