Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Nov 20, 2023
2 parents c8d0806 + 779220a commit 9dcbba9
Show file tree
Hide file tree
Showing 53 changed files with 709 additions and 355 deletions.
8 changes: 8 additions & 0 deletions .env.production.sample
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ MAILNAME=localhost
# AWS_SECRET_ACCESS_KEY=
# S3_BUCKET=my-asciinema-bucket
# S3_REGION=us-east-1

### File cache

## Location of local cache directory used for storing .txt versions of the
## recordings, local copy of .cast files when S3 file store is used above,
## and other cached items.
#Default: /var/cache/asciinema
#FILE_CACHE_PATH=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ npm-debug.log
/config/custom.exs
/priv/native
/uploads/*
/cache
/volumes
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ RUN apk upgrade && \
mix local.rebar --force && \
mix local.hex --force

COPY native native/
RUN cd native/vt_nif && cargo build -r

COPY mix.* ./
RUN mix do deps.get --only prod, deps.compile

Expand All @@ -37,7 +40,6 @@ RUN mix phx.digest
COPY config/*.exs config/
COPY lib lib/
COPY priv priv/
COPY native native/

# recompile sentry with our source code
RUN mix deps.compile sentry --force
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ at [asciinema/asciinema](https://github.com/asciinema/asciinema), and the source
code of asciinema web player
at [asciinema/asciinema-player](https://github.com/asciinema/asciinema-player).

Shout-out to our Platinum [sponsors](https://github.com/sponsors/ku1ik), whose
financial support helps keep the project alive:

[<img src="./assets/static/images/sponsor-logos/dashcam/logo-on-light.png" width="200" />](https://dashcam.io?utm_source=asciinemagithub)

## Setting up your own asciinema web app instance

asciinema terminal recorder uses [asciinema.org](https://asciinema.org) as its
Expand Down Expand Up @@ -41,6 +46,13 @@ If you find anything that looks like a potential vulnerability please
read on
[how to report a security issue](https://github.com/asciinema/asciinema-server/blob/main/CONTRIBUTING.md#reporting-security-issues).

## Sponsors

asciinema is sponsored by:

- [**Dashcam**](https://dashcam.io?utm_source=asciinemagithub)
- [Brightbox](https://www.brightbox.com/)

## Consulting

I offer consulting services for asciinema project. See https://asciinema.org/consulting for more information.
Expand Down
12 changes: 12 additions & 0 deletions assets/css/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ body pre {
border-color: #ddd;
}

.modal-dialog pre {
background-color: #f7f7f7;
margin-bottom: 1rem;
}

.has-error .form-control {
border-color: #dc3545;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
Expand All @@ -190,3 +195,10 @@ body pre {
.form-control::placeholder {
color: #959fa7;
}

.btn-gh-sponsors {
font-weight: 600;
color: #333;
background-color: #eee;
border-color: #ccc;
}
8 changes: 4 additions & 4 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": "next",
"asciinema-player": "3.6.3",
"babel-loader": "^8.3.0",
"bootstrap": "^4.5.0",
"copy-webpack-plugin": "^11.0.0",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ config :sentry,
config :asciinema, :file_store, Asciinema.FileStore.Local
config :asciinema, Asciinema.FileStore.Local, path: "uploads/"

config :asciinema, Asciinema.FileCache, path: "cache/"

config :asciinema, :png_generator, Asciinema.PngGenerator.Rsvg

config :asciinema, Asciinema.PngGenerator.Rsvg,
Expand Down
2 changes: 2 additions & 0 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ config :asciinema, Asciinema.Emails.Mailer,
adapter: Bamboo.SMTPAdapter,
server: "smtp",
port: 25

config :asciinema, Asciinema.FileCache, path: "/var/cache/asciinema"
9 changes: 8 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ if config_env() in [:prod, :dev] do

config :ex_aws, region: {:system, "AWS_REGION"}

file_cache_path = env.("FILE_CACHE_PATH")

if file_cache_path do
config :asciinema, Asciinema.FileCache, path: file_cache_path
end

if env.("S3_BUCKET") do
config :asciinema, :file_store, Asciinema.FileStore.Cached

Expand All @@ -75,7 +81,8 @@ if config_env() in [:prod, :dev] do
access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role],
secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]

config :asciinema, Asciinema.FileStore.Local, path: "cache/uploads/"
config :asciinema, Asciinema.FileStore.Local,
path: Path.join(file_cache_path || "/var/cache/asciinema", "uploads")
end

if db_pool_size = env.("DB_POOL_SIZE") do
Expand Down
2 changes: 2 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ config :asciinema, Asciinema.Accounts,

config :asciinema, Asciinema.FileStore.Local, path: "uploads/test/"

config :asciinema, Asciinema.FileCache, path: "/tmp/asciinema/"

config :asciinema, :snapshot_updater, Asciinema.Recordings.SnapshotUpdater.Noop

config :asciinema, Oban, testing: :manual
Expand Down
1 change: 1 addition & 0 deletions lib/asciinema/emails/email.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule Asciinema.Emails.Email do
defp base_email do
new_email()
|> from({"asciinema", from_address()})
|> put_header("Date", Timex.format!(Timex.now(), "{RFC1123}"))
|> put_header("Reply-To", reply_to_address())
|> put_html_layout({AsciinemaWeb.LayoutView, "email.html"})
end
Expand Down
24 changes: 24 additions & 0 deletions lib/asciinema/file_cache.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
defmodule Asciinema.FileCache do
def full_path(namespace, path, generator) do
path = full_path(namespace, path)

case File.stat(path) do
{:ok, _} ->
path

{:error, :enoent} ->
content = generator.()
parent_dir = Path.dirname(path)
:ok = File.mkdir_p(parent_dir)
File.write!(path, content)

path
end
end

defp full_path(namespace, path), do: Path.join([base_path(), to_string(namespace), path])

defp base_path do
Keyword.get(Application.get_env(:asciinema, __MODULE__), :path)
end
end
22 changes: 12 additions & 10 deletions lib/asciinema/file_store/local.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Asciinema.FileStore.Local do

@impl true
def put_file(dst_path, src_local_path, _content_type) do
full_dst_path = base_path() <> dst_path
full_dst_path = full_path(dst_path)
parent_dir = Path.dirname(full_dst_path)

with :ok <- File.mkdir_p(parent_dir),
Expand All @@ -20,8 +20,8 @@ defmodule Asciinema.FileStore.Local do

@impl true
def move_file(from_path, to_path) do
full_from_path = base_path() <> from_path
full_to_path = base_path() <> to_path
full_from_path = full_path(from_path)
full_to_path = full_path(to_path)
parent_dir = Path.dirname(full_to_path)
:ok = File.mkdir_p(parent_dir)
File.rename(full_from_path, full_to_path)
Expand All @@ -41,13 +41,13 @@ defmodule Asciinema.FileStore.Local do
defp do_serve_file(conn, path) do
conn
|> put_resp_header("content-type", MIME.from_path(path))
|> send_file(200, base_path() <> path)
|> send_file(200, full_path(path))
|> halt
end

@impl true
def open_file(path) do
File.open(base_path() <> path, [:binary, :read])
File.open(full_path(path), [:binary, :read])
end

@impl true
Expand All @@ -56,19 +56,21 @@ defmodule Asciinema.FileStore.Local do
end

def open_file(path, function) do
File.open(base_path() <> path, [:binary, :read], function)
File.open(full_path(path), [:binary, :read], function)
end

@impl true
def delete_file(path) do
File.rm(base_path() <> path)
File.rm(full_path(path))
end

defp config do
Application.get_env(:asciinema, __MODULE__)
end
defp full_path(path), do: Path.join(base_path(), path)

defp base_path do
Keyword.get(config(), :path)
end

defp config do
Application.get_env(:asciinema, __MODULE__)
end
end
Loading

0 comments on commit 9dcbba9

Please sign in to comment.