Appearance
Storage â
All files in Uva are stored using a simple API:
js
world.storage.set(arrayBuffer) -> Promise {status: 'okay', key: 'string'}js
world.storage.get(key) -> Promise ArrayBuffer | nullEach file you upload returns a deterministic hash key, which you can then use for referencing the file. You can use this storing 3D models, audio, images, zipped assets etc.
Once a file it is uploaded, it's key and contents are permanent. If you want to store modifiable data see: Database
Examples â
Downloading a JSON object
js
const buffer = await world.storage.get("key");
const decoder = new TextDecoder();
const u8 = new Uint8Array(buffer);
const jsonData = JSON.parse(decoder.decode(u8));Storing a JSON object
js
const data = JSON.stringify({ very: "meaowy" });
const encoder = new TextEncoder();
const buffer = encoder.encode(data).buffer;
const result = await world.storage.set(buffer);
if (result.status == "okay") {
data["assetname"] = result.key;
}Uploading any file using the browser file input
js
const saveFile = async (event) => {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = async (e) => {
const arrayBuffer = e.target.result;
let result = await world.storage.set(arrayBuffer);
// the key can be used for downloading the asset later
// key is a unique ID, based on hash of the arrayBuffer
console.log(result.key);
};
reader.readAsArrayBuffer(file);
};
const importFile = document.createElement("input");
importFile.type = "file";
importFile.setAttribute("type", "file");
importFile.addEventListener("change", saveFile, false);
this.click = () => {
importFile.click();
};Internally this storage is used for project assets, and is used for things like:
js
const video = Video("assetVideoName.mp4");
const avatar = Model("Rindo.vrm");These files are cached locally using IndexedDB.
Your files â
You can export your app and all it's files, for self hosting info see local deployment.
For info on storage authentication see authentication.
Distributed nodes â
Uva runs a distributed network of servers across the U.S., Tokyo, Australia, Europe, New Zealand and Singapore. This means latency is extremely low and your apps load quickly đ¤
If you want to run a trusted node and integrate with the network send a DM. The backend is very simple and can be run on a cheap VPS or on your own Linux computer:
js
git clone https://github.com/zonkypop/uva
./install.sh
node init.js
./run.sh