Skip to content

Commit

Permalink
fix: rename cache to aggregator, avoid resetting URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpcsmith committed Jun 12, 2024
1 parent 860dd1e commit 580e22d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
6 changes: 4 additions & 2 deletions examples/javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## Prerequisites

- Set up Sui and Walrus as described
- Set up Sui and Walrus as described in the
[documentation](https://mystenlabs.github.io/walrus-docs/usage/setup.html).
- Run the client in [daemon mode](https://mystenlabs.github.io/walrus-docs/usage/web-api.html).

## Index of examples

- `blob_upload_download_webapi.html` shows how to store a blob using javascript and to embed the
blob accessible from the Walrus cache in an HTML document.
blob accessible from a Walrus aggregator in an HTML document.
28 changes: 18 additions & 10 deletions examples/javascript/blob_upload_download_webapi.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

<body>
<script>
// TODO(jsmith): Change to testnet
const SUI_NETWORK = "testnet";
const SUI_VIEW_TX_URL = `https://suiscan.xyz/${SUI_NETWORK}/tx`;
const SUI_VIEW_OBJECT_URL = `https://suiscan.xyz/${SUI_NETWORK}/object`;
Expand All @@ -44,7 +43,7 @@
console.error(error);
alert(
"An error occurred while uploading. Check the browser console and ensure that \
the cache and publisher URLs are correct."
the aggregator and publisher URLs are correct."
);
enableForm(true);
});
Expand Down Expand Up @@ -110,8 +109,8 @@
}

// The URL used to download and view the blob.
const baseCacheUrl = document.getElementById("cache-url-input").value;
const blobUrl = `${baseCacheUrl}/v1/${info.blobId}`;
const baseAggregatorUrl = document.getElementById("aggregator-url-input").value;
const blobUrl = `${baseAggregatorUrl}/v1/${info.blobId}`;

// The URL for viewing the event or object on chain
const suiUrl = `${info.suiBaseUrl}/${info.suiRef}`
Expand All @@ -120,8 +119,8 @@
// Create the HTML entry in the page for the uploaded blob.
//
// For the associated icon, we use the `<object/>` HTML element, as it allows specifying
// the media type. The walrus cache returns blobs as `application/octect-stream`, so it
// is necessary to specify the content type to the browser in the `object` element.
// the media type. The walrus aggregator returns blobs as `application/octect-stream`,
// so it's necessary to specify the content type to the browser in the `object` element.
document.getElementById("uploaded-blobs").insertAdjacentHTML(
"afterBegin",
`<article class="row border rounded-2 shadow-sm mb-3">
Expand All @@ -148,10 +147,19 @@
*/
function enableForm(isEnabled) {
if (isEnabled) {
// Copy the urls, so that they are not reset.
const publisherUrl = document.getElementById("publisher-url-input").value;
const aggregatorUrl = document.getElementById("aggregator-url-input").value;
// Reset the form
document.getElementById("upload-form").reset()
document.querySelector("#upload-form fieldset").removeAttribute("disabled");
// Revert the URLs to their previous values
document.getElementById("publisher-url-input").value = publisherUrl;
document.getElementById("aggregator-url-input").value = aggregatorUrl;
// Disable the progress indication
document.getElementById("submit-spinner").style.visibility = "collapse";
document.getElementById("submit-text").textContent = "Upload";
// Re-enable the form
document.querySelector("#upload-form fieldset").removeAttribute("disabled");
} else {
document.querySelector("#upload-form fieldset").setAttribute("disabled", "");
document.getElementById("submit-spinner").style.visibility = "visible";
Expand Down Expand Up @@ -200,10 +208,10 @@ <h2>Blob Upload</h2>
</div>

<div class="col-lg-6">
<label for="cache-url-input" class="form-label" >
Walrus cache URL
<label for="aggregator-url-input" class="form-label" >
Walrus aggregator URL
</label>
<input id="cache-url-input" type="url" class="form-control"
<input id="aggregator-url-input" type="url" class="form-control"
placeholder="http://127.0.0.1:31415" value="http://127.0.0.1:31415"
required />
</div>
Expand Down

0 comments on commit 580e22d

Please sign in to comment.