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