Skip to content

Commit

Permalink
feat: add download only icon to document and add missing fileSize
Browse files Browse the repository at this point in the history
  • Loading branch information
mfts committed Nov 18, 2024
1 parent f0baf80 commit befa2ab
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
15 changes: 14 additions & 1 deletion components/documents/document-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Document, DocumentVersion } from "@prisma/client";
import {
AlertCircleIcon,
BetweenHorizontalStartIcon,
CloudDownloadIcon,
FileDownIcon,
SheetIcon,
Sparkles,
Expand Down Expand Up @@ -455,6 +456,15 @@ export default function DocumentHeader({
</span>
</ButtonTooltip>
)}

{prismaDocument.downloadOnly && (
<ButtonTooltip content="Download only">
<span className="text-xs">
<CloudDownloadIcon className="h-6 w-6" />
<span className="sr-only">This document is download only</span>
</span>
</ButtonTooltip>
)}
</div>

<div className="flex items-center gap-x-4 md:gap-x-2">
Expand Down Expand Up @@ -508,6 +518,7 @@ export default function DocumentHeader({

{prismaDocument.type !== "notion" &&
prismaDocument.type !== "sheet" &&
prismaDocument.type !== "zip" &&
prismaDocument.assistantEnabled && (
<Button
className="group hidden h-8 space-x-1 whitespace-nowrap bg-gradient-to-r from-[#16222A] via-emerald-500 to-[#16222A] text-xs duration-200 ease-linear hover:bg-right md:flex lg:h-9 lg:text-sm"
Expand Down Expand Up @@ -580,7 +591,8 @@ export default function DocumentHeader({
</DropdownMenuItem>

{prismaDocument.type !== "notion" &&
prismaDocument.type !== "sheet" && (
prismaDocument.type !== "sheet" &&
prismaDocument.type !== "zip" && (
<DropdownMenuItem
onClick={() =>
activateOrRedirectAssistant(prismaDocument)
Expand All @@ -595,6 +607,7 @@ export default function DocumentHeader({
</DropdownMenuGroup>
{primaryVersion.type !== "notion" &&
primaryVersion.type !== "sheet" &&
primaryVersion.type !== "zip" &&
(!prismaDocument.assistantEnabled ? (
<DropdownMenuItem
onClick={() =>
Expand Down
3 changes: 2 additions & 1 deletion components/links/link-sheet/agreement-panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default function AgreementSheet({
return;
}

const { type, data, numPages } = await putFile({
const { type, data, numPages, fileSize } = await putFile({
file: currentFile,
teamId: teamId!,
});
Expand All @@ -83,6 +83,7 @@ export default function AgreementSheet({
storageType: type!,
contentType: contentType,
supportedFileType: supportedFileType,
fileSize: fileSize,
};
// create a document in the database
const response = await createAgreementDocument({
Expand Down
3 changes: 2 additions & 1 deletion components/welcome/containers/upload-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function UploadContainer({
return;
}

const { type, data, numPages } = await putFile({
const { type, data, numPages, fileSize } = await putFile({
file: currentFile,
teamId,
});
Expand All @@ -74,6 +74,7 @@ export function UploadContainer({
storageType: type!,
contentType: contentType,
supportedFileType: supportedFileType,
fileSize: fileSize,
};
// create a document in the database
const response = await createDocument({
Expand Down
3 changes: 2 additions & 1 deletion components/welcome/special-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function DeckGeneratorUpload() {
return;
}

const { type, data, numPages } = await putFile({
const { type, data, numPages, fileSize } = await putFile({
file: currentFile,
teamId,
});
Expand All @@ -106,6 +106,7 @@ export default function DeckGeneratorUpload() {
storageType: type!,
contentType: contentType,
supportedFileType: supportedFileType,
fileSize: fileSize,
};
// create a document in the database
const response = await createDocument({
Expand Down
1 change: 1 addition & 0 deletions lib/documents/create-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const createAgreementDocument = async ({
folderPathName: folderPathName,
type: documentData.supportedFileType,
contentType: documentData.contentType,
fileSize: documentData.fileSize,
}),
});

Expand Down
20 changes: 20 additions & 0 deletions pages/api/teams/[teamId]/documents/agreement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { errorhandler } from "@/lib/errorHandler";
import notion from "@/lib/notion";
import prisma from "@/lib/prisma";
import { getTeamWithUsersAndDocument } from "@/lib/team/helper";
import { convertFilesToPdfTask } from "@/lib/trigger/convert-files";
import { CustomUser } from "@/lib/types";
import { getExtension, log } from "@/lib/utils";

Expand Down Expand Up @@ -38,13 +39,15 @@ export default async function handle(
numPages,
type: fileType,
folderPathName,
fileSize,
} = req.body as {
name: string;
url: string;
storageType: DocumentStorageType;
numPages?: number;
type?: string;
folderPathName?: string;
fileSize?: number;
};

try {
Expand Down Expand Up @@ -94,6 +97,7 @@ export default async function handle(
type: type,
storageType,
numPages: numPages,
fileSize: fileSize,
isPrimary: true,
versionNumber: 1,
},
Expand All @@ -106,6 +110,22 @@ export default async function handle(
},
});

if (type === "docs") {
console.log("converting docx to pdf");
// Trigger convert-files-to-pdf task
await convertFilesToPdfTask.trigger(
{
documentId: document.id,
documentVersionId: document.versions[0].id,
teamId,
},
{
idempotencyKey: `${teamId}-${document.versions[0].id}`,
tags: [`team_${teamId}`, `document_${document.id}`],
},
);
}

// skip triggering convert-pdf-to-image job for "notion" / "excel" documents
if (type === "pdf") {
// trigger document uploaded event to trigger convert-pdf-to-image job
Expand Down

0 comments on commit befa2ab

Please sign in to comment.