forked from rauversion/rauversion-phx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
107 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
defmodule Rauversion.BlobUtils do | ||
def fallback_image(url \\ nil) do | ||
RauversionWeb.Router.Helpers.static_path( | ||
RauversionWeb.Endpoint, | ||
url || "/images/daniel-schludi-mbGxz7pt0jM-unsplash.jpg" | ||
) | ||
end | ||
|
||
def blob_url(user, kind) do | ||
kind_blob = :"#{kind}_blob" | ||
|
||
case user do | ||
nil -> | ||
Rauversion.BlobUtils.fallback_image() | ||
|
||
%{^kind_blob => nil} -> | ||
Rauversion.BlobUtils.fallback_image() | ||
|
||
%{^kind_blob => %ActiveStorage.Blob{} = blob} -> | ||
blob |> ActiveStorage.url() | ||
|
||
%{^kind_blob => %Ecto.Association.NotLoaded{}} -> | ||
user = user |> Rauversion.Repo.preload(kind_blob) | ||
|
||
apply(__MODULE__, :blob_url, [user, kind]) | ||
end | ||
end | ||
|
||
def blob_for(track, kind) do | ||
kind_blob = :"#{kind}_blob" | ||
|
||
# a = Rauversion.Accounts.get_user_by_username("michelson") |> Rauversion.Repo.preload(:avatar_blob) | ||
case track do | ||
nil -> | ||
nil | ||
|
||
%{^kind_blob => nil} -> | ||
nil | ||
|
||
%{^kind_blob => %ActiveStorage.Blob{} = blob} -> | ||
blob | ||
|
||
%{^kind_blob => %Ecto.Association.NotLoaded{}} -> | ||
track = track |> Rauversion.Repo.preload(kind_blob) | ||
apply(__MODULE__, :blob_for, [track, kind]) | ||
end | ||
end | ||
|
||
def variant_url(track, kind, options \\ %{resize_to_limit: "100x100"}) do | ||
case blob_for(track, kind) do | ||
nil -> | ||
# default url here? | ||
RauversionWeb.Router.Helpers.static_path( | ||
RauversionWeb.Endpoint, | ||
"/images/daniel-schludi-mbGxz7pt0jM-unsplash.jpg" | ||
) | ||
|
||
blob -> | ||
variant = | ||
ActiveStorage.Blob.Representable.variant(blob, options) | ||
|> ActiveStorage.Variant.processed() | ||
|
||
ActiveStorage.storage_redirect_url(variant, options) | ||
# |> ActiveStorage.Variant.url() | ||
end | ||
end | ||
|
||
def blob_url_for(track, kind) do | ||
blob = blob_for(track, kind) | ||
ActiveStorage.service_blob_url(blob) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-272 KB
priv/static/images/musician-making-music-f7e7ab6c8889444dec047388b8887119.jpg
Binary file not shown.
Binary file not shown.