feat: wire public posts api

This commit is contained in:
TerryM
2026-05-26 12:07:13 +08:00
parent f482a2ec38
commit d3c30795dc
19 changed files with 299 additions and 163 deletions

View File

@@ -1,7 +1,7 @@
import { Download } from "lucide-react";
import { Link } from "react-router-dom";
import type { Resource } from "../api";
import { assetUrl, postJSON } from "../api";
import { assetUrl, postJSON, postNoBody } from "../api";
import { useI18n } from "../i18n";
import { useMemo } from "react";
import { formatDateYmd } from "../utils/format";
@@ -14,11 +14,16 @@ function isPlaceholderAsset(path: string | undefined | null) {
const CARD_CLASS =
"group flex w-[232px] shrink-0 flex-col overflow-hidden rounded-xl border border-ark-line bg-ark-panel transition hover:border-ark-gold/55 max-[439px]:w-[232px] min-[440px]:w-[230px] sm:w-[240px] lg:w-[246.4px] min-[1100px]:max-xl:w-[273px] xl:w-[246.4px]";
type RecommendedResource = Resource & {
downloadPostId?: string;
downloadAttachmentId?: string;
};
export function RecommendedCard({
r,
visualIndex = 0,
}: {
r: Resource;
r: RecommendedResource;
visualIndex?: number;
}) {
const { t } = useI18n();
@@ -83,7 +88,13 @@ export function RecommendedCard({
e.preventDefault();
e.stopPropagation();
try {
await postJSON(`/api/resources/${r.id}/download`, {});
if (r.downloadPostId && r.downloadAttachmentId) {
await postNoBody(
`/api/posts/${r.downloadPostId}/attachments/${r.downloadAttachmentId}/download`,
);
} else {
await postJSON(`/api/resources/${r.id}/download`, {});
}
} catch {
/* ignore */
}