Skip to content

Commit

Permalink
Add support meta method on File or Blob subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Oct 4, 2023
1 parent 9da3029 commit d386704
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion assets/js/phoenix_live_view/upload_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export default class UploadEntry {
relative_path: this.file.webkitRelativePath,
size: this.file.size,
type: this.file.type,
ref: this.ref
ref: this.ref,
meta: typeof(this.file.meta) === "function" ? this.file.meta() : undefined
}
}

Expand Down
1 change: 1 addition & 0 deletions lib/phoenix_live_view/test/live_view_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@ defmodule Phoenix.LiveViewTest do
* `:size` - the byte size of the content
* `:type` - the MIME type of the file
* `:relative_path` - for simulating webkitdirectory metadata
* `:meta` - optional metadata sent by the client
## Examples
Expand Down
9 changes: 6 additions & 3 deletions lib/phoenix_live_view/upload_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ defmodule Phoenix.LiveView.UploadEntry do
client_relative_path: nil,
client_size: nil,
client_type: nil,
client_last_modified: nil
client_last_modified: nil,
client_meta: nil

@type t :: %__MODULE__{
progress: integer(),
Expand All @@ -33,7 +34,8 @@ defmodule Phoenix.LiveView.UploadEntry do
client_relative_path: String.t() | nil,
client_size: integer() | nil,
client_type: String.t() | nil,
client_last_modified: integer() | nil
client_last_modified: integer() | nil,
client_meta: map() | nil
}

@doc false
Expand Down Expand Up @@ -558,7 +560,8 @@ defmodule Phoenix.LiveView.UploadConfig do
client_relative_path: Map.get(client_entry, "relative_path"),
client_size: Map.fetch!(client_entry, "size"),
client_type: Map.fetch!(client_entry, "type"),
client_last_modified: Map.get(client_entry, "last_modified")
client_last_modified: Map.get(client_entry, "last_modified"),
client_meta: Map.get(client_entry, "meta"),
}

{:ok, entry}
Expand Down
3 changes: 2 additions & 1 deletion priv/static/phoenix_live_view.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions priv/static/phoenix_live_view.cjs.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion priv/static/phoenix_live_view.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions priv/static/phoenix_live_view.esm.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion priv/static/phoenix_live_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,8 @@ removing illegal node: "${(childNode.outerHTML || childNode.nodeValue).trim()}"
relative_path: this.file.webkitRelativePath,
size: this.file.size,
type: this.file.type,
ref: this.ref
ref: this.ref,
meta: typeof this.file.meta === "function" ? this.file.meta() : void 0
};
}
uploader(uploaders) {
Expand Down
2 changes: 1 addition & 1 deletion priv/static/phoenix_live_view.min.js

Large diffs are not rendered by default.

0 comments on commit d386704

Please sign in to comment.