diff --git a/README.md b/README.md index f57c059..c78bd08 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,10 @@ NOTE: it's recommended to not run the container as root. Doing so can create per HTTP basic authentication is optionally supported. To use it, set the `BASIC_AUTH_USERNAME` and `BASIC_AUTH_PASSWORD` environment variables when starting the container. No authentication will be required unless you set _both_ of these. +### Important note: + +The media streaming endpoint is not protected by basic auth. To help protect your media, these endpoints work with UUIDs instead of sequential IDs but this is still essentially security through obscurity. If you're concerned about the security of your media, consider using a reverse proxy with authentication or a VPN. + ## EFF donations A portion of all donations to Pinchflat will be donated to the [Electronic Frontier Foundation](https://www.eff.org/). The EFF defends your online liberties and [backed](https://github.com/github/dmca/blob/9a85e0f021f7967af80e186b890776a50443f06c/2020/11/2020-11-16-RIAA-reversal-effletter.pdf) `youtube-dl` when Google took them down. [See here](https://github.com/kieraneglin/pinchflat/wiki/EFF-Donation-Receipts) for a list of donation receipts. diff --git a/lib/pinchflat_web/controllers/media_items/media_item_controller.ex b/lib/pinchflat_web/controllers/media_items/media_item_controller.ex index 56f8f7d..bf44c77 100644 --- a/lib/pinchflat_web/controllers/media_items/media_item_controller.ex +++ b/lib/pinchflat_web/controllers/media_items/media_item_controller.ex @@ -3,6 +3,7 @@ defmodule PinchflatWeb.MediaItems.MediaItemController do alias Pinchflat.Repo alias Pinchflat.Media + alias Pinchflat.Media.MediaItem def show(conn, %{"id" => id}) do media_item = @@ -32,13 +33,11 @@ defmodule PinchflatWeb.MediaItems.MediaItemController do # See here for details on streaming files and range requests: # https://www.zeng.dev/post/2023-http-range-and-play-mp4-in-browser/ - def stream(conn, %{"id" => id}) do - media_item = Media.get_media_item!(id) - - # TODO: show audio vs. video element in UI depending on media type - # TODO: consider how a podcast RSS feed would interact with HTTP basic auth - # TODO: reconsider the sobelow changes I made - # TODO: UUID stuff + # + # Uses the UUID instead of the ID to avoid enumeration attacks + # since streaming is a public endpoint (ie: no auth required) + def stream(conn, %{"id" => uuid}) do + media_item = Repo.get_by!(MediaItem, uuid: uuid) if File.exists?(media_item.media_filepath) do file_size = File.stat!(media_item.media_filepath).size diff --git a/lib/pinchflat_web/controllers/media_items/media_item_html.ex b/lib/pinchflat_web/controllers/media_items/media_item_html.ex index ffae16a..12d7ffa 100644 --- a/lib/pinchflat_web/controllers/media_items/media_item_html.ex +++ b/lib/pinchflat_web/controllers/media_items/media_item_html.ex @@ -2,4 +2,16 @@ defmodule PinchflatWeb.MediaItems.MediaItemHTML do use PinchflatWeb, :html embed_templates "media_item_html/*" + + def media_file_exists?(media_item) do + !!media_item.media_filepath and File.exists?(media_item.media_filepath) + end + + def media_type(media_item) do + case Path.extname(media_item.media_filepath) do + ext when ext in [".mp4", ".webm", ".mkv"] -> :video + ext when ext in [".mp3", ".m4a"] -> :audio + _ -> :unknown + end + end end diff --git a/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex b/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex new file mode 100644 index 0000000..2146a98 --- /dev/null +++ b/lib/pinchflat_web/controllers/media_items/media_item_html/media_preview.heex @@ -0,0 +1,13 @@ +<%= if media_type(@media_item) == :video do %> + +<% end %> + +<%= if media_type(@media_item) == :audio do %> + +<% end %> diff --git a/lib/pinchflat_web/controllers/media_items/media_item_html/show.html.heex b/lib/pinchflat_web/controllers/media_items/media_item_html/show.html.heex index 3d379e5..7d56c51 100644 --- a/lib/pinchflat_web/controllers/media_items/media_item_html/show.html.heex +++ b/lib/pinchflat_web/controllers/media_items/media_item_html/show.html.heex @@ -8,19 +8,16 @@ -