Compare commits
3 commits
4929ce21fd
...
ea667243e0
Author | SHA1 | Date | |
---|---|---|---|
ea667243e0 | |||
5d4ac46b67 | |||
867f94572d |
4 changed files with 30 additions and 13 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -28,8 +28,8 @@ nulla-*.tar
|
||||||
# Ignore assets that are produced by build tools.
|
# Ignore assets that are produced by build tools.
|
||||||
/priv/static/assets/
|
/priv/static/assets/
|
||||||
|
|
||||||
# Ignore static files
|
# Ignore upload dir
|
||||||
/priv/static/files/
|
/priv/static/system/
|
||||||
|
|
||||||
# Ignore digested assets cache.
|
# Ignore digested assets cache.
|
||||||
/priv/static/cache_manifest.json
|
/priv/static/cache_manifest.json
|
||||||
|
|
|
@ -1,22 +1,36 @@
|
||||||
defmodule Nulla.Models.MediaAttachment do
|
defmodule Nulla.Models.MediaAttachment do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
alias Nulla.Repo
|
||||||
|
alias Nulla.Snowflake
|
||||||
alias Nulla.Models.Note
|
alias Nulla.Models.Note
|
||||||
|
|
||||||
@primary_key {:id, :integer, autogenerate: false}
|
@primary_key {:id, :integer, autogenerate: false}
|
||||||
schema "media_attachments" do
|
schema "media_attachments" do
|
||||||
field :file, :string
|
field :type, :string
|
||||||
field :mime_type, :string
|
field :mediaType, :string
|
||||||
field :description, :string
|
field :url, :string
|
||||||
|
field :name, :string
|
||||||
|
field :width, :integer
|
||||||
|
field :height, :integer
|
||||||
|
|
||||||
belongs_to :note, Note
|
belongs_to :note, Note
|
||||||
|
|
||||||
timestamps(type: :utc_datetime)
|
timestamps(type: :utc_datetime)
|
||||||
end
|
end
|
||||||
|
|
||||||
def changeset(media, attrs) do
|
def changeset(media_attachment, attrs) do
|
||||||
media
|
media_attachment
|
||||||
|> cast(attrs, [:note_id, :file, :mime_type, :description])
|
|> cast(attrs, [:type, :mediaType, :url, :name, :width, :height, :note_id])
|
||||||
|> validate_required([:note_id, :file])
|
|> validate_required([:type, :mediaType, :url, :note_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_media_attachment(attrs) when is_map(attrs) do
|
||||||
|
id = Map.get(attrs, :id, Snowflake.next_id())
|
||||||
|
|
||||||
|
%__MODULE__{}
|
||||||
|
|> changeset(attrs)
|
||||||
|
|> put_change(:id, id)
|
||||||
|
|> Repo.insert()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,7 +17,7 @@ defmodule NullaWeb do
|
||||||
those modules here.
|
those modules here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def static_paths, do: ~w(assets files fonts images favicon.ico robots.txt)
|
def static_paths, do: ~w(assets system fonts images favicon.ico robots.txt)
|
||||||
|
|
||||||
def router do
|
def router do
|
||||||
quote do
|
quote do
|
||||||
|
|
|
@ -4,10 +4,13 @@ defmodule Nulla.Repo.Migrations.CreateMediaAttachments do
|
||||||
def change do
|
def change do
|
||||||
create table(:media_attachments, primary_key: false) do
|
create table(:media_attachments, primary_key: false) do
|
||||||
add :id, :bigint, primary_key: true
|
add :id, :bigint, primary_key: true
|
||||||
|
add :type, :string, null: false
|
||||||
|
add :mediaType, :string, null: false
|
||||||
|
add :url, :string, null: false
|
||||||
|
add :name, :string
|
||||||
|
add :width, :integer
|
||||||
|
add :height, :integer
|
||||||
add :note_id, references(:notes, on_delete: :delete_all), null: false
|
add :note_id, references(:notes, on_delete: :delete_all), null: false
|
||||||
add :file, :string, null: false
|
|
||||||
add :mime_type, :string
|
|
||||||
add :description, :string
|
|
||||||
|
|
||||||
timestamps(type: :utc_datetime)
|
timestamps(type: :utc_datetime)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue