From 867f94572d3790f348b36e2c123ced854704dfa2 Mon Sep 17 00:00:00 2001 From: miraikumiko Date: Fri, 20 Jun 2025 16:46:58 +0200 Subject: [PATCH 1/3] Update media_attachment --- lib/nulla/models/media_attachment.ex | 26 ++++++++++++++----- ...0250615131644_create_media_attachments.exs | 9 ++++--- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/nulla/models/media_attachment.ex b/lib/nulla/models/media_attachment.ex index 97efee3..5369007 100644 --- a/lib/nulla/models/media_attachment.ex +++ b/lib/nulla/models/media_attachment.ex @@ -5,18 +5,30 @@ defmodule Nulla.Models.MediaAttachment do @primary_key {:id, :integer, autogenerate: false} schema "media_attachments" do - field :file, :string - field :mime_type, :string - field :description, :string + field :type, :string + field :mediaType, :string + field :url, :string + field :name, :string + field :width, :integer + field :height, :integer belongs_to :note, Note timestamps(type: :utc_datetime) end - def changeset(media, attrs) do - media - |> cast(attrs, [:note_id, :file, :mime_type, :description]) - |> validate_required([:note_id, :file]) + def changeset(media_attachment, attrs) do + media_attachment + |> cast(attrs, [:type, :mediaType, :url, :name, :width, :height, :note_id]) + |> 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 diff --git a/priv/repo/migrations/20250615131644_create_media_attachments.exs b/priv/repo/migrations/20250615131644_create_media_attachments.exs index 1d9fe64..efacd89 100644 --- a/priv/repo/migrations/20250615131644_create_media_attachments.exs +++ b/priv/repo/migrations/20250615131644_create_media_attachments.exs @@ -4,10 +4,13 @@ defmodule Nulla.Repo.Migrations.CreateMediaAttachments do def change do create table(:media_attachments, primary_key: false) do 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 :file, :string, null: false - add :mime_type, :string - add :description, :string timestamps(type: :utc_datetime) end From 5d4ac46b67711df57ef571534bac01cd20278a31 Mon Sep 17 00:00:00 2001 From: miraikumiko Date: Fri, 20 Jun 2025 17:58:36 +0200 Subject: [PATCH 2/3] Update upload dir --- .gitignore | 4 ++-- lib/nulla_web.ex | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 43182ba..ad243a8 100644 --- a/.gitignore +++ b/.gitignore @@ -28,8 +28,8 @@ nulla-*.tar # Ignore assets that are produced by build tools. /priv/static/assets/ -# Ignore static files -/priv/static/files/ +# Ignore upload dir +/priv/static/system/ # Ignore digested assets cache. /priv/static/cache_manifest.json diff --git a/lib/nulla_web.ex b/lib/nulla_web.ex index 9feaa88..0c0b0cb 100644 --- a/lib/nulla_web.ex +++ b/lib/nulla_web.ex @@ -17,7 +17,7 @@ defmodule NullaWeb do 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 quote do From ea667243e0c44aca8f64edf345e51de0482a7dc4 Mon Sep 17 00:00:00 2001 From: miraikumiko Date: Fri, 20 Jun 2025 19:41:59 +0200 Subject: [PATCH 3/3] Update media_attachment --- lib/nulla/models/media_attachment.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/nulla/models/media_attachment.ex b/lib/nulla/models/media_attachment.ex index 5369007..61dbb1f 100644 --- a/lib/nulla/models/media_attachment.ex +++ b/lib/nulla/models/media_attachment.ex @@ -1,6 +1,8 @@ defmodule Nulla.Models.MediaAttachment do use Ecto.Schema import Ecto.Changeset + alias Nulla.Repo + alias Nulla.Snowflake alias Nulla.Models.Note @primary_key {:id, :integer, autogenerate: false}