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,8 +1,7 @@
import { ArrowDownToLine } from "lucide-react";
import { postNoBody } from "../../../api";
import { useI18n } from "../../../i18n";
import type { Attachment, Post } from "../../../types/post";
import { downloadFile } from "../utils/downloadFile";
import { downloadAttachment } from "../utils/downloadFile";
import { fileIcon } from "../utils/fileIcon";
import {
filenameWithExtension,
@@ -17,8 +16,7 @@ function AttachmentRow({ postId, att }: { postId: string; att: Attachment }) {
const displayFilename = filenameWithExtension(att.filename, att.mime);
const handleDownload = () => {
void postNoBody(`/api/posts/${postId}/attachments/${att.id}/download`);
void downloadFile(att.url, displayFilename).catch(() => {});
void downloadAttachment(postId, att.id, displayFilename).catch(() => {});
};
return (

View File

@@ -1,11 +1,10 @@
import { ArrowDownToLine, Play } from "lucide-react";
import { useRef, useState } from "react";
import { postNoBody } from "../../../api";
import { useI18n } from "../../../i18n";
import type { Post } from "../../../types/post";
import { useVideoPlayer } from "../overlays/VideoPlayer";
import { autolink } from "../utils/autolink";
import { downloadFile } from "../utils/downloadFile";
import { downloadAttachment } from "../utils/downloadFile";
import { formatBytes } from "../utils/formatBytes";
import { postDisplayText } from "../utils/postText";
@@ -74,10 +73,9 @@ export function VideoBubble({ post }: { post: Post }) {
type="button"
onClick={(e) => {
e.stopPropagation();
void postNoBody(
`/api/posts/${post.id}/attachments/${att.id}/download`,
void downloadAttachment(post.id, att.id, att.filename).catch(
() => {},
);
void downloadFile(att.url, att.filename).catch(() => {});
}}
className="group absolute left-3 top-3 z-10 inline-flex overflow-hidden rounded-full bg-black/45 text-xs text-white shadow-lg ring-1 ring-white/15 backdrop-blur-md transition hover:bg-black/60"
aria-label={`Download ${att.filename}`}