Merge pull request #104 from linkwarden/dev

Updated the dependencies
This commit is contained in:
Daniel 2023-08-01 22:23:57 -04:00 committed by GitHub
commit 501e9e59e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 854 additions and 826 deletions

View File

@ -1,15 +1,22 @@
import { GetObjectCommand, GetObjectCommandInput } from "@aws-sdk/client-s3";
import {
GetObjectCommand,
GetObjectCommandInput,
S3,
} from "@aws-sdk/client-s3";
import fs from "fs";
import path from "path";
import s3Client from "./s3Client";
import util from "util";
export default async function readFile({ filePath }: { filePath: string }) {
let contentType:
type ReturnContentTypes =
| "text/plain"
| "image/jpeg"
| "image/png"
| "application/pdf";
export default async function readFile({ filePath }: { filePath: string }) {
let contentType: ReturnContentTypes;
if (s3Client) {
const bucketParams: GetObjectCommandInput = {
Bucket: process.env.BUCKET_NAME,
@ -17,7 +24,32 @@ export default async function readFile({ filePath }: { filePath: string }) {
};
try {
const response = await s3Client.send(new GetObjectCommand(bucketParams));
let returnObject:
| {
file: Buffer | string;
contentType: ReturnContentTypes;
}
| undefined;
const headObjectAsync = util.promisify(
s3Client.headObject.bind(s3Client)
);
try {
await headObjectAsync(bucketParams);
} catch (err) {
contentType = "text/plain";
returnObject = {
file: "File not found, it's possible that the file you're looking for either doesn't exist or hasn't been created yet.",
contentType,
};
}
if (!returnObject) {
const response = await (s3Client as S3).send(
new GetObjectCommand(bucketParams)
);
const data = await streamToBuffer(response.Body);
if (filePath.endsWith(".pdf")) {
@ -28,15 +60,16 @@ export default async function readFile({ filePath }: { filePath: string }) {
// if (filePath.endsWith(".jpg"))
contentType = "image/jpeg";
}
returnObject = { file: data as Buffer, contentType };
}
return { file: data, contentType };
return returnObject;
} catch (err) {
console.log("Error", err);
console.log("Error:", err);
contentType = "text/plain";
return {
file: "File not found, it's possible that the file you're looking for either doesn't exist or hasn't been created yet.",
file: "An internal occurred, please contact support.",
contentType,
};
}

View File

@ -14,7 +14,7 @@
},
"dependencies": {
"@auth/prisma-adapter": "^1.0.1",
"@aws-sdk/client-s3": "^3.363.0",
"@aws-sdk/client-s3": "^3.379.1",
"@fortawesome/fontawesome-svg-core": "^6.4.0",
"@fortawesome/free-regular-svg-icons": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
@ -31,9 +31,10 @@
"bcrypt": "^5.1.0",
"colorthief": "^2.4.0",
"crypto-js": "^4.1.1",
"eslint": "8.44.0",
"csstype": "^3.1.2",
"eslint": "8.46.0",
"eslint-config-next": "13.4.9",
"next": "13.1.6",
"next": "13.4.12",
"next-auth": "^4.22.1",
"nodemailer": "^6.9.3",
"playwright": "^1.35.1",
@ -42,7 +43,7 @@
"react-dom": "18.2.0",
"react-hot-toast": "^2.4.1",
"react-image-file-resizer": "^0.4.8",
"react-select": "^5.7.3",
"react-select": "^5.7.4",
"sharp": "^0.32.1",
"stripe": "^12.13.0",
"typescript": "4.9.4",
@ -53,7 +54,7 @@
"@types/bcrypt": "^5.0.0",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.26",
"prisma": "^4.16.2",
"prisma": "^5.1.0",
"tailwindcss": "^3.3.3"
}
}

1598
yarn.lock

File diff suppressed because it is too large Load Diff