Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: switch to using backblaze for images #948

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/src/components/ManageArtist/UploadArtistImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const UploadArtistImage: React.FC<{
const { uploadJobs, setUploadJobs } = useJobStatusCheck({
reload: () => {},
reset: resetWrapper,
queue: "optimizeImage",
});

const deleteImage = React.useCallback(async () => {
Expand All @@ -130,6 +131,7 @@ const UploadArtistImage: React.FC<{
`${buildRootUrl(existing)}${imageType}`,
[file]
);
console.log("jobInfo", jobInfo);
setUploadJobs([
{ jobId: jobInfo.result.jobId, jobStatus: "waiting" },
]);
Expand Down
64 changes: 37 additions & 27 deletions client/src/components/common/DownloadAlbumButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import Modal from "./Modal";
import LoadingSpinner from "./LoadingSpinner";

const formats = ["flac", "wav", "opus", "320.mp3", "256.mp3", "128.mp3"];
const formatsDisplay: { [format: string]: string; } = {
const formatsDisplay: { [format: string]: string } = {
"": "",
"flac": "FLAC",
"wav": "WAV",
"opus": "OPUS",
flac: "FLAC",
wav: "WAV",
opus: "OPUS",
"320.mp3": "MP3 320kbps",
"256.mp3": "MP3 256kbps",
"128.mp3": "MP3 128kbps",
}
};

const DownloadAlbumButton: React.FC<{
trackGroup: TrackGroup;
Expand Down Expand Up @@ -70,25 +70,26 @@ const DownloadAlbumButton: React.FC<{
trackGroup.title,
]);

const generateAlbum = React.useCallback(async (format: string) => {
try {
const queryParams = new URLSearchParams();
queryParams.append("format", format);
const resp = await api.generateDownload(`trackGroups/${trackGroup.id}/generate?${queryParams.toString()}`);
if ((resp as any).result.jobId) {
setIsGeneratingAlbum(+(resp as any).result.jobId);
} else if ((resp as any).result === true) {
setIsGeneratingAlbum(0);
const generateAlbum = React.useCallback(
async (format: string) => {
try {
const queryParams = new URLSearchParams();
queryParams.append("format", format);
const resp = await api.generateDownload(
`trackGroups/${trackGroup.id}/generate?${queryParams.toString()}`
);
if ((resp as any).result.jobId) {
setIsGeneratingAlbum(+(resp as any).result.jobId);
} else if ((resp as any).result === true) {
setIsGeneratingAlbum(0);
}
} catch (e) {
snackbar(t("error"), { type: "warning" });
console.error(e);
}
} catch (e) {
snackbar(t("error"), { type: "warning" });
console.error(e);
}
}, [
chosenFormat,
trackGroup.id,
t,
])
},
[chosenFormat, trackGroup.id, t]
);

React.useEffect(() => {
let interval: NodeJS.Timeout | null = null;
Expand All @@ -114,7 +115,7 @@ const DownloadAlbumButton: React.FC<{
return (
<div>
<Modal
title={`${t("download")} ${formatsDisplay[chosenFormat]}` ?? ""}
title={`${t("download")} ${formatsDisplay[chosenFormat]}`}
open={isPopupOpen}
size="small"
onClose={() => setIsPopupOpen(false)}
Expand All @@ -123,13 +124,17 @@ const DownloadAlbumButton: React.FC<{
className={css`
display: flex;
flex-direction: column;
text-align: center;
text-align: center;
`}
>
{!chosenFormat && !isDownloading ? (
<>
<p>{t("downloadFiletypeQuery")}</p>
<ul className={css`list-style-type: none;`}>
<ul
className={css`
list-style-type: none;
`}
>
{formats.map((format) => (
<li key={format}>
<Button
Expand Down Expand Up @@ -183,7 +188,12 @@ const DownloadAlbumButton: React.FC<{
)}
</Button>
<p>
<Button className={css`margin-top: 1rem`} onClick={() => setChosenFormat("")}>
<Button
className={css`
margin-top: 1rem;
`}
onClick={() => setChosenFormat("")}
>
{t("chooseAnotherFormat")}
</Button>
</p>
Expand Down
6 changes: 5 additions & 1 deletion client/src/utils/useJobStatusCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import api from "services/api";
const useJobStatusCheck = ({
reload,
reset,
queue,
}: {
reload: () => void;
reset?: () => void;
queue?: "optimizeImage";
}) => {
const [uploadJobs, setUploadJobs] = React.useState<
{ jobId: string; jobStatus: string }[]
Expand All @@ -16,9 +18,11 @@ const useJobStatusCheck = ({
let timer: NodeJS.Timeout | undefined;
if (uploadJobs.length > 0) {
timer = setInterval(async () => {
console.log("setting an interval");
const result = await api.getMany<{ jobStatus: string; jobId: string }>(
`jobs?${uploadJobs.map((job) => `ids=${job.jobId}&`).join("")}`
`jobs?queue=${queue ?? ""}&${uploadJobs.map((job) => `ids=${job.jobId}&`).join("")}`
);
console.log("result", result);

if (
result.results.some(
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"prepare": "husky install"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.715.0",
"@aws-sdk/lib-storage": "^3.715.0",
"@bull-board/express": "^4.11.0",
"@faker-js/faker": "^8.3.1",
"@prisma/client": "5",
Expand Down
173 changes: 87 additions & 86 deletions src/config/sharp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ export default {
smartSubsample: true,
},
},
jpeg: {
ext: ".jpg",
outputOptions: {
chromaSubsampling: "4:4:4",
optimiseCoding: true,
quantisationTable: 3,
progressive: false,
optimiseScans: false, // required mozjpeg support
trellisQuantisation: true, // required mozjpeg support
overshootDeringing: true, // required mozjpeg support
},
},
png: {
ext: ".png",
outputOptions: {
chromaSubsampling: "4:4:4",
optimiseCoding: true,
quantisationTable: 3,
progressive: false,
optimiseScans: false, // required mozjpeg support
trellisQuantisation: true, // required mozjpeg support
overshootDeringing: true, // required mozjpeg support
},
},
// jpeg: {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm getting rid of these because they're not getting used in the UI, and I can't quite imagine why they'd get used, and we can always generate them in the future?

// ext: ".jpg",
// outputOptions: {
// chromaSubsampling: "4:4:4",
// optimiseCoding: true,
// quantisationTable: 3,
// progressive: false,
// optimiseScans: false, // required mozjpeg support
// trellisQuantisation: true, // required mozjpeg support
// overshootDeringing: true, // required mozjpeg support
// },
// },
// png: {
// ext: ".png",
// outputOptions: {
// chromaSubsampling: "4:4:4",
// optimiseCoding: true,
// quantisationTable: 3,
// progressive: false,
// optimiseScans: false, // required mozjpeg support
// trellisQuantisation: true, // required mozjpeg support
// overshootDeringing: true, // required mozjpeg support
// },
// },
},
config: {
banner: {
Expand All @@ -47,28 +47,29 @@ export default {
{ width: 625, height: 625 },
],
},
jpeg: {
variants: [
{ width: 2500, height: 2500 },
{ width: 1250, height: 1250 },
{ width: 1200, height: 630 },
{ width: 1024, height: 1024 },
{ width: 625, height: 625 },
],
},
png: {
variants: [
{ width: 2500, height: 2500 },
{ width: 1250, height: 1250 },
{ width: 1200, height: 630 },
{ width: 1024, height: 1024 },
{ width: 625, height: 625 },
],
},
// jpeg: {
// variants: [
// { width: 2500, height: 2500 },
// { width: 1250, height: 1250 },
// { width: 1200, height: 630 },
// { width: 1024, height: 1024 },
// { width: 625, height: 625 },
// ],
// },
// png: {
// variants: [
// { width: 2500, height: 2500 },
// { width: 1250, height: 1250 },
// { width: 1200, height: 630 },
// { width: 1024, height: 1024 },
// { width: 625, height: 625 },
// ],
// },
},
avatar: {
webp: {
variants: [
{ width: 3000, height: 3000 },
{ width: 1500, height: 1500 },
{ width: 1200, height: 1200 },
{ width: 960, height: 960 },
Expand All @@ -78,28 +79,28 @@ export default {
{ width: 60, height: 60 },
],
},
jpeg: {
variants: [
{ width: 1500, height: 1500 },
{ width: 1200, height: 1200 },
{ width: 960, height: 960 },
{ width: 600, height: 600 },
{ width: 300, height: 300 },
{ width: 120, height: 120 },
{ width: 60, height: 60 },
],
},
png: {
variants: [
{ width: 1500, height: 1500 },
{ width: 1200, height: 1200 },
{ width: 960, height: 960 },
{ width: 600, height: 600 },
{ width: 300, height: 300 },
{ width: 120, height: 120 },
{ width: 60, height: 60 },
],
},
// jpeg: {
// variants: [
// { width: 1500, height: 1500 },
// { width: 1200, height: 1200 },
// { width: 960, height: 960 },
// { width: 600, height: 600 },
// { width: 300, height: 300 },
// { width: 120, height: 120 },
// { width: 60, height: 60 },
// ],
// },
// png: {
// variants: [
// { width: 1500, height: 1500 },
// { width: 1200, height: 1200 },
// { width: 960, height: 960 },
// { width: 600, height: 600 },
// { width: 300, height: 300 },
// { width: 120, height: 120 },
// { width: 60, height: 60 },
// ],
// },
},
artwork: {
webp: {
Expand All @@ -113,28 +114,28 @@ export default {
{ width: 60, height: 60 },
],
},
jpeg: {
variants: [
{ width: 1500, height: 1500 },
{ width: 1200, height: 1200 },
{ width: 960, height: 960 },
{ width: 600, height: 600 },
{ width: 300, height: 300 },
{ width: 120, height: 120 },
{ width: 60, height: 60 },
],
},
png: {
variants: [
{ width: 1500, height: 1500 },
{ width: 1200, height: 1200 },
{ width: 960, height: 960 },
{ width: 600, height: 600 },
{ width: 300, height: 300 },
{ width: 120, height: 120 },
{ width: 60, height: 60 },
],
},
// jpeg: {
// variants: [
// { width: 1500, height: 1500 },
// { width: 1200, height: 1200 },
// { width: 960, height: 960 },
// { width: 600, height: 600 },
// { width: 300, height: 300 },
// { width: 120, height: 120 },
// { width: 60, height: 60 },
// ],
// },
// png: {
// variants: [
// { width: 1500, height: 1500 },
// { width: 1200, height: 1200 },
// { width: 960, height: 960 },
// { width: 600, height: 600 },
// { width: 300, height: 300 },
// { width: 120, height: 120 },
// { width: 60, height: 60 },
// ],
// },
},
},
};
Loading
Loading