Skip to content

Instantly share code, notes, and snippets.

@lbogdan
Created October 24, 2018 09:15
Show Gist options
  • Save lbogdan/852adae62e2af920e45e49ca64f7f90f to your computer and use it in GitHub Desktop.
Save lbogdan/852adae62e2af920e45e49ca64f7f90f to your computer and use it in GitHub Desktop.
Feature: synchronize externally modified sandbox files with the API

Feature: synchronize externally modified sandbox files with the API

Steps:

  1. the agent detects the change, sends it to the manager
  2. the manager sends the change to an authenticated API endpoint
  3. the API process the change (uploads the file if binary, updates the DB)
  4. the manager sends an external change notification to all connected clients
  5. the client refetches the sandbox contents (lazy fetching?)

Detecting the change - agent

  • use node-watch / chokidar
  • detect
    • added file / folder
    • changed file content
    • deleted file / folder
    • (renamed file / folder?)
  • exclude node_modules
  • exclude based on .gitignore
  • (maybe also exclude on .syncignore?)
  • debounce changes

API sync endpoint

  • POST /api/v1/sandboxes/${sandboxId}/msync
  • authentication?
  • data
    • sandbox id (in URL)
    • file / folder name, relative to the root of the sandbox, ex.: /src/components/Hello.vue
    • type - "file" or "folder"
    • if type is file, the file content (base64 encoded); if the file was deleted, content is null
    • (new name, in case of a rename?)

Example:

POST /api/v1/sandboxes/qv463kv6z6/msync
{
    "name": "/src/components/Hello.vue",
    "type": "file",
    "content": "<template>..."
}

Comments:

  • type can be inferred from the existence of the content field (not really, because we can't distinguish between deleting a folder and deleting a file, both would have name and content: null)
  • should we use multipart/form-data, which supports binary content, or JSON body with base64 encoded content?
  • maybe also have an operation field, with "change" or "delete" values, and not use content: null for deletes?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment