Skip to content

Commit

Permalink
Rename Asciicasts context to Recordings
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed May 15, 2023
1 parent 7f90b31 commit 51fd756
Show file tree
Hide file tree
Showing 63 changed files with 219 additions and 222 deletions.
4 changes: 2 additions & 2 deletions .iex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
2 changes: 1 addition & 1 deletion assets/css/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ body, main {
background-color: #f7f7f7;
}

.c-asciicast {
.c-recording {
main {
h1, h2, h3 {
margin-top: 2rem;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.c-asciicast {
.c-recording {
&.a-category {
main {
.nav {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.c-asciicast.a-show {
.c-recording.a-show {
section.info {
small {
font-size: 14px;
Expand Down
8 changes: 4 additions & 4 deletions assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/asciinema.ex
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/asciinema/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions lib/asciinema/asciicasts/snapshot_updater/sync.ex

This file was deleted.

2 changes: 1 addition & 1 deletion lib/asciinema/authorization.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/asciinema/gc.ex
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/asciinema/png_generator.ex
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
2 changes: 1 addition & 1 deletion lib/asciinema/png_generator/rsvg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Asciinema.Asciicasts.PlaybackOpts do
defmodule Asciinema.Recordings.PlaybackOpts do
use Ecto.Schema
import Ecto.Changeset

Expand Down
Original file line number Diff line number Diff line change
@@ -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 [
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Asciinema.Asciicasts.SnapshotUpdater.Noop do
defmodule Asciinema.Recordings.SnapshotUpdater.Noop do
def update_snapshot(_asciicast) do
:ok
end
Expand Down
9 changes: 9 additions & 0 deletions lib/asciinema/recordings/snapshot_updater/sync.ex
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/asciinema/upgrades/initial_seed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
23 changes: 0 additions & 23 deletions lib/asciinema/upgrades/upgrade_asciicasts.ex

This file was deleted.

23 changes: 23 additions & 0 deletions lib/asciinema/upgrades/upgrade_recordings.ex
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/asciinema_web/controllers/oembed_controller.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule AsciinemaWeb.OembedController do
use AsciinemaWeb, :controller
alias Asciinema.Asciicasts
alias Asciinema.Recordings

plug :put_layout, nil

Expand All @@ -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"])

Expand Down
Loading

0 comments on commit 51fd756

Please sign in to comment.