Skip to content

Conversation

@jonlunsford
Copy link

What's The Problem?

In the Filesystem module:

defp build_url(_fs, endpoint, params) do
  query = URI.encode_query(params)
  "#{endpoint}?#{query}"
end

Builds URLs like /fs/write?... without the sprite name.

The API docs specify:

 PUT /v1/sprites/{name}/fs/write

What Was Done?

A Sprites.Sprite.path/3 function was added so any caller that can access a %Sprite{}, can generate properly scoped API paths, like:

/v1/sprites/my-sprite-name/fs/write

Before:

iex(4)> entries = Sprites.Filesystem.ls!(fs, "/home/sprite")
** (Sprites.Error.FilesystemError) File or directory not found: /home/sprite
    (sprites 0.1.0) lib/sprites/filesystem.ex:199: Sprites.Filesystem.ls!/2

After:

entries = Sprites.Filesystem.ls!(fs, "/home/sprite")
=> [
  ...
  %{
    "isDir" => false,
    "modTime" => "2026-01-14T00:20:01Z",
    "mode" => "644",
    "name" => ".tcshrc",
    "path" => "/home/sprite/.tcshrc",
    "size" => 383,
    "type" => "file"
  },
  %{
    "isDir" => false,
    "modTime" => "2026-01-14T00:20:01Z",
    "mode" => "644",
    "name" => ".zshrc",
    "path" => "/home/sprite/.zshrc",
    "size" => 1159,
    "type" => "file"
  }
]

…#1)

## What's The Problem?

In the Filesystem module:

```elixir
defp build_url(_fs, endpoint, params) do
  query = URI.encode_query(params)
  "#{endpoint}?#{query}"
end
```

Builds URLs like `/fs/write?`... without the sprite name.

The [API docs](https://docs.sprites.dev/api/v001-rc30/filesystem/#write-file) specify:
```
 PUT /v1/sprites/{name}/fs/write
```

## What Was Done?

A `Sprites.Sprite.path/3` function was added so any caller that can access a `%Sprite{}`, can generate properly scoped API paths, like: 

```
/v1/sprites/my-sprite-name/fs/write
```

**Before:**

```elixir
iex(4)> entries = Sprites.Filesystem.ls!(fs, "/home/sprite")
** (Sprites.Error.FilesystemError) File or directory not found: /home/sprite
    (sprites 0.1.0) lib/sprites/filesystem.ex:199: Sprites.Filesystem.ls!/2
```

**After:**

```elixir
entries = Sprites.Filesystem.ls!(fs, "/home/sprite")
=> [
  ...
  %{
    "isDir" => false,
    "modTime" => "2026-01-14T00:20:01Z",
    "mode" => "644",
    "name" => ".tcshrc",
    "path" => "/home/sprite/.tcshrc",
    "size" => 383,
    "type" => "file"
  },
  %{
    "isDir" => false,
    "modTime" => "2026-01-14T00:20:01Z",
    "mode" => "644",
    "name" => ".zshrc",
    "path" => "/home/sprite/.zshrc",
    "size" => 1159,
    "type" => "file"
  }
]
```
def path(%__MODULE__{name: name}, endpoint, params \\ []) do
query = if params == [], do: "", else: "?#{URI.encode_query(params)}"
"/v1/sprites/#{URI.encode(name)}#{endpoint}#{query}"
end
Copy link
Author

@jonlunsford jonlunsford Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally open to a better names, Sprites.Sprite.path was just my first thought :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant