@resolute/rio
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

Locally

  1. Source may be a URL or a local file
    1. If a URL, perform HEAD request and parse etag header. Generate the source hash as {xxHash64(URL)}-{etag}.
    2. If a local file, read contents of file and generate source hash as {xxHash64(file contents)}.
    3. Note: we must create a lock to prevent re-reading or re-requesting the same resource over and over. This would act as an ephemeral cache of the source hash. We must figure out how to purge this cache during periods of long execution contexts—like a “watch” scenario.
  2. Generate an {optionsHash} by normalizing the options (mime type, width, height).
    1. Options must be normalized so that swapping the order of width and height does not generate a different hash.
    2. If {sourceHash}-{optionsHash} exists in local FS cache, return it.
  3. GET rio-gcf passing the {sourceHash} and the options, and optionally a locally existing If-None-Match: "{variantHash}" —doesn’t make sense: if we’re caching locally, then we do not need to check with the server. If the response is:
    1. 404
      1. The rio-gcf server does not have the source.
      2. Proceed to upload POST source where the request body is either 1) the file contents or the 2) URL.
      3. Note: we must also create a lock for source uploading to prevent overloading rio-gcf with may upload request.
    2. 200
      1. The rio-gcf server has the source and is either 1) generating the variant based on the options, or 2) found the asset in its GCS cache and is returning that.
    3. 304
      1. The rio-gcf server has the source, and the ETAG ({variantHash}) passed in If-None-Match request header is the correct fresh version.

Server-side

GET Request Headers

  • If-None-Match: "{variantHash}"
  • Accept: {mime type} Request URL Search Params
  • sourceHash
  • width (optional)
  • height (optional)
  1. Generate an {optionsHash} by normalizing the options (mime type, width, height).

Possible States

  1. Variant locally on filesystem by {sourceHash}-{optionsHash}
    1. exists
    2. does not exist
  2. Source in GCS
    1. exists
    2. does not exist
  3. Variant in GCS
    1. exists
    2. does not exist

If the Variant ({sourceHash}-{optionsHash}) exists locally, simply return it along with its meta ({sourceHash}-{optionsHash}.meta).

If the Source does not exist in GCS, upload (POST) it to GCF/GCS.

Package Sidebar

Install

npm i @resolute/rio

Weekly Downloads

0

Version

0.1.0

License

ISC

Unpacked Size

35.8 kB

Total Files

3

Last publish

Collaborators

  • adamchal