Object Storage
Retrieve raw scripts

Retrieve a Raw Script

To retrieve the raw script content, you need to perform a GET request to the following URL: https://rscripts.net/raw/<key>

Replace <key> with the actual file name of the script you want to retrieve.

Obtaining the File Name

The file name can be obtained from the download property of the script object returned by the /api/scripts or /api/script/retrieve endpoint. This property contains the key of the S3 object storage where the raw script is stored.

For example, if the script object looks like this:

{
  "_id": "script_id",
  "title": "Script Title",
  "description": "Script Description",
  "download": "hello-world.txt",
  // ...
}

The file name to use in the URL would be hello-world.txt.

Response

If the script exists and you have access to retrieve it, the response will be the raw script content.

However, if the script no longer exists or you don't have access to retrieve it, you may receive an "Access Denied" XML response from the S3 object storage.

Example Usage

const scriptObject = {
  // ...
  "download": "hello-world.txt"
};
 
const scriptUrl = `https://rscripts.net/raw/${scriptObject.download}`;
 
fetch(scriptUrl)
  .then(response => {
    if (response.ok) {
      return response.text();
    } else {
      throw new Error('Access Denied');
    }
  })
  .then(scriptContent => {
    console.log('Raw script content:', scriptContent);
  })
  .catch(error => {
    console.error('Error retrieving script:', error);
  });

In this example, the scriptObject contains the download property with the file name. The URL is constructed using this file name, and a GET request is made to retrieve the raw script content. If the response is successful, the raw script content is logged to the console. If an error occurs (e.g., "Access Denied"), an error message is logged instead.