29 lines
689 B
Elixir
29 lines
689 B
Elixir
defmodule Bright.Torrents.Torrent do
|
|
use Ecto.Schema
|
|
import Ecto.Changeset
|
|
|
|
schema "torrents" do
|
|
field :info_hash_v1, :string
|
|
field :info_hash_v2, :string
|
|
field :cdn_url, :string
|
|
field :magnet, :string
|
|
|
|
belongs_to :vod, Bright.Streams.Vod
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
|
|
@doc false
|
|
def changeset(torrent, attrs) do
|
|
torrent
|
|
|> cast(attrs, [:vod_id, :info_hash_v1, :info_hash_v2, :cdn_url, :magnet])
|
|
|> validate_required([:info_hash_v1, :info_hash_v2, :cdn_url, :magnet])
|
|
end
|
|
end
|
|
|
|
defimpl Phoenix.HTML.Safe, for: Bright.Torrents.Torrent do
|
|
def to_iodata(torrent) do
|
|
Phoenix.HTML.Safe.to_iodata("Torrent #{torrent.id}")
|
|
end
|
|
end
|