Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed May 31, 2023
2 parents 27b79c8 + 6328ab8 commit 68e6b75
Show file tree
Hide file tree
Showing 68 changed files with 329 additions and 246 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
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
24 changes: 12 additions & 12 deletions assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand All @@ -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
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 @@ -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)
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.

Loading

0 comments on commit 68e6b75

Please sign in to comment.