fix: implement feedback

This commit is contained in:
Mythie
2023-09-14 13:21:03 +10:00
parent 5a99a0b5eb
commit 0835da45ef
9 changed files with 48 additions and 34 deletions
+8 -2
View File
@@ -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);
+7 -1
View File
@@ -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,
+5 -1
View File
@@ -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";
-1
View File
@@ -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