Skip to content

Commit

Permalink
fix(webserver): /repositories/resolve api should contains its file ki…
Browse files Browse the repository at this point in the history
…nd (dir / file) when resolving a directory (#1111)
  • Loading branch information
wsxiaoys authored Dec 24, 2023
1 parent 31a80b4 commit d1526cf
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions ee/tabby-webserver/src/repositories/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ impl ResolveParams {

#[derive(Serialize)]
struct ListDir {
entries: Vec<String>,
entries: Vec<DirEntry>,
}

#[derive(Serialize)]
enum DirEntryKind {
File,
Dir,
}

#[derive(Serialize)]
struct DirEntry {
kind: DirEntryKind,
basename: String,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -113,16 +125,28 @@ fn load_meta() -> HashMap<DatasetKey, Meta> {
/// Resolve a directory
pub async fn resolve_dir(root: PathBuf, full_path: PathBuf) -> Result<Response> {
let mut read_dir = tokio::fs::read_dir(full_path).await?;
let mut entries = vec![];
let mut entries: Vec<DirEntry> = vec![];

while let Some(entry) = read_dir.next_entry().await? {
let path = entry
let basename = entry
.path()
.strip_prefix(&root)?
.to_str()
.unwrap()
.to_string();
entries.push(path);

let meta = entry.metadata().await?;

let kind = if meta.is_dir() {
DirEntryKind::Dir
} else if meta.is_file() {
DirEntryKind::File
} else {
// Skip others.
continue;
};

entries.push(DirEntry { kind, basename });
}

let body = Json(ListDir { entries }).into_response();
Expand Down

0 comments on commit d1526cf

Please sign in to comment.