Skip to content

Commit 0b376a6

Browse files
committed
fix: Increate max video length + truncate
1 parent 0c907d9 commit 0b376a6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

apps/db/lib/db_schema/video.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,24 @@ defmodule DB.Schema.Video do
151151
|> cast(params, [:url, :title, :language])
152152
|> validate_required([:url, :title])
153153
|> parse_video_url()
154-
|> validate_length(:title, min: 5, max: 120)
154+
|> update_change(:title, &truncate_title/1)
155+
|> validate_length(:title, min: 5, max: 130)
155156
|> unique_constraint(:videos_youtube_id_index)
156157
|> unique_constraint(:videos_facebook_id_index)
157158
# Change locales like "en-US" to "en"
158159
|> update_change(:language, &format_language/1)
159160
end
160161

162+
163+
defp truncate_title(title) do
164+
trimmed = String.trim(title)
165+
if String.length(trimmed) > 130 do
166+
String.slice(trimmed, 0..128) <> "…"
167+
else
168+
trimmed
169+
end
170+
end
171+
161172
defp format_language("zxx"), do: nil
162173

163174
defp format_language(locale) do

0 commit comments

Comments
 (0)