Skip to content

Commit 6f56d6e

Browse files
allow glob patterns
1 parent 5b21a19 commit 6f56d6e

File tree

38 files changed

+31681
-35088
lines changed

38 files changed

+31681
-35088
lines changed

README.md

+8-106
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ This package is a configurable rocket to add a storage API to your Booster appli
55
## Supported Providers
66

77
- Azure Provider
8-
- AWS Provider
98
- Local Provider
109

1110
## Overview
@@ -15,7 +14,6 @@ This rocket provides some methods to access files stores in your cloud provider:
1514
- `presignedPut`: Returns a presigned put url and the necessary form params. With this url files can be uploaded directly to your provider.
1615
- `presignedGet`: Returns a presigned get url to download a file. With this url files can be downloaded directly from your provider.
1716
- `list`: Returns a list of files stored in the provider.
18-
- `deleteFile`: Removes a file from a directory (only supported in AWS at the moment).
1917

2018
These methods may be used from a Command in your project secured via JWT Token.
2119

@@ -37,12 +35,6 @@ _Azure Provider:_
3735
npm install --save @boostercloud/rocket-file-uploads-azure
3836
```
3937

40-
_AWS Provider:_
41-
42-
```bash
43-
npm install --save @boostercloud/rocket-file-uploads-aws
44-
```
45-
4638
_Local Provider:_
4739

4840
```bash
@@ -57,12 +49,6 @@ _Azure Provider_
5749
npm install --save-dev @boostercloud/rocket-file-uploads-azure-infrastructure
5850
```
5951

60-
_AWS Provider_
61-
62-
```bash
63-
npm install --save-dev @boostercloud/rocket-file-uploads-aws-infrastructure
64-
```
65-
6652
_Local Provider:_
6753

6854
```bash
@@ -79,7 +65,7 @@ import { RocketFilesUserConfiguration } from '@boostercloud/rocket-file-uploads-
7965

8066
const rocketFilesConfigurationDefault: RocketFilesUserConfiguration = {
8167
storageName: 'clientst',
82-
containerName: 'rocketfiles', // Not used in AWS (you can just pass '' in this case)
68+
containerName: 'rocketfiles',
8369
directories: ['client1', 'client2'],
8470
}
8571

@@ -100,15 +86,6 @@ Booster.configure('production', (config: BoosterConfig): void => {
10086
]
10187
})
10288

