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 97% rename from assets/css/_asciicast_card.scss rename to assets/css/_recording_card.scss index ac970e99c..29f09d817 100644 --- a/assets/css/_asciicast_card.scss +++ b/assets/css/_recording_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/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/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/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 77% rename from lib/asciinema/asciicasts/asciicast.ex rename to lib/asciinema/recordings/asciicast.ex index b04e434b8..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" @@ -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/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..099bd73d5 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 [ @@ -42,7 +42,7 @@ defmodule Asciinema.Asciicasts 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) @@ -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/_thumbnail.html.eex b/lib/asciinema_web/templates/asciicast/_thumbnail.html.eex deleted file mode 100644 index 287e239df..000000000 --- a/lib/asciinema_web/templates/asciicast/_thumbnail.html.eex +++ /dev/null @@ -1,5 +0,0 @@ -
<%= for line <- thumbnail(@asciicast) do %><%= for {text, attrs} <- line do %><%= text %><% end %><% end %>
-