@anysphere/file-service 0.0.0-e6124fba → 0.0.0-e68f3241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +179 -9
- package/index.js +70 -4
- package/package.json +19 -11
- package/.yarnrc.yml +0 -1
- package/Cargo.toml +0 -40
- package/build.rs +0 -46
- package/src/file_utils.rs +0 -328
- package/src/git_utils.rs +0 -355
- package/src/lib.rs +0 -308
- package/src/lib2.rs +0 -212
- package/src/merkle_tree/local_construction.rs +0 -243
- package/src/merkle_tree/mod.rs +0 -1193
- package/src/merkle_tree/remote_sync.rs +0 -40
- package/src/merkle_tree/test.rs +0 -127
- package/src/merkle_tree/test_files/1/test.txt +0 -0
- package/src/test.rs +0 -5
package/src/lib.rs
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
#![windows_subsystem = "windows"]
|
|
2
|
-
#![deny(clippy::all)]
|
|
3
|
-
#![deny(unsafe_op_in_unsafe_fn)]
|
|
4
|
-
pub mod file_utils;
|
|
5
|
-
pub mod merkle_tree;
|
|
6
|
-
|
|
7
|
-
use std::{collections::HashSet, vec};
|
|
8
|
-
|
|
9
|
-
use anyhow::Context;
|
|
10
|
-
use merkle_tree::{LocalConstruction, MerkleTree};
|
|
11
|
-
use tracing::{info, Level};
|
|
12
|
-
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
|
13
|
-
use tracing_subscriber::fmt;
|
|
14
|
-
|
|
15
|
-
#[macro_use]
|
|
16
|
-
extern crate napi_derive;
|
|
17
|
-
|
|
18
|
-
#[napi]
|
|
19
|
-
pub struct MerkleClient {
|
|
20
|
-
tree: MerkleTree,
|
|
21
|
-
absolute_root_directory: String,
|
|
22
|
-
_guard: Option<tracing_appender::non_blocking::WorkerGuard>,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
pub fn init_logger() -> Option<tracing_appender::non_blocking::WorkerGuard> {
|
|
26
|
-
#[cfg(feature = "debugfile")]
|
|
27
|
-
let _guard = {
|
|
28
|
-
let file_appender =
|
|
29
|
-
RollingFileAppender::new(Rotation::NEVER, "./", "rust_log.txt");
|
|
30
|
-
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
|
|
31
|
-
let subscriber = fmt::Subscriber::builder()
|
|
32
|
-
.with_max_level(Level::TRACE)
|
|
33
|
-
.with_writer(non_blocking)
|
|
34
|
-
.with_ansi(false)
|
|
35
|
-
.with_line_number(true)
|
|
36
|
-
.finish();
|
|
37
|
-
|
|
38
|
-
let _ = tracing::subscriber::set_global_default(subscriber);
|
|
39
|
-
Some(_guard)
|
|
40
|
-
};
|
|
41
|
-
#[cfg(not(feature = "debugfile"))]
|
|
42
|
-
let _guard = { None };
|
|
43
|
-
_guard
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
#[napi]
|
|
47
|
-
impl MerkleClient {
|
|
48
|
-
#[napi(constructor)]
|
|
49
|
-
pub fn new(absolute_root_directory: String) -> MerkleClient {
|
|
50
|
-
let _guard = init_logger();
|
|
51
|
-
|
|
52
|
-
// let canonical_root_directory = std::path::Path::new(&absolute_root_directory);
|
|
53
|
-
// use dunce::canonicalize;
|
|
54
|
-
// let canonical_root_directory = match dunce::canonicalize(&canonical_root_directory) {
|
|
55
|
-
// Ok(path) => path.to_str().unwrap_or(&absolute_root_directory).to_string().to_lowercase(),
|
|
56
|
-
// Err(e) => {
|
|
57
|
-
// info!("Error in canonicalizing path: path: {:?}, error {:?}", canonical_root_directory, e);
|
|
58
|
-
// absolute_root_directory
|
|
59
|
-
// }
|
|
60
|
-
// };
|
|
61
|
-
|
|
62
|
-
MerkleClient {
|
|
63
|
-
tree: MerkleTree::empty_tree(),
|
|
64
|
-
absolute_root_directory,
|
|
65
|
-
_guard,
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
#[napi]
|
|
70
|
-
pub async unsafe fn init(
|
|
71
|
-
&mut self,
|
|
72
|
-
git_ignored_files: Vec<String>,
|
|
73
|
-
is_git_repo: bool,
|
|
74
|
-
) -> Result<(), napi::Error> {
|
|
75
|
-
// 1. compute the merkle tree
|
|
76
|
-
// 2. update the backend
|
|
77
|
-
// 3. sync with the remote
|
|
78
|
-
info!("Merkle tree compute started!");
|
|
79
|
-
info!("Root directory: {:?}", self.absolute_root_directory);
|
|
80
|
-
unsafe {
|
|
81
|
-
self
|
|
82
|
-
.compute_merkle_tree(git_ignored_files, is_git_repo)
|
|
83
|
-
.await?;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
Ok(())
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
pub async unsafe fn interrupt(&mut self) -> Result<(), napi::Error> {
|
|
90
|
-
unimplemented!("Interrupt is not implemented yet");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
#[napi]
|
|
94
|
-
pub async unsafe fn compute_merkle_tree(
|
|
95
|
-
&mut self,
|
|
96
|
-
git_ignored_files: Vec<String>,
|
|
97
|
-
is_git_repo: bool,
|
|
98
|
-
) -> Result<(), napi::Error> {
|
|
99
|
-
// make the git ignored files into a hash set
|
|
100
|
-
let git_ignored_set = HashSet::from_iter(git_ignored_files.into_iter());
|
|
101
|
-
|
|
102
|
-
info!("Git ignored set: {:?}", git_ignored_set);
|
|
103
|
-
|
|
104
|
-
let t = MerkleTree::construct_merkle_tree(
|
|
105
|
-
self.absolute_root_directory.clone(),
|
|
106
|
-
git_ignored_set,
|
|
107
|
-
is_git_repo,
|
|
108
|
-
)
|
|
109
|
-
.await;
|
|
110
|
-
|
|
111
|
-
match t {
|
|
112
|
-
Ok(tree) => {
|
|
113
|
-
self.tree = tree;
|
|
114
|
-
Ok(())
|
|
115
|
-
}
|
|
116
|
-
Err(e) => Err(napi::Error::new(
|
|
117
|
-
napi::Status::Unknown,
|
|
118
|
-
format!("Error in compute_merkle_tree: {:?}", e),
|
|
119
|
-
)),
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
#[napi]
|
|
124
|
-
pub async unsafe fn update_file(&mut self, file_path: String) {
|
|
125
|
-
let _ = self.tree.update_file(file_path).await;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
#[napi]
|
|
129
|
-
pub async unsafe fn delete_file(&mut self, file_path: String) {
|
|
130
|
-
let _r = self.tree.delete_file(file_path);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
#[napi]
|
|
134
|
-
pub async fn get_subtree_hash(
|
|
135
|
-
&self,
|
|
136
|
-
relative_path: String,
|
|
137
|
-
) -> Result<String, napi::Error> {
|
|
138
|
-
let relative_path_without_leading_slash = match relative_path
|
|
139
|
-
.strip_prefix('.')
|
|
140
|
-
{
|
|
141
|
-
Some(path) => path.strip_prefix(std::path::MAIN_SEPARATOR).unwrap_or(""),
|
|
142
|
-
None => relative_path.as_str(),
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
let absolute_path = if !relative_path_without_leading_slash.is_empty() {
|
|
146
|
-
std::path::Path::new(&self.absolute_root_directory)
|
|
147
|
-
.join(relative_path_without_leading_slash)
|
|
148
|
-
} else {
|
|
149
|
-
std::path::Path::new(&self.absolute_root_directory).to_path_buf()
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
let absolute_path_string = match absolute_path.to_str() {
|
|
153
|
-
Some(path) => path.to_string(),
|
|
154
|
-
None => {
|
|
155
|
-
return Err(napi::Error::new(
|
|
156
|
-
napi::Status::Unknown,
|
|
157
|
-
format!("some string error"),
|
|
158
|
-
))
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
let hash = self
|
|
163
|
-
.tree
|
|
164
|
-
.get_subtree_hash(absolute_path_string.as_str())
|
|
165
|
-
.await;
|
|
166
|
-
|
|
167
|
-
match hash {
|
|
168
|
-
Ok(hash) => Ok(hash),
|
|
169
|
-
Err(e) => Err(napi::Error::new(
|
|
170
|
-
napi::Status::Unknown,
|
|
171
|
-
format!("Error in get_subtree_hash. \nRelative path: {:?}, \nAbsolute path: {:?}, \nRoot directory: {:?}\nError: {:?}", &relative_path, absolute_path, self.absolute_root_directory, e)
|
|
172
|
-
)),
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
#[napi]
|
|
177
|
-
pub async fn get_num_embeddable_files(&self) -> Result<i32, napi::Error> {
|
|
178
|
-
let num = self.tree.get_num_embeddable_files().await;
|
|
179
|
-
|
|
180
|
-
match num {
|
|
181
|
-
Ok(num) => Ok(num),
|
|
182
|
-
Err(e) => Err(napi::Error::new(
|
|
183
|
-
napi::Status::Unknown,
|
|
184
|
-
format!("Error in get_num_embeddable_files: {:?}", e),
|
|
185
|
-
)),
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
pub async fn get_num_embeddable_files_in_subtree(
|
|
190
|
-
&self,
|
|
191
|
-
relative_path: String,
|
|
192
|
-
) -> Result<i32, napi::Error> {
|
|
193
|
-
let absolute_path = std::path::Path::new(&self.absolute_root_directory)
|
|
194
|
-
.join(relative_path)
|
|
195
|
-
.canonicalize()?;
|
|
196
|
-
|
|
197
|
-
let num = self
|
|
198
|
-
.tree
|
|
199
|
-
.get_num_embeddable_files_in_subtree(absolute_path)
|
|
200
|
-
.await;
|
|
201
|
-
|
|
202
|
-
match num {
|
|
203
|
-
Ok(num) => Ok(num),
|
|
204
|
-
Err(e) => Err(napi::Error::new(
|
|
205
|
-
napi::Status::Unknown,
|
|
206
|
-
format!("Error in get_num_embeddable_files_in_subtree: {:?}", e),
|
|
207
|
-
)),
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
#[napi]
|
|
212
|
-
pub async fn get_all_files(&self) -> Result<Vec<String>, napi::Error> {
|
|
213
|
-
let files = self.tree.get_all_files().await;
|
|
214
|
-
|
|
215
|
-
match files {
|
|
216
|
-
Ok(files) => Ok(files),
|
|
217
|
-
Err(e) => Err(napi::Error::new(
|
|
218
|
-
napi::Status::Unknown,
|
|
219
|
-
format!("Error in get_all_files: {:?}", e),
|
|
220
|
-
)),
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
#[napi]
|
|
225
|
-
pub async fn get_all_dir_files_to_embed(
|
|
226
|
-
&self,
|
|
227
|
-
absolute_file_path: String,
|
|
228
|
-
) -> Result<Vec<String>, napi::Error> {
|
|
229
|
-
// let absolute_path = absolute_file_path.to_lowercase();
|
|
230
|
-
// let absolute_path_str = absolute_path.as_str();
|
|
231
|
-
|
|
232
|
-
let files = self
|
|
233
|
-
.tree
|
|
234
|
-
.get_all_dir_files_to_embed(absolute_file_path.as_str())
|
|
235
|
-
.await;
|
|
236
|
-
|
|
237
|
-
match files {
|
|
238
|
-
Ok(files) => Ok(files),
|
|
239
|
-
Err(e) => Err(napi::Error::new(
|
|
240
|
-
napi::Status::Unknown,
|
|
241
|
-
format!("Error in get_all_dir_files_to_embed: {:?}", e),
|
|
242
|
-
)),
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
#[napi]
|
|
247
|
-
pub async unsafe fn get_next_file_to_embed(
|
|
248
|
-
&mut self,
|
|
249
|
-
) -> Result<Vec<String>, napi::Error> {
|
|
250
|
-
let n = self.tree.get_next_file_to_embed().await;
|
|
251
|
-
|
|
252
|
-
match n {
|
|
253
|
-
Ok((file, path)) => {
|
|
254
|
-
// now our job is to put the filename as the first element of the path.
|
|
255
|
-
|
|
256
|
-
// TODO(sualeh): we should assert that the path is ascending up to the path.
|
|
257
|
-
|
|
258
|
-
let ret = vec![file];
|
|
259
|
-
let ret = ret.into_iter().chain(path.into_iter()).collect::<Vec<_>>();
|
|
260
|
-
Ok(ret)
|
|
261
|
-
}
|
|
262
|
-
Err(e) => Err(napi::Error::new(
|
|
263
|
-
napi::Status::Unknown,
|
|
264
|
-
format!("Error in get_next_file_to_embed: {:?}", e),
|
|
265
|
-
)),
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// FIXME(sualeh): get_spline
|
|
270
|
-
#[napi]
|
|
271
|
-
pub async fn get_spline(
|
|
272
|
-
&self,
|
|
273
|
-
absolute_file_path: String,
|
|
274
|
-
) -> Result<Vec<String>, napi::Error> {
|
|
275
|
-
// let absolute_path = absolute_file_path.to_lowercase();
|
|
276
|
-
// let absolute_path_str = absolute_path.as_str();
|
|
277
|
-
let spline = self.tree.get_spline(absolute_file_path.as_str()).await;
|
|
278
|
-
|
|
279
|
-
match spline {
|
|
280
|
-
Ok(spline) => Ok(spline),
|
|
281
|
-
Err(e) => Err(napi::Error::new(
|
|
282
|
-
napi::Status::Unknown,
|
|
283
|
-
format!("Error in get_spline: {:?}", e),
|
|
284
|
-
)),
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
#[napi]
|
|
289
|
-
pub async fn get_hashes_for_files(
|
|
290
|
-
&self,
|
|
291
|
-
files: Vec<String>,
|
|
292
|
-
) -> Result<Vec<String>, napi::Error> {
|
|
293
|
-
let hashes = self.tree.get_hashes_for_files(files).await;
|
|
294
|
-
|
|
295
|
-
match hashes {
|
|
296
|
-
Ok(hashes) => Ok(hashes),
|
|
297
|
-
Err(e) => Err(napi::Error::new(
|
|
298
|
-
napi::Status::Unknown,
|
|
299
|
-
format!("Error in get_hashes_for_files: {:?}", e),
|
|
300
|
-
)),
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
#[napi]
|
|
305
|
-
pub fn update_root_directory(&mut self, root_directory: String) {
|
|
306
|
-
self.absolute_root_directory = root_directory;
|
|
307
|
-
}
|
|
308
|
-
}
|
package/src/lib2.rs
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
#![deny(clippy::all)]
|
|
2
|
-
pub mod file_utils;
|
|
3
|
-
pub mod git_utils;
|
|
4
|
-
pub mod merkle_tree;
|
|
5
|
-
|
|
6
|
-
// #[path = "proto/aiserver.v1.rs"]
|
|
7
|
-
// pub mod aiserver;
|
|
8
|
-
|
|
9
|
-
// use aiserver::repository_service_client::RepositoryServiceClient;
|
|
10
|
-
// use aiserver::{FastRepoInitHandshakeRequest, GetNumFilesToSendRequest, GetNumFilesToSendResponse};
|
|
11
|
-
use merkle_tree::{MerkleTree, LocalConstruction};
|
|
12
|
-
|
|
13
|
-
// use tonic::metadata::MetadataValue;
|
|
14
|
-
// use tonic::transport::Channel;
|
|
15
|
-
// use tonic::Request;
|
|
16
|
-
// use aiserver::v1::repository_client::RepositoryClient;
|
|
17
|
-
|
|
18
|
-
#[macro_use]
|
|
19
|
-
extern crate napi_derive;
|
|
20
|
-
|
|
21
|
-
// pub type RepositoryClient = RepositoryServiceClient<
|
|
22
|
-
// tonic::service::interceptor::InterceptedService<Channel, AsphrAuthInterceptor>,
|
|
23
|
-
// >;
|
|
24
|
-
|
|
25
|
-
#[napi]
|
|
26
|
-
pub struct MerkleClient {
|
|
27
|
-
tree: MerkleTree,
|
|
28
|
-
root_directory: String,
|
|
29
|
-
// intercepter: AsphrAuthInterceptor,
|
|
30
|
-
// backend_url: String,
|
|
31
|
-
// repository_info: RepositoryInfo,
|
|
32
|
-
// repo_client: Option<RepositoryClient>,
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
#[napi]
|
|
37
|
-
impl MerkleClient {
|
|
38
|
-
#[napi(constructor)]
|
|
39
|
-
pub fn new(
|
|
40
|
-
root_directory: String,
|
|
41
|
-
// bearer_token: String,
|
|
42
|
-
// backend_url: String,
|
|
43
|
-
// repository_info: RepositoryInfo
|
|
44
|
-
) -> MerkleClient {
|
|
45
|
-
MerkleClient {
|
|
46
|
-
tree: MerkleTree::empty_tree(),
|
|
47
|
-
root_directory,
|
|
48
|
-
// intercepter: AsphrAuthInterceptor::new(bearer_token),
|
|
49
|
-
// backend_url,
|
|
50
|
-
// repository_info,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
#[napi]
|
|
55
|
-
pub async unsafe fn init(&mut self) -> Result<(), napi::Error> {
|
|
56
|
-
// 1. compute the merkle tree
|
|
57
|
-
// 2. update the backend
|
|
58
|
-
// 3. sync with the remote
|
|
59
|
-
self.compute_merkle_tree().await;
|
|
60
|
-
let res = self.sync_with_remote().await;
|
|
61
|
-
|
|
62
|
-
if let Err(e) = res {
|
|
63
|
-
println!("Error: {:?}", e);
|
|
64
|
-
return Err(napi::Error::new(
|
|
65
|
-
napi::Status::Unknown,
|
|
66
|
-
"Error in sync_with_remote",
|
|
67
|
-
));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
Ok(())
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// #[napi]
|
|
74
|
-
pub async unsafe fn interrupt(&mut self) -> Result<(), napi::Error> {
|
|
75
|
-
unimplemented!("Interrupt is not implemented yet");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// pub async fn update_backend(&self) -> Result<RepositoryClient, napi::Error> {
|
|
79
|
-
// let channel = match Channel::from_shared(self.backend_url.clone()) {
|
|
80
|
-
// Ok(channel) => {
|
|
81
|
-
// let connection = match channel.connect().await {
|
|
82
|
-
// Ok(connection) => connection,
|
|
83
|
-
// Err(_) => {
|
|
84
|
-
// return Err(napi::Error::new(
|
|
85
|
-
// napi::Status::Unknown,
|
|
86
|
-
// "Invalid backend URL",
|
|
87
|
-
// ))
|
|
88
|
-
// }
|
|
89
|
-
// };
|
|
90
|
-
|
|
91
|
-
// connection
|
|
92
|
-
// }
|
|
93
|
-
// Err(_) => {
|
|
94
|
-
// return Err(napi::Error::new(
|
|
95
|
-
// napi::Status::Unknown,
|
|
96
|
-
// "Invalid backend URL",
|
|
97
|
-
// ))
|
|
98
|
-
// }
|
|
99
|
-
// };
|
|
100
|
-
|
|
101
|
-
// let repo_client = RepositoryServiceClient::with_interceptor(channel, self.intercepter.clone());
|
|
102
|
-
|
|
103
|
-
// Ok(repo_client)
|
|
104
|
-
// }
|
|
105
|
-
|
|
106
|
-
// #[napi]
|
|
107
|
-
pub async fn sync_with_remote(&self) -> Result<(), napi::Error> {
|
|
108
|
-
// BLOCKER:
|
|
109
|
-
// 1. need to get the repository info nicely from javascript.
|
|
110
|
-
// 2. need to handle the napi conversions.
|
|
111
|
-
// let client: Result<RepositoryClient, napi::Error> = self.update_backend().await;
|
|
112
|
-
|
|
113
|
-
// if let Err(e) = client {
|
|
114
|
-
// return Err(e);
|
|
115
|
-
// }
|
|
116
|
-
// let mut client = client.unwrap();
|
|
117
|
-
|
|
118
|
-
// 1. make sure your tree is upto date.
|
|
119
|
-
// just make sure that you did an update recently and that you havent left too many updates to be buffered up.
|
|
120
|
-
|
|
121
|
-
// 2. sync it carefully.
|
|
122
|
-
// let repo_init_handshake_req = tonic::Request::new(FastRepoInitHandshakeRequest {
|
|
123
|
-
// repository:
|
|
124
|
-
// merkle_tree: self.tree.clone(),
|
|
125
|
-
// });
|
|
126
|
-
// client.fast_repo_init_handshake()
|
|
127
|
-
|
|
128
|
-
// 2.5 if the hash is the same, you are happy and you just leave.
|
|
129
|
-
|
|
130
|
-
// 3. start the diffing process if everything is ok.
|
|
131
|
-
// let different_files = self.tree.sync_with_remote(client).await;
|
|
132
|
-
// let num_files_to_send = different_files.len();
|
|
133
|
-
|
|
134
|
-
// 4. send those files to the server!
|
|
135
|
-
Ok(())
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
#[napi]
|
|
139
|
-
pub async unsafe fn compute_merkle_tree(&mut self) {
|
|
140
|
-
self.tree = MerkleTree::construct_merkle_tree(self.root_directory.clone()).await;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
#[napi]
|
|
144
|
-
pub async unsafe fn update_file(&mut self, file_path: String) {
|
|
145
|
-
let _ = self.tree.update_file(file_path).await;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
#[napi]
|
|
149
|
-
pub async unsafe fn delete_file(&mut self, file_path: String) {
|
|
150
|
-
let _r = self.tree.delete_file(file_path);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// #[napi]
|
|
154
|
-
pub fn update_root_directory(&mut self, root_directory: String) {
|
|
155
|
-
self.root_directory = root_directory;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// TODO
|
|
159
|
-
// pub fn update_repository_info(&mut self, repository_info: RepositoryInfo) {
|
|
160
|
-
// self.repository_info = repository_info;
|
|
161
|
-
// }
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
#[napi(object)]
|
|
165
|
-
#[derive(Clone, Debug)]
|
|
166
|
-
pub struct RepositoryInfo {
|
|
167
|
-
pub relative_workspace_path: String,
|
|
168
|
-
pub remote_urls: String,
|
|
169
|
-
pub remote_names: String,
|
|
170
|
-
pub repo_name: String,
|
|
171
|
-
pub repo_owner: String,
|
|
172
|
-
pub is_tracked: bool,
|
|
173
|
-
pub is_local: bool,
|
|
174
|
-
pub num_files: Option<i32>
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
// use std::convert::TryFrom;
|
|
179
|
-
// A simple implementation of an interceptor that adds a bearer token to the request
|
|
180
|
-
// #[derive(Clone)]
|
|
181
|
-
// pub struct AsphrAuthInterceptor {
|
|
182
|
-
// auth_token: String,
|
|
183
|
-
// full_auth_string: String,
|
|
184
|
-
// }
|
|
185
|
-
|
|
186
|
-
// impl tonic::service::Interceptor for AsphrAuthInterceptor {
|
|
187
|
-
// fn call(&mut self, mut request: tonic::Request<()>) -> Result<tonic::Request<()>, tonic::Status> {
|
|
188
|
-
// request.metadata_mut().insert(
|
|
189
|
-
// "authorization",
|
|
190
|
-
// MetadataValue::try_from(&self.full_auth_string).unwrap(),
|
|
191
|
-
// );
|
|
192
|
-
// Ok(request)
|
|
193
|
-
// }
|
|
194
|
-
// }
|
|
195
|
-
|
|
196
|
-
// impl AsphrAuthInterceptor {
|
|
197
|
-
// pub fn new(auth_token: String) -> AsphrAuthInterceptor {
|
|
198
|
-
// AsphrAuthInterceptor {
|
|
199
|
-
// auth_token: auth_token.clone(),
|
|
200
|
-
// full_auth_string: format!("Bearer {}", auth_token),
|
|
201
|
-
// }
|
|
202
|
-
// }
|
|
203
|
-
|
|
204
|
-
// pub fn get_auth_token(&self) -> String {
|
|
205
|
-
// self.auth_token.clone()
|
|
206
|
-
// }
|
|
207
|
-
|
|
208
|
-
// pub fn update_auth_token(&mut self, new_token: String) {
|
|
209
|
-
// self.auth_token = new_token;
|
|
210
|
-
// self.full_auth_string = format!("Bearer {}", self.auth_token);
|
|
211
|
-
// }
|
|
212
|
-
// }
|