Use backend endpoint for attachment downloads
This commit is contained in:
@@ -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 */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user