-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add security macro in controllers (#157)
- Loading branch information
Showing
12 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...llyfish_web/controllers/hls_controller.ex → ...web/controllers/hls_content_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
lib/jellyfish_web/controllers/recording_content_controller.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
defmodule JellyfishWeb.RecordingContentController do | ||
use JellyfishWeb, :controller | ||
use OpenApiSpex.ControllerSpecs | ||
|
||
require Logger | ||
|
||
alias Jellyfish.Component.HLS.RequestHandler | ||
alias JellyfishWeb.ApiSpec | ||
|
||
alias Plug.Conn | ||
|
||
action_fallback JellyfishWeb.FallbackController | ||
|
||
@playlist_content_type "application/vnd.apple.mpegurl" | ||
@recording_id_spec [in: :path, description: "Recording id", type: :string] | ||
|
||
tags [:recording] | ||
|
||
operation :index, | ||
operation_id: "getRecordingContent", | ||
summary: "Retrieve Recording (HLS) Content", | ||
parameters: [ | ||
recording_id: @recording_id_spec, | ||
filename: [in: :path, description: "Name of the file", type: :string] | ||
], | ||
required: [:recording_id, :filename], | ||
responses: [ | ||
ok: ApiSpec.data("File was found", ApiSpec.HLS.Response), | ||
not_found: ApiSpec.error("File not found"), | ||
bad_request: ApiSpec.error("Invalid request") | ||
] | ||
|
||
def index(conn, %{"recording_id" => recording_id, "filename" => filename}) do | ||
with {:ok, file} <- | ||
RequestHandler.handle_recording_request(recording_id, filename) do | ||
conn = | ||
if String.ends_with?(filename, ".m3u8"), | ||
do: put_resp_content_type(conn, @playlist_content_type, nil), | ||
else: conn | ||
|
||
Conn.send_resp(conn, 200, file) | ||
else | ||
{:error, :invalid_recording} -> | ||
{:error, :bad_request, "Invalid recording, got: #{recording_id}"} | ||
|
||
{:error, :invalid_path} -> | ||
{:error, :bad_request, "Invalid filename, got: #{filename}"} | ||
|
||
{:error, _reason} -> | ||
{:error, :not_found, "File not found"} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters