Skip to content
Open
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
103 changes: 103 additions & 0 deletions apps/web/src/api/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 105 additions & 0 deletions apps/web/src/components/ReleaseBlockNotice.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { CircleAlert, LockOpen } from "lucide-react";
import { api, result, type Auth } from "../api/client";
import type { components } from "../api/schema";

type Block = components["schemas"]["ReleaseBlockInfo"];

export function blockedSummary(block: Block) {
const when = new Date(block.blocked_at).toLocaleDateString();
return `${block.reason} (${block.automatic ? "found automatically" : "reported"} ${when})`;
}

// Why this release cannot be downloaded again, and the way out for administrators.
export default function ReleaseBlockNotice({ block }: { block: Block }) {
const cache = useQueryClient();
const { data: session } = useQuery<Auth | null>({
queryKey: ["session"],
enabled: false,
});
const admin = session?.user.role === "admin";
const refresh = () => {
for (const name of [
"book-sources",
"requests",
"downloads",
"activity",
"release-blocklist",
])
void cache.invalidateQueries({ queryKey: [name] });
};
const unblock = useMutation({
mutationFn: async () =>
result(
await api.DELETE("/api/acquisition/recovery/blocklist/{block_id}", {
params: { path: { block_id: block.id } },
}),
),
onSuccess: refresh,
});
const resume = useMutation({
mutationFn: async () =>
result(
await api.POST(
"/api/acquisition/recovery/blocklist/{block_id}/resume",
{
params: { path: { block_id: block.id } },
},
),
),
onSuccess: refresh,
});
const busy = unblock.isPending || resume.isPending;
const outcome = resume.data;
const refused = outcome?.attempts.filter((attempt) => !attempt.resumed);
const error = unblock.error || resume.error;
return (
<div
className="release-block-notice"
role="group"
aria-label="Blocked release"
>
<p className="error">
<CircleAlert size={14} aria-hidden /> Blocked: {blockedSummary(block)}
</p>
{admin && (
<div className="button-row">
{block.can_resume && (
<button
disabled={busy}
onClick={() => resume.mutate()}
title="Remove the block and continue the download that is already on your downloader"
>
<LockOpen size={14} aria-hidden />{" "}
{resume.isPending ? "Resuming…" : "Unblock and resume"}
</button>
)}
<button
disabled={busy}
onClick={() => unblock.mutate()}
title="Allow this release to be selected again"
>
{unblock.isPending ? "Unblocking…" : "Unblock"}
</button>
</div>
)}
{outcome && outcome.resumed > 0 && (
<p role="status">
Resumed. Dewarr is checking the existing download; no new torrent was
added.
</p>
)}
{refused?.map((attempt) => (
<p key={attempt.attempt_id} role="status" className="muted">
Unblocked, but the existing download was not resumed:{" "}
{attempt.message}.
</p>
))}
{error && (
<p className="error" role="alert">
{error.message}
</p>
)}
</div>
);
}
2 changes: 2 additions & 0 deletions apps/web/src/components/SourceReleaseDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useQuery } from "@tanstack/react-query";
import { ExternalLink } from "lucide-react";
import { api, result } from "../api/client";
import type { components } from "../api/schema";
import ReleaseBlockNotice from "./ReleaseBlockNotice";
import SourceReleaseDownload from "./SourceReleaseDownload";
import { transferSize } from "../pages/DownloadConstraints";
import BookDialog from "./BookDialog";
Expand Down Expand Up @@ -104,6 +105,7 @@ export default function SourceReleaseDetails({
{!!item.assessment.blocked.length && (
<p className="notice error">{item.assessment.blocked.join(" · ")}</p>
)}
{item.block && <ReleaseBlockNotice block={item.block} />}
<div className="release-detail-actions">
{canAcquire && (
<SourceReleaseDownload
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/pages/BookSources.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import InfiniteScroll from "../components/InfiniteScroll";
import ReleaseBlockNotice from "../components/ReleaseBlockNotice";
import SourceReleaseDownload from "../components/SourceReleaseDownload";
import { Info, Search as SearchIcon } from "lucide-react";
import SourceReleaseDetails, {
Expand Down Expand Up @@ -670,10 +671,11 @@ function Results({
{sourceName(item.release)} · #{rank + 1}
{unavailableReason(item)
? ` · ${unavailableReason(item)}`
: item.assessment.blocked.length
: item.block || item.assessment.blocked.length
? " · Blocked"
: ""}
</small>
{item.block && <ReleaseBlockNotice block={item.block} />}
</td>
<td data-label="Authors">
{item.release.authors?.join(", ") || "—"}
Expand Down Expand Up @@ -742,12 +744,15 @@ function Results({
disabled={
data.status !== "completed" ||
!!unavailableReason(item) ||
!!item.block ||
item.assessment.blocked.length > 0
}
disabledReason={
unavailableReason(item)
? `${unavailableReason(item)}. Refresh results to download.`
: undefined
: item.block
? "This release is blocked. Unblock it first."
: undefined
}
/>
)}
Expand All @@ -769,6 +774,7 @@ function Results({
canAcquire={canAcquire && canDownload(detailItem.release.medium)}
disabled={
!!unavailableReason(detailItem) ||
!!detailItem.block ||
detailItem.assessment.blocked.length > 0
}
/>
Expand Down
10 changes: 10 additions & 0 deletions apps/web/src/sources.css
Original file line number Diff line number Diff line change
Expand Up @@ -1017,3 +1017,13 @@
.collection-cover .cover-formats {
display: none;
}

.release-block-notice {
display: grid;
gap: 0.35rem;
margin-top: 0.35rem;
}

.release-block-notice p {
margin: 0;
}
Loading