mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
fix: implement feedback
This commit is contained in:
@ -47,8 +47,6 @@ export default async function DocumentPage({ params }: DocumentPageProps) {
|
||||
.then((buffer) => Buffer.from(buffer).toString('base64'))
|
||||
.then((data) => `data:application/pdf;base64,${data}`);
|
||||
|
||||
console.log({ documentDataUrl: documentDataUrl.slice(0, 40) });
|
||||
|
||||
const [recipients, fields] = await Promise.all([
|
||||
await getRecipientsForDocument({
|
||||
documentId,
|
||||
|
||||
@ -14,15 +14,9 @@ import {
|
||||
XCircle,
|
||||
} from 'lucide-react';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { match } from 'ts-pattern';
|
||||
|
||||
import {
|
||||
Document,
|
||||
DocumentDataType,
|
||||
DocumentStatus,
|
||||
Recipient,
|
||||
User,
|
||||
} from '@documenso/prisma/client';
|
||||
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
||||
import { Document, DocumentStatus, Recipient, User } from '@documenso/prisma/client';
|
||||
import { DocumentWithData } from '@documenso/prisma/types/document-with-data';
|
||||
import { trpc } from '@documenso/trpc/client';
|
||||
import {
|
||||
@ -75,23 +69,7 @@ export const DataTableActionDropdown = ({ row }: DataTableActionDropdownProps) =
|
||||
return;
|
||||
}
|
||||
|
||||
const documentBytes = await match(documentData.type)
|
||||
.with(DocumentDataType.BYTES, () =>
|
||||
Uint8Array.from(documentData.data, (c) => c.charCodeAt(0)),
|
||||
)
|
||||
.with(DocumentDataType.BYTES_64, () =>
|
||||
Uint8Array.from(
|
||||
atob(documentData.data)
|
||||
.split('')
|
||||
.map((c) => c.charCodeAt(0)),
|
||||
),
|
||||
)
|
||||
.with(DocumentDataType.S3_PATH, async () =>
|
||||
fetch(documentData.data)
|
||||
.then(async (res) => res.arrayBuffer())
|
||||
.then((buffer) => new Uint8Array(buffer)),
|
||||
)
|
||||
.exhaustive();
|
||||
const documentBytes = await getFile(documentData);
|
||||
|
||||
const blob = new Blob([documentBytes], {
|
||||
type: 'application/pdf',
|
||||
|
||||
@ -7,6 +7,7 @@ import { Download } from 'lucide-react';
|
||||
import { getFile } from '@documenso/lib/universal/upload/get-file';
|
||||
import { DocumentData } from '@documenso/prisma/client';
|
||||
import { Button } from '@documenso/ui/primitives/button';
|
||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
||||
|
||||
export type DownloadButtonProps = HTMLAttributes<HTMLButtonElement> & {
|
||||
disabled?: boolean;
|
||||
@ -21,6 +22,8 @@ export const DownloadButton = ({
|
||||
disabled,
|
||||
...props
|
||||
}: DownloadButtonProps) => {
|
||||
const { toast } = useToast();
|
||||
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const onDownloadClick = async () => {
|
||||
@ -47,6 +50,12 @@ export const DownloadButton = ({
|
||||
window.URL.revokeObjectURL(link.href);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: 'An error occurred while downloading your document.',
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
@ -35,9 +35,15 @@ const getFileFromBytes64 = (data: string) => {
|
||||
const getFileFromS3 = async (key: string) => {
|
||||
const { url } = await getPresignGetUrl(key);
|
||||
|
||||
const buffer = await fetch(url, {
|
||||
const response = await fetch(url, {
|
||||
method: 'GET',
|
||||
}).then(async (res) => res.arrayBuffer());
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to get file "${key}", failed with status code ${response.status}`);
|
||||
}
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
const binaryData = new Uint8Array(buffer);
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ const putFileInS3 = async (file: File) => {
|
||||
|
||||
const body = await file.arrayBuffer();
|
||||
|
||||
await fetch(url, {
|
||||
const reponse = await fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
@ -46,6 +46,12 @@ const putFileInS3 = async (file: File) => {
|
||||
body,
|
||||
});
|
||||
|
||||
if (!reponse.ok) {
|
||||
throw new Error(
|
||||
`Failed to upload file "${file.name}", failed with status code ${reponse.status}`,
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
type: DocumentDataType.S3_PATH,
|
||||
data: key,
|
||||
|
||||
@ -42,11 +42,15 @@ const updateFileWithBytes64 = (data: string) => {
|
||||
const updateFileWithS3 = async (key: string, data: string) => {
|
||||
const { url } = await getAbsolutePresignPostUrl(key);
|
||||
|
||||
await fetch(url, {
|
||||
const response = await fetch(url, {
|
||||
method: 'PUT',
|
||||
body: data,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to update file "${key}", failed with status code ${response.status}`);
|
||||
}
|
||||
|
||||
return {
|
||||
type: DocumentDataType.S3_PATH,
|
||||
data: key,
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Document" ADD COLUMN "createdAt" TIMESTAMP(3);
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Document" ADD COLUMN "updatedAt" TIMESTAMP(3);
|
||||
|
||||
-- DefaultValues
|
||||
@ -9,5 +11,9 @@ SET
|
||||
"updatedAt" = COALESCE("created"::TIMESTAMP, NOW());
|
||||
|
||||
-- AlterColumn
|
||||
ALTER TABLE "Document" ALTER COLUMN "createdAt" SET NOT NULL DEFAULT NOW();
|
||||
ALTER TABLE "Document" ALTER COLUMN "updatedAt" SET NOT NULL DEFAULT NOW();
|
||||
ALTER TABLE "Document" ALTER COLUMN "createdAt" SET DEFAULT NOW();
|
||||
ALTER TABLE "Document" ALTER COLUMN "createdAt" SET NOT NULL;
|
||||
|
||||
-- AlterColumn
|
||||
ALTER TABLE "Document" ALTER COLUMN "updatedAt" SET DEFAULT NOW();
|
||||
ALTER TABLE "Document" ALTER COLUMN "updatedAt" SET NOT NULL;
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to drop the column `created` on the `Document` table. All the data in the column will be lost.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "Document" DROP COLUMN "created";
|
||||
@ -92,7 +92,6 @@ enum DocumentStatus {
|
||||
|
||||
model Document {
|
||||
id Int @id @default(autoincrement())
|
||||
created DateTime @default(now())
|
||||
userId Int
|
||||
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
title String
|
||||
|
||||
Reference in New Issue
Block a user