feat: add file viewer and downloads

This commit is contained in:
Henry
2025-11-14 22:15:28 +00:00
parent 070fc373f2
commit f495ca3505
9 changed files with 286 additions and 35 deletions

View File

@@ -197,7 +197,11 @@ export const attachmentRouter = createTRPCRouter({
code: "INTERNAL_SERVER_ERROR",
});
const url = await generateDownloadUrl(bucket, attachment.s3Key, 3600);
const url = await generateDownloadUrl(
bucket,
attachment.s3Key,
86400, // 24 hours expiration
);
return { url, filename: attachment.originalFilename };
}),

View File

@@ -586,6 +586,7 @@ export const cardRouter = createTRPCRouter({
contentType: string;
s3Key: string;
originalFilename: string | null;
size?: number | null;
url: string | null;
}[];
}
@@ -634,6 +635,7 @@ export const cardRouter = createTRPCRouter({
contentType: string;
s3Key: string;
originalFilename: string | null;
size?: number | null;
}[];
const attachmentsWithUrls = await Promise.all(
@@ -643,6 +645,7 @@ export const cardRouter = createTRPCRouter({
contentType: attachment.contentType,
s3Key: attachment.s3Key,
originalFilename: attachment.originalFilename,
size: attachment.size,
};
if (!bucket || !attachment.s3Key) {
return { ...base, url: null };
@@ -651,7 +654,7 @@ export const cardRouter = createTRPCRouter({
const url = await generateDownloadUrl(
bucket,
attachment.s3Key,
3600, // 1 hour expiration
86400, // 24 hours expiration
);
return { ...base, url };
} catch {

View File

@@ -5,6 +5,7 @@ import type { BoardVisibilityStatus } from "@kan/db/schema";
import {
boards,
cardActivities,
cardAttachments,
cards,
cardsToLabels,
cardToWorkspaceMembers,
@@ -196,6 +197,13 @@ export const getByPublicId = async (
},
},
},
attachments: {
columns: {
publicId: true,
},
where: isNull(cardAttachments.deletedAt),
orderBy: asc(cardAttachments.createdAt),
},
checklists: {
columns: {
publicId: true,
@@ -358,6 +366,13 @@ export const getBySlug = async (
},
},
},
attachments: {
columns: {
publicId: true,
},
where: isNull(cardAttachments.deletedAt),
orderBy: asc(cardAttachments.createdAt),
},
comments: {
columns: {
publicId: true,

View File

@@ -3,6 +3,7 @@ import { and, asc, desc, eq, gt, inArray, isNull, sql } from "drizzle-orm";
import type { dbClient } from "@kan/db/client";
import {
cardActivities,
cardAttachments,
cards,
cardsToLabels,
cardToWorkspaceMembers,
@@ -415,7 +416,10 @@ export const getWithListAndMembersByPublicId = async (
contentType: true,
s3Key: true,
originalFilename: true,
size: true,
},
where: isNull(cardAttachments.deletedAt),
orderBy: asc(cardAttachments.createdAt),
},
checklists: {
columns: {