@bash-app/bash-common 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bash-app/bash-common",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Common data and scripts to use on the frontend and backend",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -24,9 +24,9 @@
24
24
  "typescript": "^5.2.2"
25
25
  },
26
26
  "peerDependencies": {
27
- "tsx": "^4.10.3",
28
27
  "dayjs": "^1.11.10",
29
- "react-tailwindcss-datepicker": "^1.6.6"
28
+ "react-tailwindcss-datepicker": "^1.6.6",
29
+ "tsx": "^4.10.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@prisma/client": "^5.13.0",
@@ -4,7 +4,24 @@ import {DeleteObjectCommandOutput} from "@aws-sdk/client-s3/dist-types/commands"
4
4
 
5
5
 
6
6
  export class AwsS3Utils {
7
- static async uploadFile(file: Blob, preSignedUrl: string | undefined, mimetype: string): Promise<boolean> {
7
+ static async uploadBase64String(base64Str: string, assetKey: string): Promise<string | undefined> {
8
+ const bufferData = Buffer.from(base64Str, 'base64');
9
+ const blobData = new Blob([bufferData]);
10
+ return AwsS3Utils.uploadFile(blobData, assetKey, 'text/plain');
11
+ }
12
+
13
+ static async uploadFile(file: Blob, assetKey: string, mimetype: string): Promise<string | undefined> {
14
+ const preSignedUrl = await AwsS3Utils.createPreSignedUrl(assetKey, mimetype);
15
+ const assetUrl = AwsS3Utils.createUrlFromAssetKey(assetKey);
16
+ const uploadSuccessful = await AwsS3Utils.uploadFileViaPreSignedUrl(file, preSignedUrl, mimetype);
17
+ if (uploadSuccessful) {
18
+ return assetUrl;
19
+ }
20
+ }
21
+
22
+ static async uploadFileViaPreSignedUrl(file: Blob,
23
+ preSignedUrl: string | undefined,
24
+ mimetype: string): Promise<boolean> {
8
25
  try {
9
26
  if (!file) {
10
27
  throw new Error('The file data buffer was undefined; no data to upload.');
@@ -16,7 +33,7 @@ export class AwsS3Utils {
16
33
  const res = await fetch(preSignedUrl, {
17
34
  method: 'PUT',
18
35
  headers: {
19
- 'Content-Type': mimetype,
36
+ 'Content-Type': mimetype
20
37
  },
21
38
  body: file
22
39
  });
@@ -56,7 +73,7 @@ export class AwsS3Utils {
56
73
  ContentType: mimetype
57
74
  });
58
75
  return getSignedUrl(client, command, {
59
- expiresIn: 3600
76
+ expiresIn: 3600,
60
77
  });
61
78
  }
62
79