41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
// RFS Client: Auth + Upload + Download example
|
|
// Prereqs:
|
|
// - RFS server reachable at RFS_BASE_URL
|
|
// - 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");
|
|
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"; }
|
|
|
|
// Create client
|
|
let ok = rfs_create_client(BASE_URL, USER, PASS, TIMEOUT);
|
|
if !ok { throw "Failed to create RFS client"; }
|
|
|
|
// Optional health check
|
|
let health = rfs_health_check();
|
|
print(`RFS health: ${health}`);
|
|
|
|
// Authenticate (required for some operations)
|
|
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);
|
|
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"; }
|
|
|
|
print(`Downloaded to: ${out_path}`);
|
|
|
|
true
|