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

@@ -9,10 +9,9 @@ import {
} from "react";
import { createPortal } from "react-dom";
import { ChevronLeft, ChevronRight, Download, X } from "lucide-react";
import { postNoBody } from "../../../api";
import type { Attachment } from "../../../types/post";
import { autolink } from "../utils/autolink";
import { downloadFile } from "../utils/downloadFile";
import { downloadAttachment, downloadFile } from "../utils/downloadFile";
type LightboxState = {
images: Attachment[];
@@ -143,11 +142,12 @@ function LightboxView({
onClick={(e) => {
e.stopPropagation();
if (postId) {
void postNoBody(
`/api/posts/${postId}/attachments/${current.id}/download`,
void downloadAttachment(postId, current.id, current.filename).catch(
() => {},
);
} else {
void downloadFile(current.url, current.filename).catch(() => {});
}
void downloadFile(current.url, current.filename).catch(() => {});
}}
className="absolute right-16 top-4 z-10 flex h-10 w-10 items-center justify-center rounded-full bg-white/10 text-white transition hover:bg-white/20"
aria-label="Download"