1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Files API for OpenCode.
//!
//! Endpoints for file operations.
use crate::error::Result;
use crate::http::HttpClient;
use crate::types::file::{FileContent, FileInfo, FileStatus};
use reqwest::Method;
/// Files API client.
#[derive(Clone)]
pub struct FilesApi {
http: HttpClient,
}
impl FilesApi {
/// Create a new Files API client.
pub fn new(http: HttpClient) -> Self {
Self { http }
}
/// List files in the project.
///
/// # Errors
///
/// Returns an error if the request fails.
pub async fn list(&self) -> Result<Vec<FileInfo>> {
self.http.request_json(Method::GET, "/file", None).await
}
/// Read file content.
///
/// # Errors
///
/// Returns an error if the request fails.
pub async fn read(&self, path: &str) -> Result<FileContent> {
let encoded = urlencoding::encode(path);
self.http
.request_json(
Method::GET,
&format!("/file/content?path={}", encoded),
None,
)
.await
}
/// Get file VCS status.
///
/// # Errors
///
/// Returns an error if the request fails.
pub async fn status(&self) -> Result<Vec<FileStatus>> {
self.http
.request_json(Method::GET, "/file/status", None)
.await
}
}