103-
// AWS Config:
104-
Booster.configure('production', (config: BoosterConfig): void => {
105-
config.appName = APP_NAME
106-
config.providerPackage = '@boostercloud/framework-provider-aws'
107-
config.rockets = [
108-
new BoosterRocketFiles(config, [rocketFilesConfigurationDefault, rocketFilesConfigurationCms]).rocketForAWS(),
109-
]
110-
})
111-
11289
// Local Config:
11390
Booster.configure('local', (config: BoosterConfig): void => {
11491
config.appName = APP_NAME
@@ -123,8 +100,8 @@ Booster.configure('local', (config: BoosterConfig): void => {
123100
Available parameters are:
124101

125102
- `storageName`: Name of the storage repository.
126-
- `containerName`: Directories container (not used in AWS).
127-
- `directories` A list of folders where the files will be stored
103+
- `containerName`: Directories container.
104+
- `directories` A list of dirs to be watched, or [glob patterns](https://en.wikipedia.org/wiki/Glob_(programming))
128105

129106
> [!NOTE] Azure Provider will use `storageName` as the **Storage Account Name**.
130107
> Local Provider will use it as the **root folder name**
@@ -138,10 +115,6 @@ The structure created for Azure and the Local Provider will be:
138115
> http://localhost:3000/storageName/containerName/filename.ext but for Azure:
139116
> http://storageAccountUrl:3000/containerName/filename.ext
140117
141-
The `container` parameter is **not used** in AWS, so the structure created will be:
142-
> * storage
143-
> * directory
144-
145118

146119
### PresignedPut Usage
147120

@@ -245,76 +218,6 @@ Local Provider will write files on `.<storageName>/rocketfiles` folder
245218

246219
**Note**: Azure will return a 201 status but Local will return a 200
247220

248-
#### AWS
249-
250-
Create a command in your application and call the `presignedGet` method on the FileHandler class with the `directory` and `filename` you want to get on the storage.
251-
252-
The `storageName` parameter is optional. It will use the first storage if undefined.
253-
254-
```typescript
255-
import { Booster, Command } from '@boostercloud/framework-core'
256-
import { Register } from '@boostercloud/framework-types'
257-
import { FileHandler } from '@boostercloud/rocket-file-uploads-core'
258-
259-
// AWS returns these fields in the response:
260-
export class PresignedPostResponse {
261-
public constructor(
262-
readonly url: string,
263-
readonly fields: { [key: string]: string }
264-
){}
265-
}
266-
267-
@Command({
268-
authorize: 'all', // Add an authentiation role as needed.
269-
})
270-
export class FileUploadGet {
271-
public constructor(readonly directory: string, readonly fileName: string, readonly storageName?: string) {}
272-
273-
public static async handle(command: FileUploadGet, register: Register): Promise<PresignedPostResponse> {
274-
const boosterConfig = Booster.config
275-
const fileHandler = new FileHandler(boosterConfig, command.storageName)
276-
return await fileHandler.presignedGet(command.directory, command.fileName)
277-
}
278-
}
279-
```
280-
281-
GraphQL mutation example:
282-
283-
```
284-
mutation {
285-
FileUploadPut(input: {
286-
directory: "files",
287-
fileName: "lol.jpg"
288-
}) {
289-
url
290-
fields
291-
}
292-
}
293-
```
294-
295-
296-
AWS Response:
297-
298-
```
299-
{
300-
"data": {
301-
"FileUploadPut": {
302-
"url": "https://s3.eu-west-1.amazonaws.com/myappstorage",
303-
"fields": {
304-
"Key": "files/lol.jpg",
305-
"bucket": "myappstorage",
306-
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
307-
"X-Amz-Credential": "blablabla.../eu-west-1/s3/aws4_request",
308-
"X-Amz-Date": "20230207T142138Z",
309-
"X-Amz-Security-Token": "IQoJb3JpZ2... blablabla",
310-
"Policy": "eyJleHBpcmF0a... blablabla",
311-
"X-Amz-Signature": "60511... blablabla"
312-
}
313-
}
314-
}
315-
}
316-
```
317-
318221
### PresignedGet Usage
319222

320223
Create a command in your application and call the `presignedGet` method on the FileHandler class with the `directory` and `filename` you want to get on the storage.
@@ -418,7 +321,7 @@ mutation {
418321
}
419322
```
420323

421-
This returns the following payload in Azure and AWS:
324+
This returns the following payload in Azure:
422325

423326
```json
424327
{
@@ -504,7 +407,7 @@ This returns the following payload:
504407
{
505408
"id": "f119ef635226888dd1bacd734f8955db",
506409
"metadata": {
507-
// A bunch of fields (depending on Azure or AWS)
410+
// A bunch of fields (depending on Azure)
508411
}
509412
],
510413
"count": 1,
@@ -544,7 +447,7 @@ For Local
544447

545448
For each upload file a new event will be generated.
546449

547-
On Azure and AWS, the event will be like this:
450+
On Azure, the event will be like this:
548451

549452
```json
550453
{
@@ -558,7 +461,7 @@ On Azure and AWS, the event will be like this:
558461
"value": {
559462
"id": "xxx",
560463
"metadata": {
561-
// A bunch of fields (depending on Azure or AWS)
464+
// A bunch of fields (depending on Azure)
562465
}
563466
},
564467
"createdAt": "2022-10-26T10:23:36.562Z",
@@ -636,7 +539,6 @@ az role assignment create \
636539
Local Provider doesn't check `paths`. You should check that the `directory` and `files` passed as paratemers are valid.
637540

638541
### TODOs:
639-
- Add file deletion to Azure and Local (only supported in AWS at the moment).
640542
- Optional storage deletion when unmounting the stack.
641543
- Optional events, in case you don't want to store that information in the events-store.
642-
- When deleting a file, save a deletion event in the events-store. Only uploads are stored at the moment.
544+
- When deleting a file, save a deletion event in the events-store. Only uploads are stored at the moment.

0 commit comments

Comments
 (0)