Script
Syntax & Interface

Syntax and Interface

Basic Methods

  • $script.name: Script name
  • $script.type: Script type, such as request, response, and tile
  • $script.startTime: The time when the script starts running
  • $environment["stash-build"]: Stash Build number
  • $environment["stash-version"]: Stash version number
  • $environment.language: Stash runtime language
  • $environment.system: Stash runtime system (iOS / macOS)
  • $argument: Runtime arguments
  • $done(value): End script execution and release resources
  • $notification.post(title, subtitle, body): Send iOS notification
  • console.log(value): Output log, script log will be output to a separate file
  • setTimeout(callback, delay): Delay execution of callback function

$done(value)

⚠️

For all scripts, $done(value) method must be called at the end to release resources.

Persistent Storage

  • $persistentStore.write(value, key): Write to persistent storage
  • $persistentStore.read(key): Read from persistent storage

HTTP Client

  • $httpClient.get(url<String>, callback<Function>)
  • $httpClient.get(request<Object>, callback<Function>)

Similarly, there are:

  • $httpClient.post()
  • $httpClient.put()
  • $httpClient.delete()
  • $httpClient.head()
  • $httpClient.options()
  • $httpClient.patch()

The request timeout is 5 seconds, and you can specify the proxy used for the request by setting X-Stash-Selected-Proxy, or enable binary mode by setting binary-mode, for example:

$httpClient.get('http://httpbin.org/get', (error, response, data) => {
  if (error) {
    console.log(error)
  } else {
    console.log(data)
  }
})
 
const yourProxyName = 'a fancy name with 😄'
 
$httpClient.post(
  {
    url: 'http://httpbin.org/post',
    headers: {
      'X-Header-Key': 'headerValue',
      'X-Stash-Selected-Proxy': encodeURIComponent(yourProxyName),
    },
    body: '{}', // can be object or string
    'binary-mode': true,
  },
  (error, response, data) => {
    if (error) {
      console.log(error)
    } else {
      console.log(data)
    }
  }
)