-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checkpoint: starting to build out Work pages, and made some changes t…
…o schema stuff
- Loading branch information
Showing
7 changed files
with
218 additions
and
5 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
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 BanchanWeb.WorkUploadsController do | ||
@moduledoc """ | ||
Serves work uploads and previews, taking into account permissions. | ||
""" | ||
use BanchanWeb, :controller | ||
|
||
alias Banchan.Studios | ||
alias Banchan.Uploads | ||
alias Banchan.Works | ||
|
||
def show(conn, %{"handle" => studio_handle, "work_id" => public_id, "upload_id" => upload_id}) do | ||
studio = Studios.get_studio_by_handle!(studio_handle) | ||
work = Works.get_work_by_public_id!(studio, public_id) | ||
work_upload = Works.get_work_upload_if_allowed!(work, upload_id, conn.assigns.current_user) | ||
|
||
conn | ||
|> put_resp_header("content-length", "#{work_upload.upload.size}") | ||
|> put_resp_header( | ||
"content-disposition", | ||
"attachment; filename=\"#{work_upload.upload.name || work_upload.upload.key}\"" | ||
) | ||
|> put_resp_content_type(work_upload.upload.type) | ||
|> send_chunked(200) | ||
|> then( | ||
&Enum.reduce_while(Uploads.stream_data!(work_upload.upload), &1, fn chunk, conn -> | ||
case chunk(conn, chunk) do | ||
{:ok, conn} -> | ||
{:cont, conn} | ||
|
||
{:error, :closed} -> | ||
{:halt, conn} | ||
end | ||
end) | ||
) | ||
end | ||
|
||
def preview(conn, %{"handle" => studio_handle, "work_id" => public_id, "upload_id" => upload_id}) do | ||
studio = Studios.get_studio_by_handle!(studio_handle) | ||
work = Works.get_work_by_public_id!(studio, public_id) | ||
work_upload = Works.get_work_upload_if_allowed!(work, upload_id, conn.assigns.current_user) | ||
|
||
if work_upload.preview && !work_upload.preview.pending do | ||
conn | ||
|> put_resp_header("content-length", "#{work_upload.preview.size}") | ||
|> put_resp_content_type(work_upload.preview.type) | ||
|> send_resp(200, Uploads.get_data!(work_upload.preview)) | ||
else | ||
conn | ||
|> resp(404, "Not Found") | ||
|> send_resp() | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
defmodule BanchanWeb.WorksLive.Show do | ||
@moduledoc """ | ||
Displays a work. | ||
""" | ||
use BanchanWeb, :live_view | ||
|
||
import BanchanWeb.StudioLive.Helpers | ||
|
||
alias Banchan.Repo | ||
alias Banchan.Works | ||
|
||
alias BanchanWeb.Components.{ | ||
Carousel, | ||
Layout, | ||
Lightbox | ||
} | ||
|
||
@impl true | ||
def handle_params(%{"work_id" => work_id} = params, _url, socket) do | ||
socket = assign_studio_defaults(params, socket, false, true) | ||
|
||
work = Works.get_work!(work_id) |> Repo.preload(:uploads) | ||
|
||
{:noreply, socket |> assign(work: work)} | ||
end | ||
|
||
@impl true | ||
def render(assigns) do | ||
~F""" | ||
<style> | ||
.container { | ||
@apply w-full p-4 mx-auto max-w-7xl; | ||
} | ||
.work-grid { | ||
@apply grid grid-cols-1 gap-6 md:grid-cols-3; | ||
} | ||
.preview-column { | ||
@apply flex flex-col gap-4 md:order-1; | ||
} | ||
.carousel-image { | ||
@apply w-full h-full object-contain aspect-video; | ||
} | ||
.work-info { | ||
} | ||
.work-title { | ||
@apply text-3xl font-bold; | ||
} | ||
.work-description { | ||
@apply text-base; | ||
} | ||
</style> | ||
<Layout flashes={@flash}> | ||
<div class="container"> | ||
<div class="work-grid"> | ||
<div class="preview-column"> | ||
<Carousel id="preview-carousel"> | ||
<Lightbox id="preview-lightbox"> | ||
{#for wupload <- @work.uploads} | ||
{#if !is_nil(wupload.preview_id)} | ||
<Carousel.Slide> | ||
<Lightbox.Item | ||
src={~p"/studios/#{@studio.handle}/works/#{@work.public_id}/upload/#{wupload.id}/preview"} | ||
download={~p"/studios/#{@studio.handle}/works/#{@work.public_id}/upload/#{wupload.id}"} | ||
> | ||
<img | ||
class="carousel-image" | ||
src={~p"/studios/#{@studio.handle}/works/#{@work.public_id}/upload/#{wupload.id}/preview"} | ||
/> | ||
</Lightbox.Item> | ||
</Carousel.Slide> | ||
{/if} | ||
{/for} | ||
</Lightbox> | ||
</Carousel> | ||
</div> | ||
<div class="work-info"> | ||
<h1 class="work-title">{@work.title}</h1> | ||
<p class="work-description">{@work.description}</p> | ||
</div> | ||
</div> | ||
</div> | ||
</Layout> | ||
""" | ||
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