Skip to content

Commit

Permalink
Merge pull request #146 from dfabulich/cloud-list-files
Browse files Browse the repository at this point in the history
cloud: add list_files method
  • Loading branch information
ceifa authored Jun 3, 2024
2 parents 18bdbf6 + f159b67 commit 0d1d418
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export namespace cloud {
export function writeFile(name: string, content: string): boolean
export function deleteFile(name: string): boolean
export function fileExists(name: string): boolean
export function listFiles(): Array<FileInfo>
export class FileInfo {
name: string
size: bigint
}
}
export namespace input {
export interface AnalogActionVector {
Expand Down
22 changes: 21 additions & 1 deletion src/api/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ use napi_derive::napi;

#[napi]
pub mod cloud {
use napi::bindgen_prelude::Error;
use napi::bindgen_prelude::{BigInt, Error};
use std::io::Read;
use std::io::Write;

#[napi]
pub struct FileInfo {
pub name: String,
pub size: BigInt,
}

#[napi]
pub fn is_enabled_for_account() -> bool {
let client = crate::client::get_client();
Expand Down Expand Up @@ -58,4 +64,18 @@ pub mod cloud {

file.exists()
}

#[napi]
pub fn list_files() -> Vec<FileInfo> {
let client = crate::client::get_client();
client
.remote_storage()
.files()
.into_iter()
.map(|identity| FileInfo {
name: identity.name,
size: BigInt::from(identity.size),
})
.collect()
}
}

0 comments on commit 0d1d418

Please sign in to comment.