fix rfsclient rhai example and update docs
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
// - Valid credentials in env: RFS_USER, RFS_PASS
|
||||
// - Run with herodo so the SAL Rhai modules are registered
|
||||
|
||||
let BASE_URL = env_get("RFS_BASE_URL");
|
||||
let USER = env_get("RFS_USER");
|
||||
let PASS = env_get("RFS_PASS");
|
||||
// NOTE: env_get not available in this runtime; hardcode or replace with your env loader
|
||||
let BASE_URL = "http://127.0.0.1:8080";
|
||||
let USER = "user";
|
||||
let PASS = "password";
|
||||
let TIMEOUT = 30; // seconds
|
||||
|
||||
if BASE_URL == null || BASE_URL == "" { throw "Set RFS_BASE_URL in your environment"; }
|
||||
if USER == null || PASS == null { throw "Set RFS_USER and RFS_PASS in your environment"; }
|
||||
if BASE_URL == "" { throw "Set BASE_URL in the script"; }
|
||||
|
||||
// Create client
|
||||
let ok = rfs_create_client(BASE_URL, USER, PASS, TIMEOUT);
|
||||
@@ -25,15 +25,16 @@ let auth_ok = rfs_authenticate();
|
||||
if !auth_ok { throw "Authentication failed"; }
|
||||
|
||||
// Upload a local file
|
||||
let local_file = "/tmp/rfs_example.txt";
|
||||
os_write_file(local_file, "hello rfs");
|
||||
let hash = rfs_upload_file(local_file);
|
||||
// Use an existing readable file to avoid needing os_write_file module
|
||||
let local_file = "/etc/hosts";
|
||||
// rfs_upload_file(file_path, chunk_size, verify)
|
||||
let hash = rfs_upload_file(local_file, 0, false);
|
||||
print(`Uploaded file hash: ${hash}`);
|
||||
|
||||
// Download it back
|
||||
let out_path = "/tmp/rfs_example_out.txt";
|
||||
let dl_ok = rfs_download_file(hash, out_path);
|
||||
if !dl_ok { throw "Download failed"; }
|
||||
// rfs_download_file(file_id, output_path, verify) returns unit and throws on error
|
||||
rfs_download_file(hash, out_path, false);
|
||||
|
||||
print(`Downloaded to: ${out_path}`);
|
||||
|
||||
|
Reference in New Issue
Block a user