From 253a2d0221d94f3b5a1dd1353343f02bcecd32d0 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 15 May 2023 09:32:04 +0200 Subject: [PATCH 1/7] Add markdown hint to edit form's description field --- lib/asciinema_web/templates/asciicast/edit.html.eex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/asciinema_web/templates/asciicast/edit.html.eex b/lib/asciinema_web/templates/asciicast/edit.html.eex index 88bfff1ca..431a71c2b 100644 --- a/lib/asciinema_web/templates/asciicast/edit.html.eex +++ b/lib/asciinema_web/templates/asciicast/edit.html.eex @@ -17,6 +17,7 @@
<%= textarea f, :description, class: "form-control", rows: 10 %> <%= error_tag f, :description %> + Parsed as Markdown.
From 84ce49e64d61a3e2ca0834dc636bf2a865df4de9 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 15 May 2023 12:48:19 +0200 Subject: [PATCH 2/7] Upgrade player --- assets/css/_asciicast_card.scss | 4 ++-- assets/package-lock.json | 24 +++++++++---------- assets/package.json | 2 +- .../templates/asciicast/_thumbnail.html.eex | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/assets/css/_asciicast_card.scss b/assets/css/_asciicast_card.scss index ac970e99c..29f09d817 100644 --- a/assets/css/_asciicast_card.scss +++ b/assets/css/_asciicast_card.scss @@ -60,8 +60,8 @@ div.asciicast-card { border-bottom-left-radius: 0; border-bottom-right-radius: 0; - .asciinema-terminal { - .line { + .ap-terminal { + .ap-line { height: 1.3333333333em; } } diff --git a/assets/package-lock.json b/assets/package-lock.json index 66fdd22ea..e3bbc6d3c 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -8,7 +8,7 @@ "devDependencies": { "@babel/core": "^7.21.0", "@babel/preset-env": "^7.20.2", - "asciinema-player": "3.2.0", + "asciinema-player": "^3.4.0", "babel-loader": "^8.3.0", "bootstrap": "^4.5.0", "copy-webpack-plugin": "^11.0.0", @@ -1618,12 +1618,12 @@ "dev": true }, "node_modules/@babel/runtime": { - "version": "7.16.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.16.0.tgz", - "integrity": "sha512-Nht8L0O8YCktmsDV6FqFue7vQLRx3Hb0B37lS5y0jDRqRxlBG4wIJHnf9/bgSE2UyipKFA01YtS+npRdTWBUyw==", + "version": "7.21.5", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.5.tgz", + "integrity": "sha512-8jI69toZqqcsnqGGqwGS4Qb1VwLOEp4hz+CXPywcvjs60u3B4Pom/U/7rm4W8tMOYEB+E9wgD0mW1l3r8qlI9Q==", "dev": true, "dependencies": { - "regenerator-runtime": "^0.13.4" + "regenerator-runtime": "^0.13.11" }, "engines": { "node": ">=6.9.0" @@ -2297,12 +2297,12 @@ } }, "node_modules/asciinema-player": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/asciinema-player/-/asciinema-player-3.2.0.tgz", - "integrity": "sha512-fV3Coe/UGieUy+5KCrh1qZf1lFWkuj12a6KcKrr84b61UFfUOpAZfyem4UnpczuP6cjrV3w5t0u8Wd1kTz/e7g==", + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/asciinema-player/-/asciinema-player-3.4.0.tgz", + "integrity": "sha512-dX6jt5S3K6daItsVWzyY9mRDK+ivC2QgqCxFkdSiNslo0vY/ZqA4upcTzqIKZqBtxppovOZk44ltg9VnHG9QVg==", "dev": true, "dependencies": { - "@babel/runtime": "^7.15.4", + "@babel/runtime": "^7.21.0", "solid-js": "^1.3.0" } }, @@ -4920,9 +4920,9 @@ } }, "node_modules/regenerator-runtime": { - "version": "0.13.9", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.9.tgz", - "integrity": "sha512-p3VT+cOEgxFsRRA9X4lkI1E+k2/CtnKtU4gcxyaCUreilL/vqI6CdZ3wxVUx3UOUg+gnUOQQcRI7BmSI656MYA==", + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", "dev": true }, "node_modules/regenerator-transform": { diff --git a/assets/package.json b/assets/package.json index 6330b7696..05cf2cefa 100644 --- a/assets/package.json +++ b/assets/package.json @@ -12,7 +12,7 @@ "devDependencies": { "@babel/core": "^7.21.0", "@babel/preset-env": "^7.20.2", - "asciinema-player": "3.2.0", + "asciinema-player": "^3.4.0", "babel-loader": "^8.3.0", "bootstrap": "^4.5.0", "copy-webpack-plugin": "^11.0.0", diff --git a/lib/asciinema_web/templates/asciicast/_thumbnail.html.eex b/lib/asciinema_web/templates/asciicast/_thumbnail.html.eex index 287e239df..8983ead91 100644 --- a/lib/asciinema_web/templates/asciicast/_thumbnail.html.eex +++ b/lib/asciinema_web/templates/asciicast/_thumbnail.html.eex @@ -1,5 +1,5 @@
-
<%= for line <- thumbnail(@asciicast) do %><%= for {text, attrs} <- line do %><%= text %><% end %><% end %>
+
<%= for line <- thumbnail(@asciicast) do %><%= for {text, attrs} <- line do %><%= text %><% end %><% end %>
\ No newline at end of file + in order to render terminal properly. --> From 5c69081111e55de4136878cc60df9162066400c2 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 15 May 2023 12:48:36 +0200 Subject: [PATCH 3/7] Add space above forms submit button --- lib/asciinema_web/templates/asciicast/edit.html.eex | 1 + lib/asciinema_web/templates/user/edit.html.eex | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/asciinema_web/templates/asciicast/edit.html.eex b/lib/asciinema_web/templates/asciicast/edit.html.eex index 431a71c2b..71753ffdd 100644 --- a/lib/asciinema_web/templates/asciicast/edit.html.eex +++ b/lib/asciinema_web/templates/asciicast/edit.html.eex @@ -83,6 +83,7 @@
+
<%= submit "Save", class: "btn btn-primary" %> <%= link "Cancel", to: Routes.asciicast_path(@conn, :show, @changeset.data), class: "btn" %>
diff --git a/lib/asciinema_web/templates/user/edit.html.eex b/lib/asciinema_web/templates/user/edit.html.eex index 253ba5bc7..fbe06b3d6 100644 --- a/lib/asciinema_web/templates/user/edit.html.eex +++ b/lib/asciinema_web/templates/user/edit.html.eex @@ -54,6 +54,7 @@
+
<%= submit "Save", class: "btn btn-primary" %> <%= link "Cancel", to: profile_path(@conn), class: "btn" %>
From f01c2576079db780dc610160b543fb715312c449 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 15 May 2023 14:30:10 +0200 Subject: [PATCH 4/7] Display user recordings in 2 columns instead of 3 --- lib/asciinema_web/templates/user/show.html.eex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/asciinema_web/templates/user/show.html.eex b/lib/asciinema_web/templates/user/show.html.eex index 8c2737c45..d49ae301d 100644 --- a/lib/asciinema_web/templates/user/show.html.eex +++ b/lib/asciinema_web/templates/user/show.html.eex @@ -66,10 +66,10 @@ <% {0, false} -> %> <% _ -> %> - <%= for asciicasts <- Enum.chunk_every(@page, 3, 3) do %> + <%= for asciicasts <- Enum.chunk_every(@page, 2, 2) do %>
<%= for asciicast <- asciicasts do %> -
+
<%= render AsciinemaWeb.AsciicastView, "_card.html", conn: @conn, asciicast: asciicast %>
<% end %> From 7f90b3110028cb585b8afdfe3d55d5623ceb5cc8 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 15 May 2023 14:59:06 +0200 Subject: [PATCH 5/7] Add support for markers --- lib/asciinema/asciicasts/asciicast.ex | 42 ++++++++++++++++++- .../templates/asciicast/edit.html.eex | 9 ++++ lib/asciinema_web/views/asciicast_view.ex | 11 +++++ ...230515080531_add_markers_to_asciicasts.exs | 9 ++++ test/asciinema/asciicasts_test.exs | 14 +++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 priv/repo/migrations/20230515080531_add_markers_to_asciicasts.exs diff --git a/lib/asciinema/asciicasts/asciicast.ex b/lib/asciinema/asciicasts/asciicast.ex index b04e434b8..9dea8bc27 100644 --- a/lib/asciinema/asciicasts/asciicast.ex +++ b/lib/asciinema/asciicasts/asciicast.ex @@ -40,6 +40,7 @@ defmodule Asciinema.Asciicasts.Asciicast do field :archived_at, :utc_datetime_usec field :terminal_line_height, :float field :terminal_font_family, :string + field :markers, :string timestamps() @@ -100,7 +101,8 @@ defmodule Asciinema.Asciicasts.Asciicast do :theme_name, :idle_time_limit, :terminal_line_height, - :terminal_font_family + :terminal_font_family, + :markers ]) |> validate_number(:cols_override, greater_than: 0, less_than: 1024) |> validate_number(:rows_override, greater_than: 0, less_than: 512) @@ -111,6 +113,44 @@ defmodule Asciinema.Asciicasts.Asciicast do ) |> validate_inclusion(:terminal_font_family, custom_terminal_font_families) |> validate_number(:snapshot_at, greater_than: 0) + |> validate_change(:markers, &validate_markers/2) + end + + defp validate_markers(_, markers) do + case parse_markers(markers) do + {:ok, _} -> [] + {:error, index} -> [markers: "invalid syntax in line #{index + 1}"] + end + end + + def parse_markers(markers) do + results = + markers + |> String.trim() + |> String.split("\n") + |> Enum.map(&parse_marker/1) + + case Enum.find_index(results, fn result -> result == :error end) do + nil -> {:ok, results} + index -> {:error, index} + end + end + + defp parse_marker(marker) do + parts = + marker + |> String.trim() + |> String.split(~r/\s+-\s+/, parts: 2) + |> Kernel.++([""]) + |> Enum.take(2) + + with [t, l] <- parts, + {t, ""} <- Float.parse(t), + true <- String.length(l) < 100 do + {t, l} + else + _ -> :error + end end def snapshot_changeset(struct, snapshot) do diff --git a/lib/asciinema_web/templates/asciicast/edit.html.eex b/lib/asciinema_web/templates/asciicast/edit.html.eex index 71753ffdd..734dd3754 100644 --- a/lib/asciinema_web/templates/asciicast/edit.html.eex +++ b/lib/asciinema_web/templates/asciicast/edit.html.eex @@ -81,6 +81,15 @@
+
+ <%= label f, :markers, class: "col-sm-4 col-md-3 col-lg-3 col-form-label" %> +
+ <%= textarea f, :markers, class: "form-control", rows: 6, placeholder: "Example:\n\n5.0 - Intro\n11.3 - Installation\n32.0 - Configuration\n66.5 - Tips & Tricks" %> + <%= error_tag f, :markers %> + Each line is a marker defined as [time] - [label]. +
+
+

diff --git a/lib/asciinema_web/views/asciicast_view.ex b/lib/asciinema_web/views/asciicast_view.ex index 053e5b9b4..4ebeaa627 100644 --- a/lib/asciinema_web/views/asciicast_view.ex +++ b/lib/asciinema_web/views/asciicast_view.ex @@ -2,6 +2,7 @@ defmodule AsciinemaWeb.AsciicastView do use AsciinemaWeb, :view import Scrivener.HTML alias Asciinema.Asciicasts + alias Asciinema.Asciicasts.Asciicast alias AsciinemaWeb.Endpoint alias AsciinemaWeb.Router.Helpers.Extra, as: RoutesX alias AsciinemaWeb.UserView @@ -42,6 +43,7 @@ defmodule AsciinemaWeb.AsciicastView do terminalLineHeight: asciicast.terminal_line_height, customTerminalFontFamily: asciicast.terminal_font_family, poster: poster(asciicast.snapshot), + markers: markers(asciicast.markers), idleTimeLimit: asciicast.idle_time_limit, title: title(asciicast), author: author_username(asciicast), @@ -135,6 +137,15 @@ defmodule AsciinemaWeb.AsciicastView do "data:text/plain," <> text <> @csi_init <> "?25l" end + defp markers(nil), do: nil + + defp markers(markers) do + case Asciicast.parse_markers(markers) do + {:ok, markers} -> Enum.map(markers, &Tuple.to_list/1) + {:error, _} -> nil + end + end + defp line_to_text(segments) do segments |> Enum.map(&segment_to_text/1) diff --git a/priv/repo/migrations/20230515080531_add_markers_to_asciicasts.exs b/priv/repo/migrations/20230515080531_add_markers_to_asciicasts.exs new file mode 100644 index 000000000..196115c96 --- /dev/null +++ b/priv/repo/migrations/20230515080531_add_markers_to_asciicasts.exs @@ -0,0 +1,9 @@ +defmodule Asciinema.Repo.Migrations.AddMarkersToAsciicasts do + use Ecto.Migration + + def change do + alter table(:asciicasts) do + add :markers, :text + end + end +end diff --git a/test/asciinema/asciicasts_test.exs b/test/asciinema/asciicasts_test.exs index b068bd3a4..d34b7a861 100644 --- a/test/asciinema/asciicasts_test.exs +++ b/test/asciinema/asciicasts_test.exs @@ -315,4 +315,18 @@ defmodule Asciinema.AsciicastsTest do assert stream_v0 == stream_v2 end end + + describe "parse_markers/1" do + test "returns markers for valid syntax" do + result = Asciicast.parse_markers("1.0 - Intro\n2.5\n5.0 - Tips & Tricks\n") + + assert result == {:ok, [{1.0, "Intro"}, {2.5, ""}, {5.0, "Tips & Tricks"}]} + end + + test "returns error for invalid syntax" do + result = Asciicast.parse_markers("1.0 - Intro\nFoobar\n") + + assert result == {:error, 1} + end + end end From 51fd7567a91671ed35baa0b25d6f974714783fb3 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 15 May 2023 16:31:51 +0200 Subject: [PATCH 6/7] Rename Asciicasts context to Recordings --- .iex.exs | 4 +- assets/css/_base.scss | 2 +- ...ciicast_card.scss => _recording_card.scss} | 0 ...ciicast_list.scss => _recording_list.scss} | 2 +- ...ciicast_show.scss => _recording_show.scss} | 2 +- assets/css/app.scss | 8 +-- config/test.exs | 2 +- lib/asciinema.ex | 4 +- lib/asciinema/accounts/user.ex | 2 +- .../asciicasts/snapshot_updater/sync.ex | 9 --- lib/asciinema/authorization.ex | 2 +- lib/asciinema/gc.ex | 8 +-- lib/asciinema/png_generator.ex | 2 +- lib/asciinema/png_generator/rsvg.ex | 2 +- .../{asciicasts => recordings}/asciicast.ex | 4 +- .../playback_opts.ex | 2 +- .../recordings.ex} | 8 +-- .../snapshot_updater.ex | 8 +-- .../snapshot_updater/noop.ex | 2 +- .../recordings/snapshot_updater/sync.ex | 9 +++ lib/asciinema/upgrades/initial_seed.ex | 2 +- lib/asciinema/upgrades/upgrade_asciicasts.ex | 23 -------- lib/asciinema/upgrades/upgrade_recordings.ex | 23 ++++++++ ..._controller.ex => recording_controller.ex} | 8 +-- .../controllers/oembed_controller.ex | 4 +- ..._controller.ex => recording_controller.ex} | 36 ++++++------ .../controllers/user_controller.ex | 4 +- lib/asciinema_web/router.ex | 20 +++---- .../{asciicast => recording}/_card.html.eex | 4 +- .../_download_modal.html.eex | 0 .../_featured_badge.html.eex | 0 .../{asciicast => recording}/_logo.svg.eex | 0 .../_private_badge.html.eex | 0 .../_share_modal.html.eex | 6 +- .../_svg_256_colors.css.eex | 0 .../_svg_theme_asciinema.css.eex | 0 .../_svg_theme_monokai.css.eex | 0 .../_svg_theme_solarized-dark.css.eex | 0 .../_svg_theme_solarized-light.css.eex | 0 .../_svg_theme_tango.css.eex | 0 .../_terminal.svg.eex | 0 .../_thumbnail.html.eex | 0 .../archived.html.eex | 0 .../{asciicast => recording}/edit.html.eex | 6 +- .../{asciicast => recording}/gif.html.heex | 0 .../{asciicast => recording}/iframe.html.eex | 0 .../{asciicast => recording}/index.html.eex | 0 .../meta.show.html.eex | 8 +-- .../{asciicast => recording}/show.html.eex | 14 ++--- .../templates/user/show.html.eex | 12 ++-- .../{asciicast_view.ex => recording_view.ex} | 4 +- lib/asciinema_web/views/oembed_view.ex | 10 ++-- .../{asciicast_view.ex => recording_view.ex} | 19 +++---- .../20211212114046_insert_upgrade_jobs.exs | 2 +- priv/repo/seeds.exs | 2 +- ...sciicasts_test.exs => recordings_test.exs} | 56 +++++++++---------- ...test.exs => recording_controller_test.exs} | 44 +++++++-------- test/controllers/oembed_controller_test.exs | 6 +- ...test.exs => recording_controller_test.exs} | 28 +++++----- test/controllers/user_controller_test.exs | 2 +- test/support/factory.ex | 2 +- test/support/fixtures.ex | 6 +- ..._view_test.exs => recording_view_test.exs} | 8 +-- 63 files changed, 219 insertions(+), 222 deletions(-) rename assets/css/{_asciicast_card.scss => _recording_card.scss} (100%) rename assets/css/{_asciicast_list.scss => _recording_list.scss} (96%) rename assets/css/{_asciicast_show.scss => _recording_show.scss} (97%) delete mode 100644 lib/asciinema/asciicasts/snapshot_updater/sync.ex rename lib/asciinema/{asciicasts => recordings}/asciicast.ex (98%) rename lib/asciinema/{asciicasts => recordings}/playback_opts.ex (98%) rename lib/asciinema/{asciicasts/asciicasts.ex => recordings/recordings.ex} (98%) rename lib/asciinema/{asciicasts => recordings}/snapshot_updater.ex (66%) rename lib/asciinema/{asciicasts => recordings}/snapshot_updater/noop.ex (50%) create mode 100644 lib/asciinema/recordings/snapshot_updater/sync.ex delete mode 100644 lib/asciinema/upgrades/upgrade_asciicasts.ex create mode 100644 lib/asciinema/upgrades/upgrade_recordings.ex rename lib/asciinema_web/controllers/api/{asciicast_controller.ex => recording_controller.ex} (91%) rename lib/asciinema_web/controllers/{asciicast_controller.ex => recording_controller.ex} (87%) rename lib/asciinema_web/templates/{asciicast => recording}/_card.html.eex (89%) rename lib/asciinema_web/templates/{asciicast => recording}/_download_modal.html.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_featured_badge.html.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_logo.svg.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_private_badge.html.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_share_modal.html.eex (82%) rename lib/asciinema_web/templates/{asciicast => recording}/_svg_256_colors.css.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_svg_theme_asciinema.css.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_svg_theme_monokai.css.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_svg_theme_solarized-dark.css.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_svg_theme_solarized-light.css.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_svg_theme_tango.css.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_terminal.svg.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/_thumbnail.html.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/archived.html.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/edit.html.eex (96%) rename lib/asciinema_web/templates/{asciicast => recording}/gif.html.heex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/iframe.html.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/index.html.eex (100%) rename lib/asciinema_web/templates/{asciicast => recording}/meta.show.html.eex (82%) rename lib/asciinema_web/templates/{asciicast => recording}/show.html.eex (92%) rename lib/asciinema_web/views/api/{asciicast_view.ex => recording_view.ex} (93%) rename lib/asciinema_web/views/{asciicast_view.ex => recording_view.ex} (97%) rename test/asciinema/{asciicasts_test.exs => recordings_test.exs} (86%) rename test/controllers/api/{asciicast_controller_test.exs => recording_controller_test.exs} (75%) rename test/controllers/{asciicast_controller_test.exs => recording_controller_test.exs} (87%) rename test/views/{asciicast_view_test.exs => recording_view_test.exs} (92%) diff --git a/.iex.exs b/.iex.exs index 794f95316..758d36fa2 100644 --- a/.iex.exs +++ b/.iex.exs @@ -3,6 +3,6 @@ import_if_available(Ecto.Query) import_if_available(Ecto.Changeset) import_if_available(Enum, only: [map: 2, filter: 2, reduce: 2, reduce: 3]) -alias Asciinema.{Repo, Asciicasts, Accounts} -alias Asciinema.Asciicasts.Asciicast +alias Asciinema.{Repo, Recordings, Accounts} +alias Asciinema.Recordings.Asciicast alias Asciinema.Accounts.{User, ApiToken} diff --git a/assets/css/_base.scss b/assets/css/_base.scss index 0f9ffb046..57f814961 100644 --- a/assets/css/_base.scss +++ b/assets/css/_base.scss @@ -74,7 +74,7 @@ body, main { background-color: #f7f7f7; } -.c-asciicast { +.c-recording { main { h1, h2, h3 { margin-top: 2rem; diff --git a/assets/css/_asciicast_card.scss b/assets/css/_recording_card.scss similarity index 100% rename from assets/css/_asciicast_card.scss rename to assets/css/_recording_card.scss diff --git a/assets/css/_asciicast_list.scss b/assets/css/_recording_list.scss similarity index 96% rename from assets/css/_asciicast_list.scss rename to assets/css/_recording_list.scss index b5cd26757..10ece7399 100644 --- a/assets/css/_asciicast_list.scss +++ b/assets/css/_recording_list.scss @@ -1,4 +1,4 @@ -.c-asciicast { +.c-recording { &.a-category { main { .nav { diff --git a/assets/css/_asciicast_show.scss b/assets/css/_recording_show.scss similarity index 97% rename from assets/css/_asciicast_show.scss rename to assets/css/_recording_show.scss index dc610d281..07a8ab6ce 100644 --- a/assets/css/_asciicast_show.scss +++ b/assets/css/_recording_show.scss @@ -1,4 +1,4 @@ -.c-asciicast.a-show { +.c-recording.a-show { section.info { small { font-size: 14px; diff --git a/assets/css/app.scss b/assets/css/app.scss index b6a9f4d62..466d353ae 100644 --- a/assets/css/app.scss +++ b/assets/css/app.scss @@ -10,9 +10,9 @@ $primary: #06989a; @import "./_header.scss"; @import "./_footer.scss"; @import "./_flash.scss"; -@import "./_asciicast_card.scss"; -@import "./_asciicast_list.scss"; -@import "./_asciicast_show.scss"; +@import "./_recording_card.scss"; +@import "./_recording_list.scss"; +@import "./_recording_show.scss"; @import "./_simple_layout.scss"; @import "./_user_profile.scss"; @import "./_user_login.scss"; @@ -22,7 +22,7 @@ $primary: #06989a; @import "./fonts/jetbrains-mono-nerd-font.css"; @import "~asciinema-player/dist/bundle/asciinema-player.css"; -.c-asciicast.a-index { +.c-recording.a-index { h2 { font-weight: 600; diff --git a/config/test.exs b/config/test.exs index 0a727c977..15d5b7d51 100644 --- a/config/test.exs +++ b/config/test.exs @@ -31,7 +31,7 @@ config :asciinema, Asciinema.Accounts, config :asciinema, Asciinema.FileStore.Local, path: "uploads/test/" -config :asciinema, :snapshot_updater, Asciinema.Asciicasts.SnapshotUpdater.Noop +config :asciinema, :snapshot_updater, Asciinema.Recordings.SnapshotUpdater.Noop config :asciinema, Oban, testing: :manual diff --git a/lib/asciinema.ex b/lib/asciinema.ex index ca2be1476..d6f16d873 100644 --- a/lib/asciinema.ex +++ b/lib/asciinema.ex @@ -1,9 +1,9 @@ defmodule Asciinema do - alias Asciinema.{Accounts, Asciicasts, Repo} + alias Asciinema.{Accounts, Recordings, Repo} def merge_accounts(src_user, dst_user) do Repo.transaction(fn -> - Asciicasts.reassign_asciicasts(src_user.id, dst_user.id) + Recordings.reassign_asciicasts(src_user.id, dst_user.id) Accounts.reassign_api_tokens(src_user.id, dst_user.id) Accounts.delete_user!(src_user) Accounts.get_user(dst_user.id) diff --git a/lib/asciinema/accounts/user.ex b/lib/asciinema/accounts/user.ex index f9b9d2f92..25ed7e6f5 100644 --- a/lib/asciinema/accounts/user.ex +++ b/lib/asciinema/accounts/user.ex @@ -22,7 +22,7 @@ defmodule Asciinema.Accounts.User do timestamps() - has_many :asciicasts, Asciinema.Asciicasts.Asciicast + has_many :asciicasts, Asciinema.Recordings.Asciicast has_many :api_tokens, Asciinema.Accounts.ApiToken end diff --git a/lib/asciinema/asciicasts/snapshot_updater/sync.ex b/lib/asciinema/asciicasts/snapshot_updater/sync.ex deleted file mode 100644 index 4c1457c2d..000000000 --- a/lib/asciinema/asciicasts/snapshot_updater/sync.ex +++ /dev/null @@ -1,9 +0,0 @@ -defmodule Asciinema.Asciicasts.SnapshotUpdater.Sync do - alias Asciinema.Asciicasts - alias Asciinema.Asciicasts.Asciicast - - def update_snapshot(%Asciicast{} = asciicast) do - {:ok, _} = Asciicasts.update_snapshot(asciicast) - :ok - end -end diff --git a/lib/asciinema/authorization.ex b/lib/asciinema/authorization.ex index cc36c3d6b..e1ade7254 100644 --- a/lib/asciinema/authorization.ex +++ b/lib/asciinema/authorization.ex @@ -1,6 +1,6 @@ defmodule Asciinema.Authorization do alias Asciinema.Accounts.User - alias Asciinema.Asciicasts.Asciicast + alias Asciinema.Recordings.Asciicast defmodule Policy do def can?(nil, _action, _thing) do diff --git a/lib/asciinema/gc.ex b/lib/asciinema/gc.ex index 3892b9c76..5dd912c75 100644 --- a/lib/asciinema/gc.ex +++ b/lib/asciinema/gc.ex @@ -1,15 +1,15 @@ defmodule Asciinema.GC do use Oban.Worker alias Asciinema.Accounts - alias Asciinema.Asciicasts + alias Asciinema.Recordings require Logger @impl Oban.Worker def perform(_job) do - if days = Asciicasts.gc_days() do - Logger.info("archiving unclaimed asciicasts...") + if days = Recordings.gc_days() do + Logger.info("archiving unclaimed Recordings...") dt = Timex.shift(Timex.now(), days: -days) - count = Asciicasts.archive_asciicasts(Accounts.temporary_users(), dt) + count = Recordings.archive_asciicasts(Accounts.temporary_users(), dt) Logger.info("archived #{count} asciicasts") :ok diff --git a/lib/asciinema/png_generator.ex b/lib/asciinema/png_generator.ex index b28c7b24b..1110a57c5 100644 --- a/lib/asciinema/png_generator.ex +++ b/lib/asciinema/png_generator.ex @@ -1,5 +1,5 @@ defmodule Asciinema.PngGenerator do - alias Asciinema.Asciicasts.Asciicast + alias Asciinema.Recordings.Asciicast @doc "Generates PNG image from asciicast and returns path to it" @callback generate(asciicast :: %Asciicast{}) :: {:ok, String.t()} | {:error, term} diff --git a/lib/asciinema/png_generator/rsvg.ex b/lib/asciinema/png_generator/rsvg.ex index 8606a4587..ff62d24b7 100644 --- a/lib/asciinema/png_generator/rsvg.ex +++ b/lib/asciinema/png_generator/rsvg.ex @@ -57,7 +57,7 @@ defmodule Asciinema.PngGenerator.Rsvg do png_path = Path.join(tmp_dir_path, "tmp.png") svg = - AsciinemaWeb.AsciicastView.render( + AsciinemaWeb.RecordingView.render( "show.svg", %{ asciicast: asciicast, diff --git a/lib/asciinema/asciicasts/asciicast.ex b/lib/asciinema/recordings/asciicast.ex similarity index 98% rename from lib/asciinema/asciicasts/asciicast.ex rename to lib/asciinema/recordings/asciicast.ex index 9dea8bc27..11557c8aa 100644 --- a/lib/asciinema/asciicasts/asciicast.ex +++ b/lib/asciinema/recordings/asciicast.ex @@ -1,8 +1,8 @@ -defmodule Asciinema.Asciicasts.Asciicast do +defmodule Asciinema.Recordings.Asciicast do use Ecto.Schema import Ecto.Changeset alias Asciinema.Accounts.User - alias Asciinema.Asciicasts.Asciicast + alias Asciinema.Recordings.Asciicast @default_theme "asciinema" diff --git a/lib/asciinema/asciicasts/playback_opts.ex b/lib/asciinema/recordings/playback_opts.ex similarity index 98% rename from lib/asciinema/asciicasts/playback_opts.ex rename to lib/asciinema/recordings/playback_opts.ex index d04ea356d..ca27bed65 100644 --- a/lib/asciinema/asciicasts/playback_opts.ex +++ b/lib/asciinema/recordings/playback_opts.ex @@ -1,4 +1,4 @@ -defmodule Asciinema.Asciicasts.PlaybackOpts do +defmodule Asciinema.Recordings.PlaybackOpts do use Ecto.Schema import Ecto.Changeset diff --git a/lib/asciinema/asciicasts/asciicasts.ex b/lib/asciinema/recordings/recordings.ex similarity index 98% rename from lib/asciinema/asciicasts/asciicasts.ex rename to lib/asciinema/recordings/recordings.ex index 616dfba3d..6efc7587b 100644 --- a/lib/asciinema/asciicasts/asciicasts.ex +++ b/lib/asciinema/recordings/recordings.ex @@ -1,8 +1,8 @@ -defmodule Asciinema.Asciicasts do +defmodule Asciinema.Recordings do require Logger import Ecto.Query, warn: false alias Asciinema.{Repo, FileStore, StringUtils, Vt} - alias Asciinema.Asciicasts.{Asciicast, SnapshotUpdater} + alias Asciinema.Recordings.{Asciicast, SnapshotUpdater} alias Ecto.Changeset @custom_terminal_font_families [ @@ -500,14 +500,14 @@ defmodule Asciinema.Asciicasts do case cursor do {x, y} -> lines - |> AsciinemaWeb.AsciicastView.split_chunks() + |> AsciinemaWeb.RecordingView.split_chunks() |> List.update_at(y, fn line -> List.update_at(line, x, fn {text, attrs} -> attrs = Map.put(attrs, "inverse", !(attrs["inverse"] || false)) {text, attrs} end) end) - |> AsciinemaWeb.AsciicastView.group_chunks() + |> AsciinemaWeb.RecordingView.group_chunks() _ -> lines diff --git a/lib/asciinema/asciicasts/snapshot_updater.ex b/lib/asciinema/recordings/snapshot_updater.ex similarity index 66% rename from lib/asciinema/asciicasts/snapshot_updater.ex rename to lib/asciinema/recordings/snapshot_updater.ex index cf8465360..a607a1c5b 100644 --- a/lib/asciinema/asciicasts/snapshot_updater.ex +++ b/lib/asciinema/recordings/snapshot_updater.ex @@ -1,13 +1,13 @@ -defmodule Asciinema.Asciicasts.SnapshotUpdater do +defmodule Asciinema.Recordings.SnapshotUpdater do defmodule Job do use Oban.Worker - alias Asciinema.{Repo, Asciicasts} - alias Asciinema.Asciicasts.Asciicast + alias Asciinema.{Repo, Recordings} + alias Asciinema.Recordings.Asciicast @impl Oban.Worker def perform(job) do if asciicast = Repo.get(Asciicast, job.args["asciicast_id"]) do - Asciicasts.update_snapshot(asciicast) + Recordings.update_snapshot(asciicast) else :discard end diff --git a/lib/asciinema/asciicasts/snapshot_updater/noop.ex b/lib/asciinema/recordings/snapshot_updater/noop.ex similarity index 50% rename from lib/asciinema/asciicasts/snapshot_updater/noop.ex rename to lib/asciinema/recordings/snapshot_updater/noop.ex index 2c08ffcaf..58de325c1 100644 --- a/lib/asciinema/asciicasts/snapshot_updater/noop.ex +++ b/lib/asciinema/recordings/snapshot_updater/noop.ex @@ -1,4 +1,4 @@ -defmodule Asciinema.Asciicasts.SnapshotUpdater.Noop do +defmodule Asciinema.Recordings.SnapshotUpdater.Noop do def update_snapshot(_asciicast) do :ok end diff --git a/lib/asciinema/recordings/snapshot_updater/sync.ex b/lib/asciinema/recordings/snapshot_updater/sync.ex new file mode 100644 index 000000000..30eba2d7d --- /dev/null +++ b/lib/asciinema/recordings/snapshot_updater/sync.ex @@ -0,0 +1,9 @@ +defmodule Asciinema.Recordings.SnapshotUpdater.Sync do + alias Asciinema.Recordings + alias Asciinema.Recordings.Asciicast + + def update_snapshot(%Asciicast{} = asciicast) do + {:ok, _} = Recordings.update_snapshot(asciicast) + :ok + end +end diff --git a/lib/asciinema/upgrades/initial_seed.ex b/lib/asciinema/upgrades/initial_seed.ex index 517d39b02..f4afdfef7 100644 --- a/lib/asciinema/upgrades/initial_seed.ex +++ b/lib/asciinema/upgrades/initial_seed.ex @@ -5,7 +5,7 @@ defmodule Asciinema.Upgrades.InitialSeed do @impl Oban.Worker def perform(_job) do user = Asciinema.Accounts.ensure_asciinema_user() - :ok = Asciinema.Asciicasts.ensure_welcome_asciicast(user) + :ok = Asciinema.Recordings.ensure_welcome_asciicast(user) Logger.info("database seeded successfully") diff --git a/lib/asciinema/upgrades/upgrade_asciicasts.ex b/lib/asciinema/upgrades/upgrade_asciicasts.ex deleted file mode 100644 index efe94a038..000000000 --- a/lib/asciinema/upgrades/upgrade_asciicasts.ex +++ /dev/null @@ -1,23 +0,0 @@ -defmodule Asciinema.Upgrades.UpgradeAsciicasts do - use Asciinema.Upgrades.Worker - require Logger - alias Asciinema.Asciicasts - - @impl Oban.Worker - def perform(%Oban.Job{args: %{"id" => id}}) do - Asciicasts.upgrade(id) - Logger.info("asciicast #{id} upgraded") - - :ok - end - - def perform(_job) do - for asciicast <- Asciicasts.upgradable() do - Oban.insert!(__MODULE__.new(%{id: asciicast.id})) - end - - Logger.info("enqueued asciicast upgrade jobs") - - :ok - end -end diff --git a/lib/asciinema/upgrades/upgrade_recordings.ex b/lib/asciinema/upgrades/upgrade_recordings.ex new file mode 100644 index 000000000..93c111e22 --- /dev/null +++ b/lib/asciinema/upgrades/upgrade_recordings.ex @@ -0,0 +1,23 @@ +defmodule Asciinema.Upgrades.UpgradeRecordings do + use Asciinema.Upgrades.Worker + require Logger + alias Asciinema.Recordings + + @impl Oban.Worker + def perform(%Oban.Job{args: %{"id" => id}}) do + Recordings.upgrade(id) + Logger.info("recording #{id} upgraded") + + :ok + end + + def perform(_job) do + for recording <- Recordings.upgradable() do + Oban.insert!(__MODULE__.new(%{id: recording.id})) + end + + Logger.info("enqueued recording upgrade jobs") + + :ok + end +end diff --git a/lib/asciinema_web/controllers/api/asciicast_controller.ex b/lib/asciinema_web/controllers/api/recording_controller.ex similarity index 91% rename from lib/asciinema_web/controllers/api/asciicast_controller.ex rename to lib/asciinema_web/controllers/api/recording_controller.ex index 897a2bed9..01f2a608a 100644 --- a/lib/asciinema_web/controllers/api/asciicast_controller.ex +++ b/lib/asciinema_web/controllers/api/recording_controller.ex @@ -1,7 +1,7 @@ -defmodule AsciinemaWeb.Api.AsciicastController do +defmodule AsciinemaWeb.Api.RecordingController do use AsciinemaWeb, :controller import AsciinemaWeb.Auth, only: [get_basic_auth: 1, put_basic_auth: 3] - alias Asciinema.{Asciicasts, Accounts} + alias Asciinema.{Recordings, Accounts} alias Asciinema.Accounts.User plug :accepts, ~w(text json) @@ -23,9 +23,9 @@ defmodule AsciinemaWeb.Api.AsciicastController do user = conn.assigns.current_user user_agent = conn |> get_req_header("user-agent") |> List.first() - case Asciicasts.create_asciicast(user, params, %{user_agent: user_agent}) do + case Recordings.create_asciicast(user, params, %{user_agent: user_agent}) do {:ok, asciicast} -> - url = Routes.asciicast_url(conn, :show, asciicast) + url = Routes.recording_url(conn, :show, asciicast) conn |> put_status(:created) diff --git a/lib/asciinema_web/controllers/oembed_controller.ex b/lib/asciinema_web/controllers/oembed_controller.ex index 339400663..c2c26f90f 100644 --- a/lib/asciinema_web/controllers/oembed_controller.ex +++ b/lib/asciinema_web/controllers/oembed_controller.ex @@ -1,6 +1,6 @@ defmodule AsciinemaWeb.OembedController do use AsciinemaWeb, :controller - alias Asciinema.Asciicasts + alias Asciinema.Recordings plug :put_layout, nil @@ -9,7 +9,7 @@ defmodule AsciinemaWeb.OembedController do with path when is_binary(path) <- uri.path, [_, id] <- Regex.run(~r|^/a/([^/]+)$|, path), - {:ok, asciicast} <- Asciicasts.fetch_asciicast(id) do + {:ok, asciicast} <- Recordings.fetch_asciicast(id) do mw = if params["maxwidth"], do: String.to_integer(params["maxwidth"]) mh = if params["maxheight"], do: String.to_integer(params["maxheight"]) diff --git a/lib/asciinema_web/controllers/asciicast_controller.ex b/lib/asciinema_web/controllers/recording_controller.ex similarity index 87% rename from lib/asciinema_web/controllers/asciicast_controller.ex rename to lib/asciinema_web/controllers/recording_controller.ex index 405051fdd..18dcea60c 100644 --- a/lib/asciinema_web/controllers/asciicast_controller.ex +++ b/lib/asciinema_web/controllers/recording_controller.ex @@ -1,7 +1,7 @@ -defmodule AsciinemaWeb.AsciicastController do +defmodule AsciinemaWeb.RecordingController do use AsciinemaWeb, :controller - alias Asciinema.{Asciicasts, PngGenerator, Accounts} - alias Asciinema.Asciicasts.Asciicast + alias Asciinema.{Recordings, PngGenerator, Accounts} + alias Asciinema.Recordings.Asciicast plug :clear_main_class plug :load_asciicast when action in [:show, :edit, :update, :delete, :iframe] @@ -12,10 +12,10 @@ defmodule AsciinemaWeb.AsciicastController do category = params[:category] order = if params["order"] == "popularity", do: :popularity, else: :date - page = Asciicasts.paginate_asciicasts(category, order, params["page"], 12) + page = Recordings.paginate_asciicasts(category, order, params["page"], 12) assigns = [ - page_title: String.capitalize("#{category} asciicasts"), + page_title: String.capitalize("#{category} recordings"), category: category, sidebar_hidden: params[:sidebar_hidden], page: page, @@ -26,7 +26,7 @@ defmodule AsciinemaWeb.AsciicastController do end def auto(conn, params) do - case Asciicasts.count_featured_asciicasts() do + case Recordings.count_featured_asciicasts() do 0 -> index(conn, Map.merge(params, %{category: :public, sidebar_hidden: true})) @@ -58,11 +58,11 @@ defmodule AsciinemaWeb.AsciicastController do |> put_archival_info_flash(asciicast) |> render( "show.html", - page_title: AsciinemaWeb.AsciicastView.title(asciicast), + page_title: AsciinemaWeb.RecordingView.title(asciicast), asciicast: asciicast, playback_options: playback_options(conn.params), actions: asciicast_actions(asciicast, conn.assigns.current_user), - author_asciicasts: Asciicasts.other_public_asciicasts(asciicast) + author_asciicasts: Recordings.other_public_asciicasts(asciicast) ) end end @@ -145,18 +145,18 @@ defmodule AsciinemaWeb.AsciicastController do end def edit(conn, _params) do - changeset = Asciicasts.change_asciicast(conn.assigns.asciicast) + changeset = Recordings.change_asciicast(conn.assigns.asciicast) render(conn, "edit.html", changeset: changeset) end def update(conn, %{"asciicast" => asciicast_params}) do asciicast = conn.assigns.asciicast - case Asciicasts.update_asciicast(asciicast, asciicast_params) do + case Recordings.update_asciicast(asciicast, asciicast_params) do {:ok, asciicast} -> conn |> put_flash(:info, "Asciicast updated.") - |> redirect(to: Routes.asciicast_path(conn, :show, asciicast)) + |> redirect(to: Routes.recording_path(conn, :show, asciicast)) {:error, %Ecto.Changeset{} = changeset} -> render(conn, "edit.html", changeset: changeset) @@ -166,7 +166,7 @@ defmodule AsciinemaWeb.AsciicastController do def delete(conn, _params) do asciicast = conn.assigns.asciicast - case Asciicasts.delete_asciicast(asciicast) do + case Recordings.delete_asciicast(asciicast) do {:ok, _asciicast} -> conn |> put_flash(:info, "Asciicast deleted.") @@ -175,7 +175,7 @@ defmodule AsciinemaWeb.AsciicastController do {:error, _reason} -> conn |> put_flash(:error, "Oops, couldn't remove this asciicast.") - |> redirect(to: Routes.asciicast_path(conn, :show, asciicast)) + |> redirect(to: Routes.recording_path(conn, :show, asciicast)) end end @@ -213,14 +213,14 @@ defmodule AsciinemaWeb.AsciicastController do defp load_asciicast(conn, _) do id = String.trim(conn.params["id"]) - case Asciicasts.fetch_asciicast(id) do + case Recordings.fetch_asciicast(id) do {:ok, asciicast} -> public_id = to_string(asciicast.id) case {asciicast.private, get_format(conn), id == public_id} do {false, "html", false} -> conn - |> redirect(to: Routes.asciicast_path(conn, :show, asciicast)) + |> redirect(to: Routes.recording_path(conn, :show, asciicast)) |> halt() _ -> @@ -239,7 +239,7 @@ defmodule AsciinemaWeb.AsciicastController do case conn.req_cookies[key] do nil -> - Asciicasts.inc_views_count(asciicast) + Recordings.inc_views_count(asciicast) put_resp_cookie(conn, key, "1", max_age: 3600 * 24) _ -> @@ -274,7 +274,7 @@ defmodule AsciinemaWeb.AsciicastController do defp put_archival_info_flash(conn, asciicast) do with true <- asciicast.archivable, - days when not is_nil(days) <- Asciicasts.gc_days(), + days when not is_nil(days) <- Recordings.gc_days(), %{} = user <- asciicast.user, true <- Accounts.temporary_user?(user), true <- Timex.before?(asciicast.inserted_at, Timex.shift(Timex.now(), days: -days)) do @@ -292,6 +292,6 @@ defmodule AsciinemaWeb.AsciicastController do defp playback_options(params) do params |> Ext.Map.rename(%{"t" => "startAt", "i" => "idleTimeLimit"}) - |> Asciicasts.PlaybackOpts.parse() + |> Recordings.PlaybackOpts.parse() end end diff --git a/lib/asciinema_web/controllers/user_controller.ex b/lib/asciinema_web/controllers/user_controller.ex index 6b77e5bd6..2f08da051 100644 --- a/lib/asciinema_web/controllers/user_controller.ex +++ b/lib/asciinema_web/controllers/user_controller.ex @@ -2,7 +2,7 @@ defmodule AsciinemaWeb.UserController do use AsciinemaWeb, :controller alias Asciinema.Accounts alias Asciinema.Authorization, as: Authz - alias Asciinema.Asciicasts + alias Asciinema.Recordings alias AsciinemaWeb.Auth plug :clear_main_class @@ -63,7 +63,7 @@ defmodule AsciinemaWeb.UserController do end page = - Asciicasts.paginate_asciicasts( + Recordings.paginate_asciicasts( {user.id, filter}, :date, params["page"], diff --git a/lib/asciinema_web/router.ex b/lib/asciinema_web/router.ex index 962ed8258..f0fa0fa64 100644 --- a/lib/asciinema_web/router.ex +++ b/lib/asciinema_web/router.ex @@ -45,7 +45,7 @@ defmodule AsciinemaWeb.Router do scope "/", AsciinemaWeb do pipe_through :asciicast - resources "/a", AsciicastController, only: [:show, :edit, :update, :delete] + resources "/a", RecordingController, only: [:show, :edit, :update, :delete] end scope "/", AsciinemaWeb do @@ -58,14 +58,14 @@ defmodule AsciinemaWeb.Router do # Use the default browser stack pipe_through :browser - get "/", AsciicastController, :auto + get "/", RecordingController, :auto - get "/explore", AsciicastController, :auto, as: :explore - get "/explore/featured", AsciicastController, :featured, as: :explore - get "/explore/public", AsciicastController, :public, as: :explore + get "/explore", RecordingController, :auto, as: :explore + get "/explore/featured", RecordingController, :featured, as: :explore + get "/explore/public", RecordingController, :public, as: :explore - get "/a/:id/iframe", AsciicastController, :iframe - get "/a/:id/example", AsciicastController, :example + get "/a/:id/iframe", RecordingController, :iframe + get "/a/:id/example", RecordingController, :example get "/docs", DocController, :index get "/docs/:topic", DocController, :show @@ -89,7 +89,7 @@ defmodule AsciinemaWeb.Router do end scope "/api", AsciinemaWeb.Api, as: :api do - post "/asciicasts", AsciicastController, :create + post "/asciicasts", RecordingController, :create end scope "/dev" do @@ -132,7 +132,7 @@ defmodule AsciinemaWeb.Router.Helpers.Extra do end def asciicast_file_path(conn, asciicast) do - H.asciicast_path(conn, :show, asciicast) <> "." <> ext(asciicast) + H.recording_path(conn, :show, asciicast) <> "." <> ext(asciicast) end def asciicast_file_url(asciicast) do @@ -140,7 +140,7 @@ defmodule AsciinemaWeb.Router.Helpers.Extra do end def asciicast_file_url(conn, asciicast) do - H.asciicast_url(conn, :show, asciicast) <> "." <> ext(asciicast) + H.recording_url(conn, :show, asciicast) <> "." <> ext(asciicast) end defp ext(asciicast) do diff --git a/lib/asciinema_web/templates/asciicast/_card.html.eex b/lib/asciinema_web/templates/recording/_card.html.eex similarity index 89% rename from lib/asciinema_web/templates/asciicast/_card.html.eex rename to lib/asciinema_web/templates/recording/_card.html.eex index c8758d59c..05857db2f 100644 --- a/lib/asciinema_web/templates/asciicast/_card.html.eex +++ b/lib/asciinema_web/templates/recording/_card.html.eex @@ -1,5 +1,5 @@
- +
@@ -13,7 +13,7 @@

- <%= link title(@asciicast), to: Routes.asciicast_path(@conn, :show, @asciicast) %> + <%= link title(@asciicast), to: Routes.recording_path(@conn, :show, @asciicast) %> <%= if @asciicast.private do %> <%= render "_private_badge.html" %> diff --git a/lib/asciinema_web/templates/asciicast/_download_modal.html.eex b/lib/asciinema_web/templates/recording/_download_modal.html.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_download_modal.html.eex rename to lib/asciinema_web/templates/recording/_download_modal.html.eex diff --git a/lib/asciinema_web/templates/asciicast/_featured_badge.html.eex b/lib/asciinema_web/templates/recording/_featured_badge.html.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_featured_badge.html.eex rename to lib/asciinema_web/templates/recording/_featured_badge.html.eex diff --git a/lib/asciinema_web/templates/asciicast/_logo.svg.eex b/lib/asciinema_web/templates/recording/_logo.svg.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_logo.svg.eex rename to lib/asciinema_web/templates/recording/_logo.svg.eex diff --git a/lib/asciinema_web/templates/asciicast/_private_badge.html.eex b/lib/asciinema_web/templates/recording/_private_badge.html.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_private_badge.html.eex rename to lib/asciinema_web/templates/recording/_private_badge.html.eex diff --git a/lib/asciinema_web/templates/asciicast/_share_modal.html.eex b/lib/asciinema_web/templates/recording/_share_modal.html.eex similarity index 82% rename from lib/asciinema_web/templates/asciicast/_share_modal.html.eex rename to lib/asciinema_web/templates/recording/_share_modal.html.eex index 05467c920..04cc4e6cd 100644 --- a/lib/asciinema_web/templates/asciicast/_share_modal.html.eex +++ b/lib/asciinema_web/templates/recording/_share_modal.html.eex @@ -12,7 +12,7 @@

Link

- +

@@ -27,13 +27,13 @@

HTML:
- +

Markdown:
- +

Embed the player

diff --git a/lib/asciinema_web/templates/asciicast/_svg_256_colors.css.eex b/lib/asciinema_web/templates/recording/_svg_256_colors.css.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_svg_256_colors.css.eex rename to lib/asciinema_web/templates/recording/_svg_256_colors.css.eex diff --git a/lib/asciinema_web/templates/asciicast/_svg_theme_asciinema.css.eex b/lib/asciinema_web/templates/recording/_svg_theme_asciinema.css.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_svg_theme_asciinema.css.eex rename to lib/asciinema_web/templates/recording/_svg_theme_asciinema.css.eex diff --git a/lib/asciinema_web/templates/asciicast/_svg_theme_monokai.css.eex b/lib/asciinema_web/templates/recording/_svg_theme_monokai.css.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_svg_theme_monokai.css.eex rename to lib/asciinema_web/templates/recording/_svg_theme_monokai.css.eex diff --git a/lib/asciinema_web/templates/asciicast/_svg_theme_solarized-dark.css.eex b/lib/asciinema_web/templates/recording/_svg_theme_solarized-dark.css.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_svg_theme_solarized-dark.css.eex rename to lib/asciinema_web/templates/recording/_svg_theme_solarized-dark.css.eex diff --git a/lib/asciinema_web/templates/asciicast/_svg_theme_solarized-light.css.eex b/lib/asciinema_web/templates/recording/_svg_theme_solarized-light.css.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_svg_theme_solarized-light.css.eex rename to lib/asciinema_web/templates/recording/_svg_theme_solarized-light.css.eex diff --git a/lib/asciinema_web/templates/asciicast/_svg_theme_tango.css.eex b/lib/asciinema_web/templates/recording/_svg_theme_tango.css.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_svg_theme_tango.css.eex rename to lib/asciinema_web/templates/recording/_svg_theme_tango.css.eex diff --git a/lib/asciinema_web/templates/asciicast/_terminal.svg.eex b/lib/asciinema_web/templates/recording/_terminal.svg.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_terminal.svg.eex rename to lib/asciinema_web/templates/recording/_terminal.svg.eex diff --git a/lib/asciinema_web/templates/asciicast/_thumbnail.html.eex b/lib/asciinema_web/templates/recording/_thumbnail.html.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/_thumbnail.html.eex rename to lib/asciinema_web/templates/recording/_thumbnail.html.eex diff --git a/lib/asciinema_web/templates/asciicast/archived.html.eex b/lib/asciinema_web/templates/recording/archived.html.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/archived.html.eex rename to lib/asciinema_web/templates/recording/archived.html.eex diff --git a/lib/asciinema_web/templates/asciicast/edit.html.eex b/lib/asciinema_web/templates/recording/edit.html.eex similarity index 96% rename from lib/asciinema_web/templates/asciicast/edit.html.eex rename to lib/asciinema_web/templates/recording/edit.html.eex index 734dd3754..6e72f4371 100644 --- a/lib/asciinema_web/templates/asciicast/edit.html.eex +++ b/lib/asciinema_web/templates/recording/edit.html.eex @@ -1,8 +1,8 @@
- <%= form_for @changeset, Routes.asciicast_path(@conn, :update, @changeset.data), fn f -> %> - Asciicast settings + <%= form_for @changeset, Routes.recording_path(@conn, :update, @changeset.data), fn f -> %> + Recording settings
<%= label f, :title, class: "col-sm-4 col-md-3 col-lg-3 col-form-label" %> @@ -94,7 +94,7 @@

<%= submit "Save", class: "btn btn-primary" %> - <%= link "Cancel", to: Routes.asciicast_path(@conn, :show, @changeset.data), class: "btn" %> + <%= link "Cancel", to: Routes.recording_path(@conn, :show, @changeset.data), class: "btn" %>
<% end %> diff --git a/lib/asciinema_web/templates/asciicast/gif.html.heex b/lib/asciinema_web/templates/recording/gif.html.heex similarity index 100% rename from lib/asciinema_web/templates/asciicast/gif.html.heex rename to lib/asciinema_web/templates/recording/gif.html.heex diff --git a/lib/asciinema_web/templates/asciicast/iframe.html.eex b/lib/asciinema_web/templates/recording/iframe.html.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/iframe.html.eex rename to lib/asciinema_web/templates/recording/iframe.html.eex diff --git a/lib/asciinema_web/templates/asciicast/index.html.eex b/lib/asciinema_web/templates/recording/index.html.eex similarity index 100% rename from lib/asciinema_web/templates/asciicast/index.html.eex rename to lib/asciinema_web/templates/recording/index.html.eex diff --git a/lib/asciinema_web/templates/asciicast/meta.show.html.eex b/lib/asciinema_web/templates/recording/meta.show.html.eex similarity index 82% rename from lib/asciinema_web/templates/asciicast/meta.show.html.eex rename to lib/asciinema_web/templates/recording/meta.show.html.eex index cb0752a3b..43f7591aa 100644 --- a/lib/asciinema_web/templates/asciicast/meta.show.html.eex +++ b/lib/asciinema_web/templates/recording/meta.show.html.eex @@ -5,8 +5,8 @@ - - + + @@ -14,9 +14,9 @@ - + - + diff --git a/lib/asciinema_web/templates/asciicast/show.html.eex b/lib/asciinema_web/templates/recording/show.html.eex similarity index 92% rename from lib/asciinema_web/templates/asciicast/show.html.eex rename to lib/asciinema_web/templates/recording/show.html.eex index 3a642e787..b33ceb08f 100644 --- a/lib/asciinema_web/templates/asciicast/show.html.eex +++ b/lib/asciinema_web/templates/recording/show.html.eex @@ -45,27 +45,27 @@ <% end %> @@ -120,7 +120,7 @@
<%= for asciicast <- asciicasts do %>
- <%= render AsciinemaWeb.AsciicastView, "_card.html", conn: @conn, asciicast: asciicast %> + <%= render AsciinemaWeb.RecordingView, "_card.html", conn: @conn, asciicast: asciicast %>
<% end %>
diff --git a/lib/asciinema_web/templates/user/show.html.eex b/lib/asciinema_web/templates/user/show.html.eex index d49ae301d..71b3a5b73 100644 --- a/lib/asciinema_web/templates/user/show.html.eex +++ b/lib/asciinema_web/templates/user/show.html.eex @@ -26,15 +26,15 @@
<%= if @user_is_self do %> <%= if @asciicast_count > 0 do %> -

You have recorded <%= pluralize(@asciicast_count, "asciicast") %>

+

You have <%= pluralize(@asciicast_count, "recording") %>

<% else %> -

Record your first asciicast

+

Record your first session

<% end %> <% else %> <%= if @asciicast_count > 0 do %> -

<%= pluralize(@asciicast_count, "public asciicast") %> by <%= username(@user) %>

+

<%= pluralize(@asciicast_count, "public recording") %> by <%= username(@user) %>

<% else %> -

<%= username(@user) %> has no public asciicasts

+

<%= username(@user) %> has no public recordings

<% end %> <% end %> @@ -58,7 +58,7 @@

- If you have already recorded an asciicast but you don't see it + If you have already uploaded a recording but you don't see it here then associate it with your account by running asciinema auth in your terminal.

@@ -70,7 +70,7 @@
<%= for asciicast <- asciicasts do %>
- <%= render AsciinemaWeb.AsciicastView, "_card.html", conn: @conn, asciicast: asciicast %> + <%= render AsciinemaWeb.RecordingView, "_card.html", conn: @conn, asciicast: asciicast %>
<% end %>
diff --git a/lib/asciinema_web/views/api/asciicast_view.ex b/lib/asciinema_web/views/api/recording_view.ex similarity index 93% rename from lib/asciinema_web/views/api/asciicast_view.ex rename to lib/asciinema_web/views/api/recording_view.ex index 74c3e9b69..b4a45d5c1 100644 --- a/lib/asciinema_web/views/api/asciicast_view.ex +++ b/lib/asciinema_web/views/api/recording_view.ex @@ -1,4 +1,4 @@ -defmodule AsciinemaWeb.Api.AsciicastView do +defmodule AsciinemaWeb.Api.RecordingView do use AsciinemaWeb, :view def render("created.text", assigns) do @@ -24,7 +24,7 @@ defmodule AsciinemaWeb.Api.AsciicastView do """ is_tmp_user = Asciinema.Accounts.temporary_user?(conn.assigns.current_user) - gc_days = Asciinema.Asciicasts.gc_days() + gc_days = Asciinema.Recordings.gc_days() if is_tmp_user && gc_days do hostname = AsciinemaWeb.instance_hostname() diff --git a/lib/asciinema_web/views/oembed_view.ex b/lib/asciinema_web/views/oembed_view.ex index 33416c4fb..dbd576552 100644 --- a/lib/asciinema_web/views/oembed_view.ex +++ b/lib/asciinema_web/views/oembed_view.ex @@ -38,8 +38,8 @@ defmodule AsciinemaWeb.OembedView do max_height || image_height ) - asciicast_url = Routes.asciicast_url(Endpoint, :show, asciicast) - thumbnail_url = asciicast_url <> ".png" + recording_url = Routes.recording_url(Endpoint, :show, asciicast) + thumbnail_url = recording_url <> ".png" %{ type: "rich", @@ -52,15 +52,15 @@ defmodule AsciinemaWeb.OembedView do thumbnail_url: thumbnail_url, thumbnail_width: width, thumbnail_height: height, - html: html(asciicast_url, thumbnail_url, asciicast.title, width), + html: html(recording_url, thumbnail_url, asciicast.title, width), width: width, height: height } end - defp html(asciicast_url, thumbnail_url, title, width) do + defp html(recording_url, thumbnail_url, title, width) do safe = - content_tag(:a, href: asciicast_url, target: "_blank") do + content_tag(:a, href: recording_url, target: "_blank") do img_tag(thumbnail_url, alt: title, width: width) end diff --git a/lib/asciinema_web/views/asciicast_view.ex b/lib/asciinema_web/views/recording_view.ex similarity index 97% rename from lib/asciinema_web/views/asciicast_view.ex rename to lib/asciinema_web/views/recording_view.ex index 4ebeaa627..25ba2a35f 100644 --- a/lib/asciinema_web/views/asciicast_view.ex +++ b/lib/asciinema_web/views/recording_view.ex @@ -1,8 +1,8 @@ -defmodule AsciinemaWeb.AsciicastView do +defmodule AsciinemaWeb.RecordingView do use AsciinemaWeb, :view import Scrivener.HTML - alias Asciinema.Asciicasts - alias Asciinema.Asciicasts.Asciicast + alias Asciinema.Recordings + alias Asciinema.Recordings.Asciicast alias AsciinemaWeb.Endpoint alias AsciinemaWeb.Router.Helpers.Extra, as: RoutesX alias AsciinemaWeb.UserView @@ -69,7 +69,7 @@ defmodule AsciinemaWeb.AsciicastView do end def embed_script(asciicast) do - src = Routes.asciicast_url(Endpoint, :show, asciicast) <> ".js" + src = Routes.recording_url(Endpoint, :show, asciicast) <> ".js" id = "asciicast-#{Phoenix.Param.to_param(asciicast)}" content_tag(:script, [src: src, id: id, async: true], do: []) end @@ -82,7 +82,7 @@ defmodule AsciinemaWeb.AsciicastView do Routes.oembed_url( Endpoint, :show, - url: Routes.asciicast_url(Endpoint, :show, asciicast), + url: Routes.recording_url(Endpoint, :show, asciicast), format: format ) end @@ -274,11 +274,8 @@ defmodule AsciinemaWeb.AsciicastView do present?(asciicast.command) && asciicast.command != asciicast.shell -> asciicast.command - asciicast.private -> - "untitled" - true -> - "asciicast:#{asciicast.id}" + "untitled" end end @@ -580,11 +577,11 @@ defmodule AsciinemaWeb.AsciicastView do end def asciicast_gc_days do - Asciicasts.gc_days() + Recordings.gc_days() end def terminal_font_family_options do - for family <- Asciicasts.custom_terminal_font_families() do + for family <- Recordings.custom_terminal_font_families() do case family do "FiraCode Nerd Font" -> {"Nerd Font - Fira Code", family} "JetBrainsMono Nerd Font" -> {"Nerd Font - JetBrains Mono", family} diff --git a/priv/repo/migrations/20211212114046_insert_upgrade_jobs.exs b/priv/repo/migrations/20211212114046_insert_upgrade_jobs.exs index 5bbcabb96..a61e929f5 100644 --- a/priv/repo/migrations/20211212114046_insert_upgrade_jobs.exs +++ b/priv/repo/migrations/20211212114046_insert_upgrade_jobs.exs @@ -8,7 +8,7 @@ defmodule Asciinema.Repo.Migrations.InsertUpgradeJobs do {:ok, _} = Multi.new() |> Multi.insert(:seed, job(U.InitialSeed)) - |> Multi.insert(:asciicasts, job(U.UpgradeAsciicasts)) + |> Multi.insert(:asciicasts, job(U.UpgradeRecordings)) |> Repo.transaction() end diff --git a/priv/repo/seeds.exs b/priv/repo/seeds.exs index a26f2aa4c..1ad314897 100644 --- a/priv/repo/seeds.exs +++ b/priv/repo/seeds.exs @@ -11,4 +11,4 @@ # and so on) as they will fail if something goes wrong. user = Asciinema.Accounts.ensure_asciinema_user() -Asciinema.Asciicasts.ensure_welcome_asciicast(user) +Asciinema.Recordings.ensure_welcome_asciicast(user) diff --git a/test/asciinema/asciicasts_test.exs b/test/asciinema/recordings_test.exs similarity index 86% rename from test/asciinema/asciicasts_test.exs rename to test/asciinema/recordings_test.exs index d34b7a861..85df88f24 100644 --- a/test/asciinema/asciicasts_test.exs +++ b/test/asciinema/recordings_test.exs @@ -1,8 +1,8 @@ -defmodule Asciinema.AsciicastsTest do +defmodule Asciinema.RecordingsTest do use Asciinema.DataCase import Asciinema.Factory - alias Asciinema.Asciicasts - alias Asciinema.Asciicasts.Asciicast + alias Asciinema.Recordings + alias Asciinema.Recordings.Asciicast describe "create_asciicast/3" do test "pre-v1 payload with uname" do @@ -24,7 +24,7 @@ defmodule Asciinema.AsciicastsTest do fixture(:upload, %{path: "0.9.7/stdout.time", content_type: "application/octet-stream"}) } - {:ok, asciicast} = Asciicasts.create_asciicast(user, params, %{user_agent: "a/user/agent"}) + {:ok, asciicast} = Recordings.create_asciicast(user, params, %{user_agent: "a/user/agent"}) assert %Asciicast{ version: 2, @@ -60,7 +60,7 @@ defmodule Asciinema.AsciicastsTest do fixture(:upload, %{path: "0.9.8/stdout.time", content_type: "application/octet-stream"}) } - {:ok, asciicast} = Asciicasts.create_asciicast(user, params, %{user_agent: "a/user/agent"}) + {:ok, asciicast} = Recordings.create_asciicast(user, params, %{user_agent: "a/user/agent"}) assert %Asciicast{ version: 2, @@ -99,8 +99,8 @@ defmodule Asciinema.AsciicastsTest do }) } - {:ok, asciicast} = Asciicasts.create_asciicast(user, params, %{user_agent: "a/user/agent"}) - stream = Asciicasts.stdout_stream(asciicast) + {:ok, asciicast} = Recordings.create_asciicast(user, params, %{user_agent: "a/user/agent"}) + stream = Recordings.stdout_stream(asciicast) assert :ok == Stream.run(stream) assert [{1.234567, "xxżó"}, {1.358023, "łć"}, {3.358023, "xx"}] == Enum.take(stream, 3) @@ -110,7 +110,7 @@ defmodule Asciinema.AsciicastsTest do user = fixture(:user) upload = fixture(:upload, %{path: "1/asciicast.json"}) - {:ok, asciicast} = Asciicasts.create_asciicast(user, upload, %{user_agent: "a/user/agent"}) + {:ok, asciicast} = Recordings.create_asciicast(user, upload, %{user_agent: "a/user/agent"}) assert %Asciicast{ version: 1, @@ -132,21 +132,21 @@ defmodule Asciinema.AsciicastsTest do user = fixture(:user) upload = fixture(:upload, %{path: "1/invalid.json"}) - assert {:error, %Ecto.Changeset{}} = Asciicasts.create_asciicast(user, upload) + assert {:error, %Ecto.Changeset{}} = Recordings.create_asciicast(user, upload) end test "json file, unsupported version number" do user = fixture(:user) upload = fixture(:upload, %{path: "5/asciicast.json"}) - assert {:error, {:unsupported_format, 5}} = Asciicasts.create_asciicast(user, upload) + assert {:error, {:unsupported_format, 5}} = Recordings.create_asciicast(user, upload) end test "cast file, v2 format, minimal" do user = fixture(:user) upload = fixture(:upload, %{path: "2/minimal.cast"}) - {:ok, asciicast} = Asciicasts.create_asciicast(user, upload, %{user_agent: "a/user/agent"}) + {:ok, asciicast} = Recordings.create_asciicast(user, upload, %{user_agent: "a/user/agent"}) assert %Asciicast{ version: 2, @@ -173,7 +173,7 @@ defmodule Asciinema.AsciicastsTest do user = fixture(:user) upload = fixture(:upload, %{path: "2/full.cast"}) - {:ok, asciicast} = Asciicasts.create_asciicast(user, upload, %{user_agent: "a/user/agent"}) + {:ok, asciicast} = Recordings.create_asciicast(user, upload, %{user_agent: "a/user/agent"}) assert %Asciicast{ version: 2, @@ -201,35 +201,35 @@ defmodule Asciinema.AsciicastsTest do user = fixture(:user) upload = fixture(:upload, %{path: "new-logo-bars.png"}) - assert {:error, :unknown_format} = Asciicasts.create_asciicast(user, upload) + assert {:error, :unknown_format} = Recordings.create_asciicast(user, upload) end end describe "delete_asciicast/1" do test "v1/v2" do asciicast = insert(:asciicast_v1) |> with_file() - assert {:ok, _asciicast} = Asciicasts.delete_asciicast(asciicast) + assert {:ok, _asciicast} = Recordings.delete_asciicast(asciicast) asciicast = insert(:asciicast_v2) |> with_file() - assert {:ok, _asciicast} = Asciicasts.delete_asciicast(asciicast) + assert {:ok, _asciicast} = Recordings.delete_asciicast(asciicast) end end describe "stdout_stream/1" do test "with asciicast v1 file" do - stream = Asciicasts.stdout_stream("test/fixtures/1/asciicast.json") + stream = Recordings.stdout_stream("test/fixtures/1/asciicast.json") assert :ok == Stream.run(stream) assert [{1.234567, "foo bar"}, {6.913554, "baz qux"}] == Enum.take(stream, 2) end test "with asciicast v2 file" do - stream = Asciicasts.stdout_stream("test/fixtures/2/minimal.cast") + stream = Recordings.stdout_stream("test/fixtures/2/minimal.cast") assert :ok == Stream.run(stream) assert [{1.234567, "foo bar"}, {5.678987, "baz qux"}] == Enum.take(stream, 2) end test "with asciicast v2 file, with idle_time_limit" do - stream = Asciicasts.stdout_stream("test/fixtures/2/full.cast") + stream = Recordings.stdout_stream("test/fixtures/2/full.cast") assert :ok == Stream.run(stream) assert [{1.234567, "foo bar"}, {3.734567, "baz qux"}, {6.234567, "żółć jaźń"}] == @@ -237,7 +237,7 @@ defmodule Asciinema.AsciicastsTest do end test "with asciicast v2 file, with blank lines" do - stream = Asciicasts.stdout_stream("test/fixtures/2/with-blank-lines.cast") + stream = Recordings.stdout_stream("test/fixtures/2/with-blank-lines.cast") assert :ok == Stream.run(stream) assert [{1.234567, "foo bar"}, {5.678987, "baz qux"}, {8.456789, "żółć jaźń"}] == @@ -248,7 +248,7 @@ defmodule Asciinema.AsciicastsTest do describe "stdout_stream/2" do test "with gzipped files" do stream = - Asciicasts.stdout_stream( + Recordings.stdout_stream( {"test/fixtures/0.9.9/stdout.time", "test/fixtures/0.9.9/stdout"} ) @@ -258,7 +258,7 @@ defmodule Asciinema.AsciicastsTest do test "with bzipped files" do stream = - Asciicasts.stdout_stream( + Recordings.stdout_stream( {"test/fixtures/0.9.8/stdout.time", "test/fixtures/0.9.8/stdout"} ) @@ -268,7 +268,7 @@ defmodule Asciinema.AsciicastsTest do test "with bzipped files (utf-8 sequence split between frames)" do stream = - Asciicasts.stdout_stream( + Recordings.stdout_stream( {"test/fixtures/0.9.8/stdout-split.time", "test/fixtures/0.9.8/stdout-split"} ) @@ -281,7 +281,7 @@ defmodule Asciinema.AsciicastsTest do @tag :vt test "returns list of screen lines" do stdout_stream = [{1.0, "a"}, {2.4, "b"}, {2.6, "c"}] - snapshot = Asciicasts.generate_snapshot(stdout_stream, 4, 2, 2.5) + snapshot = Recordings.generate_snapshot(stdout_stream, 4, 2, 2.5) assert snapshot == [[["ab", %{}], [" ", %{"inverse" => true}], [" ", %{}]], [[" ", %{}]]] end end @@ -291,8 +291,8 @@ defmodule Asciinema.AsciicastsTest do asciicast_v1 = insert(:asciicast_v1) asciicast_v2 = insert(:asciicast_v2) - assert ^asciicast_v1 = Asciicasts.upgrade(asciicast_v1) - assert ^asciicast_v2 = Asciicasts.upgrade(asciicast_v2) + assert ^asciicast_v1 = Recordings.upgrade(asciicast_v1) + assert ^asciicast_v2 = Recordings.upgrade(asciicast_v2) end test "converts v0 file to v2" do @@ -300,16 +300,16 @@ defmodule Asciinema.AsciicastsTest do stream_v0 = asciicast - |> Asciicasts.stdout_stream() + |> Recordings.stdout_stream() |> Enum.to_list() - asciicast = Asciicasts.upgrade(asciicast) + asciicast = Recordings.upgrade(asciicast) assert asciicast.version == 2 assert asciicast.path =~ ~r|\d\d/\d\d/#{asciicast.id}\.cast$| stream_v2 = asciicast - |> Asciicasts.stdout_stream() + |> Recordings.stdout_stream() |> Enum.to_list() assert stream_v0 == stream_v2 diff --git a/test/controllers/api/asciicast_controller_test.exs b/test/controllers/api/recording_controller_test.exs similarity index 75% rename from test/controllers/api/asciicast_controller_test.exs rename to test/controllers/api/recording_controller_test.exs index b85c344d8..8e8e54fe4 100644 --- a/test/controllers/api/asciicast_controller_test.exs +++ b/test/controllers/api/recording_controller_test.exs @@ -1,4 +1,4 @@ -defmodule Asciinema.Api.AsciicastControllerTest do +defmodule Asciinema.Api.RecordingControllerTest do use AsciinemaWeb.ConnCase alias Asciinema.Accounts @@ -15,7 +15,7 @@ defmodule Asciinema.Api.AsciicastControllerTest do {:ok, conn: conn, token: token} end - @asciicast_url ~r|^http://localhost:4001/a/[a-zA-Z0-9]{25}| + @recording_url ~r|^http://localhost:4001/a/[a-zA-Z0-9]{25}| @successful_response ~r|View.+at.+http://localhost:4001/a/[a-zA-Z0-9]{25}\n|s describe ".create" do @@ -29,9 +29,9 @@ defmodule Asciinema.Api.AsciicastControllerTest do fixture(:upload, %{path: "0.9.7/stdout.time", content_type: "application/octet-stream"}) } - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => asciicast} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => asciicast} assert text_response(conn, 201) =~ @successful_response - assert List.first(get_resp_header(conn, "location")) =~ @asciicast_url + assert List.first(get_resp_header(conn, "location")) =~ @recording_url end @tag token: nil @@ -44,9 +44,9 @@ defmodule Asciinema.Api.AsciicastControllerTest do fixture(:upload, %{path: "0.9.8/stdout.time", content_type: "application/octet-stream"}) } - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => asciicast} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => asciicast} assert text_response(conn, 201) =~ @successful_response - assert List.first(get_resp_header(conn, "location")) =~ @asciicast_url + assert List.first(get_resp_header(conn, "location")) =~ @recording_url end test "separate files (pre-v1 params), v0.9.9 client", %{conn: conn} do @@ -58,55 +58,55 @@ defmodule Asciinema.Api.AsciicastControllerTest do fixture(:upload, %{path: "0.9.9/stdout.time", content_type: "application/octet-stream"}) } - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => asciicast} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => asciicast} assert text_response(conn, 201) =~ @successful_response - assert List.first(get_resp_header(conn, "location")) =~ @asciicast_url + assert List.first(get_resp_header(conn, "location")) =~ @recording_url end test "json file, v1 format", %{conn: conn} do upload = fixture(:upload, %{path: "1/asciicast.json"}) - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert text_response(conn, 201) =~ @successful_response - assert List.first(get_resp_header(conn, "location")) =~ @asciicast_url + assert List.first(get_resp_header(conn, "location")) =~ @recording_url end test "json file, v2 format", %{conn: conn} do upload = fixture(:upload, %{path: "2/minimal.cast"}) - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert text_response(conn, 201) =~ @successful_response - assert List.first(get_resp_header(conn, "location")) =~ @asciicast_url + assert List.first(get_resp_header(conn, "location")) =~ @recording_url end test "json file, v1 format (missing required data)", %{conn: conn} do upload = fixture(:upload, %{path: "1/invalid.json"}) - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert %{"errors" => _} = json_response(conn, 422) end test "json file, unsupported version number", %{conn: conn} do upload = fixture(:upload, %{path: "5/asciicast.json"}) - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert text_response(conn, 422) =~ ~r|not supported| end test "non-json file", %{conn: conn} do upload = fixture(:upload, %{path: "new-logo-bars.png"}) - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert text_response(conn, 400) =~ ~r|valid asciicast| end test "existing user (API token)", %{conn: conn, token: token} do {:ok, _} = Accounts.create_user_with_api_token(token, "test") upload = fixture(:upload, %{path: "1/asciicast.json"}) - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert text_response(conn, 201) =~ @successful_response - assert List.first(get_resp_header(conn, "location")) =~ @asciicast_url + assert List.first(get_resp_header(conn, "location")) =~ @recording_url end @tag token: nil test "no authentication", %{conn: conn} do upload = fixture(:upload, %{path: "1/asciicast.json"}) - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert response(conn, 401) end @@ -115,23 +115,23 @@ defmodule Asciinema.Api.AsciicastControllerTest do Accounts.get_user_with_api_token(token, "test") token |> Accounts.get_api_token!() |> Accounts.revoke_api_token!() upload = fixture(:upload, %{path: "1/asciicast.json"}) - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert response(conn, 401) end @tag token: "invalid-lol" test "authentication with invalid token", %{conn: conn} do upload = fixture(:upload, %{path: "1/asciicast.json"}) - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert response(conn, 401) end test "requesting json response", %{conn: conn} do upload = fixture(:upload, %{path: "2/minimal.cast"}) conn = put_req_header(conn, "accept", "application/json") - conn = post conn, Routes.api_asciicast_path(conn, :create), %{"asciicast" => upload} + conn = post conn, Routes.api_recording_path(conn, :create), %{"asciicast" => upload} assert %{"url" => "http" <> _} = json_response(conn, 201) - assert List.first(get_resp_header(conn, "location")) =~ @asciicast_url + assert List.first(get_resp_header(conn, "location")) =~ @recording_url end end end diff --git a/test/controllers/oembed_controller_test.exs b/test/controllers/oembed_controller_test.exs index 79ff45f94..c5b79d753 100644 --- a/test/controllers/oembed_controller_test.exs +++ b/test/controllers/oembed_controller_test.exs @@ -6,7 +6,7 @@ defmodule Asciinema.OembedControllerTest do describe "show" do test "for JSON format", %{conn: conn} do asciicast = insert(:asciicast) - url = Routes.asciicast_url(Endpoint, :show, asciicast) + url = Routes.recording_url(Endpoint, :show, asciicast) conn = get( @@ -25,7 +25,7 @@ defmodule Asciinema.OembedControllerTest do test "for XML format", %{conn: conn} do asciicast = insert(:asciicast) - url = Routes.asciicast_url(Endpoint, :show, asciicast) + url = Routes.recording_url(Endpoint, :show, asciicast) conn = get(conn, Routes.oembed_path(conn, :show, url: url, format: "xml")) @@ -35,7 +35,7 @@ defmodule Asciinema.OembedControllerTest do test "for maxwidth without maxheight", %{conn: conn} do asciicast = insert(:asciicast) - url = Routes.asciicast_url(Endpoint, :show, asciicast) + url = Routes.recording_url(Endpoint, :show, asciicast) conn = get(conn, Routes.oembed_path(conn, :show, url: url, format: "json", maxwidth: "500")) diff --git a/test/controllers/asciicast_controller_test.exs b/test/controllers/recording_controller_test.exs similarity index 87% rename from test/controllers/asciicast_controller_test.exs rename to test/controllers/recording_controller_test.exs index b3e6ce127..fcff84ef2 100644 --- a/test/controllers/asciicast_controller_test.exs +++ b/test/controllers/recording_controller_test.exs @@ -1,4 +1,4 @@ -defmodule Asciinema.AsciicastControllerTest do +defmodule Asciinema.RecordingControllerTest do use AsciinemaWeb.ConnCase import Asciinema.Factory @@ -38,7 +38,7 @@ defmodule Asciinema.AsciicastControllerTest do describe "show" do test "HTML", %{conn: conn} do asciicast = insert(:asciicast, title: "Good stuff") - url = Routes.asciicast_path(conn, :show, asciicast) + url = Routes.recording_path(conn, :show, asciicast) conn_2 = get(conn, url) assert html_response(conn_2, 200) =~ "Good stuff" @@ -71,7 +71,7 @@ defmodule Asciinema.AsciicastControllerTest do @tag :rsvg test "PNG", %{conn: conn} do asciicast = insert(:asciicast) - url = Routes.asciicast_path(conn, :show, asciicast) + url = Routes.recording_path(conn, :show, asciicast) conn_2 = get(conn, url <> ".png") assert response(conn_2, 200) @@ -84,7 +84,7 @@ defmodule Asciinema.AsciicastControllerTest do test "SVG", %{conn: conn} do asciicast = insert(:asciicast) - url = Routes.asciicast_path(conn, :show, asciicast) + url = Routes.recording_path(conn, :show, asciicast) conn_2 = get(conn, url <> ".svg") assert response(conn_2, 200) @@ -101,14 +101,14 @@ defmodule Asciinema.AsciicastControllerTest do test "HTML with GIF generation instructions", %{conn: conn} do asciicast = insert(:asciicast) - conn = get(conn, Routes.asciicast_path(conn, :show, asciicast) <> ".gif") + conn = get(conn, Routes.recording_path(conn, :show, asciicast) <> ".gif") assert html_response(conn, 200) =~ "GIF" assert response_content_type(conn, :html) end test "embed JS", %{conn: conn} do asciicast = insert(:asciicast) - url = Routes.asciicast_path(conn, :show, asciicast) + url = Routes.recording_path(conn, :show, asciicast) conn_2 = get(conn, url <> ".js") assert response(conn_2, 200) @@ -121,7 +121,7 @@ defmodule Asciinema.AsciicastControllerTest do test "embed iframe", %{conn: conn} do asciicast = fixture(:asciicast) - conn = get(conn, Routes.asciicast_path(conn, :iframe, asciicast)) + conn = get(conn, Routes.recording_path(conn, :iframe, asciicast)) assert html_response(conn, 200) =~ ~r/iframe\.css/ assert html_response(conn, 200) =~ ~r/iframe\.js/ assert html_response(conn, 200) =~ ~r/window\.players\.set/ @@ -139,7 +139,7 @@ defmodule Asciinema.AsciicastControllerTest do end test "requires logged in user", %{conn: conn, asciicast: asciicast} do - conn = get(conn, Routes.asciicast_path(conn, :edit, asciicast)) + conn = get(conn, Routes.recording_path(conn, :edit, asciicast)) assert redirected_to(conn, 302) == "/login/new" end @@ -147,14 +147,14 @@ defmodule Asciinema.AsciicastControllerTest do conn = log_in(conn, insert(:user)) assert_raise(Asciinema.Authorization.ForbiddenError, fn -> - get(conn, Routes.asciicast_path(conn, :edit, asciicast)) + get(conn, Routes.recording_path(conn, :edit, asciicast)) end) end test "displays form", %{conn: conn, asciicast: asciicast, user: user} do conn = log_in(conn, user) - conn = get(conn, Routes.asciicast_path(conn, :edit, asciicast)) + conn = get(conn, Routes.recording_path(conn, :edit, asciicast)) assert html_response(conn, 200) =~ "Save" end @@ -163,7 +163,7 @@ defmodule Asciinema.AsciicastControllerTest do conn = log_in(conn, user) attrs = %{asciicast: %{title: "Haha!"}} - conn = put conn, Routes.asciicast_path(conn, :update, asciicast), attrs + conn = put conn, Routes.recording_path(conn, :update, asciicast), attrs location = List.first(get_resp_header(conn, "location")) assert get_flash(conn, :info) =~ ~r/updated/i @@ -189,19 +189,19 @@ defmodule Asciinema.AsciicastControllerTest do conn = log_in(conn, insert(:user)) assert_raise(Asciinema.Authorization.ForbiddenError, fn -> - delete(conn, Routes.asciicast_path(conn, :delete, asciicast)) + delete(conn, Routes.recording_path(conn, :delete, asciicast)) end) end test "removes and redirects", %{conn: conn, asciicast: asciicast, user: user} do conn = log_in(conn, user) - conn = delete(conn, Routes.asciicast_path(conn, :delete, asciicast)) + conn = delete(conn, Routes.recording_path(conn, :delete, asciicast)) assert get_flash(conn, :info) =~ ~r/deleted/i assert response(conn, 302) - conn = get(build_conn(), Routes.asciicast_path(conn, :show, asciicast)) + conn = get(build_conn(), Routes.recording_path(conn, :show, asciicast)) assert html_response(conn, 404) =~ ~r/not found/i end end diff --git a/test/controllers/user_controller_test.exs b/test/controllers/user_controller_test.exs index dfc0589b4..62ae31368 100644 --- a/test/controllers/user_controller_test.exs +++ b/test/controllers/user_controller_test.exs @@ -78,7 +78,7 @@ defmodule Asciinema.UserControllerTest do conn = get(conn, "/~dracula3000") html = html_response(conn, 200) - assert html =~ "2 asciicasts" + assert html =~ "2 recordings" assert html =~ "Public stuff" assert html =~ "Private stuff" end diff --git a/test/support/factory.ex b/test/support/factory.ex index 166ad2e16..7f0ec275b 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -1,7 +1,7 @@ defmodule Asciinema.Factory do use ExMachina.Ecto, repo: Asciinema.Repo alias Asciinema.Accounts.User - alias Asciinema.Asciicasts.Asciicast + alias Asciinema.Recordings.Asciicast alias Asciinema.FileStore def user_factory do diff --git a/test/support/fixtures.ex b/test/support/fixtures.ex index e481651de..685692c0d 100644 --- a/test/support/fixtures.ex +++ b/test/support/fixtures.ex @@ -1,5 +1,5 @@ defmodule Asciinema.Fixtures do - alias Asciinema.{Repo, Asciicasts} + alias Asciinema.{Repo, Recordings} alias Asciinema.Accounts.User def fixture(what, attrs \\ %{}) @@ -49,14 +49,14 @@ defmodule Asciinema.Fixtures do def fixture(:asciicast_v1, _attrs) do user = fixture(:user) upload = fixture(:upload_v1) - {:ok, asciicast} = Asciicasts.create_asciicast(user, upload) + {:ok, asciicast} = Recordings.create_asciicast(user, upload) asciicast end def fixture(:asciicast_v2, _attrs) do user = fixture(:user) upload = fixture(:upload_v2) - {:ok, asciicast} = Asciicasts.create_asciicast(user, upload) + {:ok, asciicast} = Recordings.create_asciicast(user, upload) asciicast end end diff --git a/test/views/asciicast_view_test.exs b/test/views/recording_view_test.exs similarity index 92% rename from test/views/asciicast_view_test.exs rename to test/views/recording_view_test.exs index d032faed2..8ddf01478 100644 --- a/test/views/asciicast_view_test.exs +++ b/test/views/recording_view_test.exs @@ -1,11 +1,11 @@ -defmodule Asciinema.AsciicastViewTest do +defmodule Asciinema.RecordingViewTest do use AsciinemaWeb.ConnCase, async: true - alias AsciinemaWeb.AsciicastView - alias Asciinema.Asciicasts.Asciicast + alias AsciinemaWeb.RecordingView + alias Asciinema.Recordings.Asciicast def thumbnail_from(snapshot, w, h) do asciicast = %Asciicast{snapshot: snapshot} - AsciicastView.thumbnail(asciicast, w, h) + RecordingView.thumbnail(asciicast, w, h) end describe "thumbnail/3" do From 6328ab8d60e98a57e77903eb9378174df3a9a96a Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 15 May 2023 16:33:47 +0200 Subject: [PATCH 7/7] Display user's other recordings in 2 columns instead of 3 --- lib/asciinema/recordings/recordings.ex | 2 +- lib/asciinema_web/templates/recording/show.html.eex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/asciinema/recordings/recordings.ex b/lib/asciinema/recordings/recordings.ex index 6efc7587b..099bd73d5 100644 --- a/lib/asciinema/recordings/recordings.ex +++ b/lib/asciinema/recordings/recordings.ex @@ -42,7 +42,7 @@ defmodule Asciinema.Recordings do |> Repo.preload(:user) end - def other_public_asciicasts(asciicast, limit \\ 3) do + def other_public_asciicasts(asciicast, limit \\ 4) do Asciicast |> filter({asciicast.user_id, :public}) |> where([a], a.id != ^asciicast.id) diff --git a/lib/asciinema_web/templates/recording/show.html.eex b/lib/asciinema_web/templates/recording/show.html.eex index b33ceb08f..0c8aad8db 100644 --- a/lib/asciinema_web/templates/recording/show.html.eex +++ b/lib/asciinema_web/templates/recording/show.html.eex @@ -119,7 +119,7 @@
<%= for asciicast <- asciicasts do %> -
+
<%= render AsciinemaWeb.RecordingView, "_card.html", conn: @conn, asciicast: asciicast %>
<% end %>