Skip to content

Commit

Permalink
Merge branch 'main' into devcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson authored Jun 19, 2022
2 parents 421ed39 + ca533d0 commit ab531d6
Show file tree
Hide file tree
Showing 42 changed files with 551 additions and 390 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ APP_DOMAIN=rauversion.com
AWS_ACCESS_KEY_ID=xxxxx
AWS_SECRET_ACCESS_KEY=xxx+xx+xxx
AWS_S3_BUCKET=mybucket
AWS_S3_REGION=us-east-1
AWS_S3_REGION=us-east-1
EMAIL_ACCOUNT=[email protected]
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Rauversion

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# Rauversion

---

![image](https://user-images.githubusercontent.com/11976/174422926-b392a1f5-bd6a-4bd2-b6c8-8d41dad6711d.png)

Rauversion is an open source music sharing platform.

Rauversion is built on Elixir with Phoenix framework.

## setup

You can develop directly in a container with [vscode devcontainer](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) or [neovim devcontainer](https://github.com/jamestthompson3/nvim-remote-containers)

To start your Phoenix server:

* Install dependencies with `mix deps.get`
* rename `.env.example` to `.env` and add your variable configurations
* Create and migrate your database with `mix ecto.setup`
* Create some fake accounts `mix fake_accounts`
* Compile assets `cd assets && yarn install & cd ..`
Expand All @@ -14,5 +25,38 @@ Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.

## images

https://unsplash.com/photos/eXVd7gDPO9A
https://unsplash.com/photos/mbGxz7pt0jM
### TODO

- [x] User account
- [x] File uploads Avatar
- [x] User auth
- [x] Tracks
- [ ] Reposts
- [ ] Albums
- [ ] Playlists
- [ ] Likes
- [ ] Followers / Followings
- [ ] Range responses https://github.com/elixir-plug/plug/pull/526/files


# Setup:

### Generate fake accounts

iex -S mix fake_accounts

### image credits


Photo by <a href="https://unsplash.com/@schluditsch?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Daniel Schludi</a> on <a href="https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

Photo by <a href="https://unsplash.com/@helloimnik?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Hello I'm Nik</a> on <a href="https://unsplash.com/s/photos/music-studio?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

Photo by <a href="https://unsplash.com/@etiennegirardet?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Etienne Girardet</a> on <a href="https://unsplash.com/s/photos/music-studio?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

Photo by <a href="https://unsplash.com/@schluditsch?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Daniel Schludi</a> on <a href="https://unsplash.com/s/photos/music-studio?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

Photo by <a href="https://unsplash.com/@dancristianpaduret?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Dan-Cristian Pădureț</a> on <a href="https://unsplash.com/s/photos/music-studio?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

Photo by <a href="https://unsplash.com/@grittzheng?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Gritt Zheng</a> on <a href="https://unsplash.com/s/photos/music-studio?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>

8 changes: 8 additions & 0 deletions assets/js/controllers/audio_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import WaveSurfer from 'wavesurfer'

export default class extends Controller {
static targets = ['player', 'play', 'pause']

static values = {
height: String
}

initialize() {}
connect() {
this.wave()
Expand All @@ -17,6 +22,9 @@ export default class extends Controller {
backend: 'MediaElement',
waveColor: 'violet',
progressColor: 'purple',
height: this.heightValue || 70,
//partialRender: true,
pixelRatio: 1,
//fillParent: false,
barWidth: 2,
barHeight: 10, // the height of the wave
Expand Down
12 changes: 6 additions & 6 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ config :active_storage, repo: Rauversion.Repo

config :mogrify,
mogrify_command: [
path: "magick",
args: ["mogrify"]
path: "mogrify",
args: []
]

# Configure convert command:

config :mogrify,
convert_command: [
path: "magick",
args: ["convert"]
path: "convert",
args: []
]

# Configure identify command:

config :mogrify,
identify_command: [
path: "magick",
args: ["identify", "-verbose"]
path: "identify",
args: ["-verbose"]
]
14 changes: 7 additions & 7 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Config
# which you should run after static files are built and
# before starting your production server.
config :rauversion, RauversionWeb.Endpoint,
url: [host: "example.com", port: 80],
url: [host: "rauversion.com", port: 443],
cache_static_manifest: "priv/static/cache_manifest.json"

# Do not print debug messages in production
Expand Down Expand Up @@ -60,22 +60,22 @@ config :active_storage, repo: Rauversion.Repo

config :mogrify,
mogrify_command: [
path: "magick",
args: ["mogrify"]
path: "mogrify",
args: []
]

# Configure convert command:

config :mogrify,
convert_command: [
path: "magick",
args: ["convert"]
path: "convert",
args: []
]

# Configure identify command:

config :mogrify,
identify_command: [
path: "magick",
args: ["identify", "-verbose"]
path: "identify",
args: ["-verbose"]
]
16 changes: 16 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,20 @@ if config_env() == :prod do
# config :swoosh, :api_client, Swoosh.ApiClient.Hackney
#
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.

config :oscflow_phx, OscflowPhx.Mailer,
adapter: Swoosh.Adapters.SMTP,
relay: System.get_env("SMTP_DOMAIN"),
username: System.get_env("SMTP_USERNAME"),
password: System.get_env("SMTP_PASSWORD"),
# ssl: true,
# tls: :always,
auth: :always,
port: 587,
# dkim: [
# s: "default", d: "domain.com",
# private_key: {:pem_plain, File.read!("priv/keys/domain.private")}
# ],
retries: 2,
no_mx_lookups: false
end
8 changes: 6 additions & 2 deletions lib/rauversion/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,14 @@ defmodule Rauversion.Accounts do
# a = Rauversion.Accounts.get_user_by_username("michelson") |> Rauversion.Repo.preload(:avatar_blob)
case user do
nil ->
nil
Rauversion.BlobUtils.fallback_image(
"/images/dan-cristian-padure-XKCH37dHt7w-unsplash.jpg"
)

%{avatar_blob: nil} ->
nil
Rauversion.BlobUtils.fallback_image(
"/images/dan-cristian-padure-XKCH37dHt7w-unsplash.jpg"
)

%{avatar_blob: %ActiveStorage.Blob{} = avatar_blob} ->
avatar_blob |> ActiveStorage.url()
Expand Down
2 changes: 1 addition & 1 deletion lib/rauversion/accounts/user_notifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Rauversion.Accounts.UserNotifier do
email =
new()
|> to(recipient)
|> from({"Rauversion", "[email protected]"})
|> from({"Rauversion", System.get_env("EMAIL_ACCOUNT")})
|> subject(subject)
|> text_body(body)

Expand Down
72 changes: 72 additions & 0 deletions lib/rauversion/blob_utils.ex
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
61 changes: 4 additions & 57 deletions lib/rauversion/tracks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -112,64 +112,11 @@ defmodule Rauversion.Tracks do
Track.changeset(track, attrs)
end

def blob_url(user, kind) do
kind_blob = :"#{kind}_blob"
defdelegate blob_url(user, kind), to: Rauversion.BlobUtils

case user do
nil ->
nil
defdelegate blob_for(track, kind), to: Rauversion.BlobUtils

%{^kind_blob => nil} ->
nil
defdelegate variant_url(track, kind, options), to: Rauversion.BlobUtils

%{^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?
nil

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
defdelegate blob_url_for(track, kind), to: Rauversion.BlobUtils
end
Loading

0 comments on commit ab531d6

Please sign in to comment.