-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
228 additions
and
14 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
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,80 @@ | ||
export const coverArtInspectorLoader = async ({ request }) => { | ||
const url = new URL(request.url); | ||
const page = url.searchParams.get("page") || 1; | ||
const perPage = url.searchParams.get("per_page") || 50; | ||
|
||
try { | ||
const response = await fetch(`/api/v2/shows?page=${page}&per_page=${perPage}`); | ||
if (!response.ok) throw response; | ||
const data = await response.json(); | ||
return { | ||
shows: data.shows, | ||
totalPages: data.total_pages, | ||
totalEntries: data.total_entries, | ||
page: parseInt(page, 10) - 1, | ||
perPage: parseInt(perPage) | ||
}; | ||
} catch (error) { | ||
throw new Response("Error fetching data", { status: 500 }); | ||
} | ||
}; | ||
|
||
import React, { useState } from "react"; | ||
import { useLoaderData, useNavigate, useOutletContext } from "react-router-dom"; | ||
import { Helmet } from "react-helmet-async"; | ||
import LayoutWrapper from "./layout/LayoutWrapper"; | ||
import CoverArt from "./CoverArt"; | ||
import Pagination from "./controls/Pagination"; | ||
import { paginationHelper } from "./helpers/pagination"; | ||
|
||
const CoverArtInspector = () => { | ||
const { shows, totalPages, totalEntries, page, perPage } = useLoaderData(); // Fetch the data from the loader | ||
const { openAppModal } = useOutletContext(); | ||
const navigate = useNavigate(); | ||
|
||
const { | ||
tempPerPage, | ||
handlePageClick, | ||
handlePerPageInputChange, | ||
handlePerPageBlurOrEnter | ||
} = paginationHelper(page, "", perPage); | ||
|
||
const sidebarContent = ( | ||
<div className="sidebar-content"> | ||
<p className="sidebar-title">Album Covers</p> | ||
<p className="sidebar-subtitle">{totalEntries} total</p> | ||
</div> | ||
); | ||
|
||
return ( | ||
<> | ||
<Helmet> | ||
<title>Cover Art - Phish.in</title> | ||
</Helmet> | ||
<LayoutWrapper sidebarContent={sidebarContent}> | ||
<div className="grid-container"> | ||
{shows.map((show) => ( | ||
<CoverArt | ||
key={show.id} | ||
coverArtUrls={show.cover_art_urls} | ||
albumCoverUrl={show.album_cover_url} | ||
openAppModal={openAppModal} | ||
size="medium" | ||
/> | ||
))} | ||
</div> | ||
<Pagination | ||
totalPages={totalPages} | ||
handlePageClick={handlePageClick} | ||
currentPage={page} | ||
perPage={tempPerPage} | ||
handlePerPageInputChange={handlePerPageInputChange} | ||
handlePerPageBlurOrEnter={handlePerPageBlurOrEnter} | ||
/> | ||
</LayoutWrapper> | ||
</> | ||
); | ||
}; | ||
|
||
export default CoverArtInspector; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require "zip" | ||
|
||
class AlbumZipJob | ||
include Sidekiq::Job | ||
|
||
attr_reader :show_id | ||
|
||
def perform(show_id) | ||
@show_id = show_id | ||
create_and_attach_album_zip | ||
end | ||
|
||
private | ||
|
||
def create_and_attach_album_zip | ||
Tempfile.open([ "album-zip-#{show_id}", ".zip" ]) do |temp_zip| # rubocop:disable Metrics/BlockLength | ||
Zip::File.open(temp_zip.path, Zip::File::CREATE) do |zipfile| | ||
# Tracks | ||
show.tracks.order(:position).each do |track| | ||
track_filename = "#{format("%02d", track.position)} #{sanitize(track.title)}.mp3" | ||
zipfile.get_output_stream(track_filename) do |stream| | ||
stream.write track.audio_file.read | ||
end | ||
end | ||
|
||
# taper-notes.txt | ||
zipfile.get_output_stream("taper-notes.txt") do |stream| | ||
stream.write show.taper_notes | ||
end | ||
|
||
# cover-art.jpg | ||
if show.cover_art.attached? && show.cover_art | ||
zipfile.get_output_stream("cover-art.jpg") do |stream| | ||
stream.write show.cover_art.download | ||
end | ||
end | ||
|
||
# album-cover.jpg | ||
if show.album_cover.attached? | ||
zipfile.get_output_stream("album-cover.jpg") do |stream| | ||
stream.write show.album_cover.download | ||
end | ||
end | ||
end | ||
|
||
show.album_zip.attach \ | ||
io: File.open(temp_zip.path), | ||
filename: "Phish #{show.date} MP3 Album.zip", | ||
content_type: "application/zip" | ||
end | ||
end | ||
|
||
def sanitize(str) | ||
str.gsub(/[\/\\<>:"|?*]/, " ").gsub(",", " ").squeeze(" ").strip | ||
end | ||
|
||
def show | ||
@show ||= Show.find(show_id) | ||
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
Oops, something went wrong.