Use backend endpoint for attachment downloads

This commit is contained in:
TerryM
2026-05-27 12:17:47 +08:00
parent 68cbce9cf1
commit 9453777dba
5 changed files with 42 additions and 23 deletions

View File

@@ -1,12 +1,15 @@
import { Download } from "lucide-react";
import { Link } from "react-router-dom";
import type { Resource } from "../api";
import { assetUrl, postJSON, postNoBody } from "../api";
import { assetUrl, postJSON } from "../api";
import { useI18n } from "../i18n";
import { useMemo } from "react";
import { formatDateYmd } from "../utils/format";
import { officialRecommendationCoverFallbacks } from "./FigmaBanner";
import { downloadFile } from "./messageStream/utils/downloadFile";
import {
downloadAttachment,
downloadFile,
} from "./messageStream/utils/downloadFile";
function isPlaceholderAsset(path: string | undefined | null) {
return !path || path.includes("placeholder-cover");
@@ -88,14 +91,16 @@ export function RecommendedCard({
onClick={async (e) => {
e.preventDefault();
e.stopPropagation();
if (r.downloadPostId && r.downloadAttachmentId) {
void downloadAttachment(
r.downloadPostId,
r.downloadAttachmentId,
r.title,
).catch(() => {});
return;
}
try {
if (r.downloadPostId && r.downloadAttachmentId) {
await postNoBody(
`/api/posts/${r.downloadPostId}/attachments/${r.downloadAttachmentId}/download`,
);
} else {
await postJSON(`/api/resources/${r.id}/download`, {});
}
await postJSON(`/api/resources/${r.id}/download`, {});
} catch {
/* ignore */
}