// 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 // 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 == "" { throw "Set BASE_URL in the script"; } // 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 // 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"; // 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}`); true