Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): add file upload core plugin #368

Merged
merged 28 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
825453b
chore: initialise the plugin
Shurtu-gal Apr 12, 2024
e6c0e8b
chore: add packageJson event
Shurtu-gal Apr 12, 2024
18fe52e
feat: add createAppModule and static files events
Shurtu-gal Apr 12, 2024
e7db10a
feat: add controller events
Shurtu-gal Apr 13, 2024
901fa59
feat: add createMainFile events
Shurtu-gal Apr 13, 2024
19ee08d
feat: add module creation
Shurtu-gal Apr 13, 2024
04ac230
feat: add resolver base creation event
Shurtu-gal Apr 13, 2024
204f638
feat: initialise local storage plugin
Shurtu-gal Apr 14, 2024
e193f24
feat: add events for addition of provider files
Shurtu-gal Apr 14, 2024
56638ef
feat: add provider service in constructor call
Shurtu-gal Apr 14, 2024
98d7e92
feat: make functions in service base as well
Shurtu-gal Apr 14, 2024
bc93c20
chore: add default path for no settings
Shurtu-gal Apr 14, 2024
90a8761
fix: minor changes to get the generated app to work
Shurtu-gal Apr 14, 2024
b290251
chore: remove bigIntTemplate
Shurtu-gal Apr 15, 2024
a9c9886
chore: change version of @amplication/code-gen-types
Shurtu-gal Apr 16, 2024
2df1006
chore: change version of @amplication/code-gen-types
Shurtu-gal Apr 16, 2024
a100c84
Merge branch 'master' into feat/file-upload-core
Shurtu-gal Apr 16, 2024
314c49f
chore: change plugin names to storage
Shurtu-gal Apr 27, 2024
1d2aaf9
chore: change plugin names to storage
Shurtu-gal Apr 27, 2024
66efb04
chore: update README
Shurtu-gal Apr 28, 2024
26cd6f3
chore: update package-lock
Shurtu-gal Apr 29, 2024
1f06b5a
chore(storage): fix deps and nx target name
overbit Apr 29, 2024
ba44511
Merge branch 'feat/file-upload-core' of github.com:Shurtu-gal/plugins…
overbit Apr 29, 2024
3f5290f
chore: add main file test
Shurtu-gal Apr 29, 2024
e594f72
chore: add tests for creation of methods
Shurtu-gal Apr 29, 2024
1af498d
chore: add tests for creation of storage module
Shurtu-gal Apr 29, 2024
3faecc1
chore: ignore tests in tsconfig
Shurtu-gal Apr 29, 2024
e2b190b
chore: fix linting issues
Shurtu-gal Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules
**/static
**/ast.ts

**/templates
**/templates
**/fixtures
213 changes: 210 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions plugins/storage-core/.amplicationrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"settings": {}
}
4 changes: 4 additions & 0 deletions plugins/storage-core/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"]
}
36 changes: 36 additions & 0 deletions plugins/storage-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Mac/OSX
.DS_Store

# Private Files
*.csv
*.csv.gz
*.tsv
*.tsv.gz
*.xlsx

# Build Files
dist/

# Private Node Modules
node_modules/
creds.js

# VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

# Common credential files
**/credentials.json
**/client_secrets.json
**/client_secret.json
*creds*
*.dat
*password*
*.httr-oauth*
2 changes: 2 additions & 0 deletions plugins/storage-core/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.prettierignore
.gitignore
1 change: 1 addition & 0 deletions plugins/storage-core/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
71 changes: 71 additions & 0 deletions plugins/storage-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# @amplication/plugin-storage-core

[![NPM Downloads](https://img.shields.io/npm/dt/@amplication/plugin-storage-core)](https://www.npmjs.com/package/@amplication/plugin-storage-core)

## Purpose

This plugin is used for integrating storage services into your app generated by Amplication. The plugin will add the required core functionality on top of which other storage services can be built.

> [!CAUTION]
> The other storage plugins should have plugin ids of the form `storage-<provider>` and should be added through the plugins page of the app settings before adding this plugin to get the expected functionality.

## Working with the plugin

It can be used by adding the plugin in the `plugins` page of the app settings. For this plugin, no additional settings are required.

> [!NOTE]
> There should be enitities with fields of data type `File` for this plugin to generate any additional functionality.

## What the plugin does

### Adds resolver and controller methods

The following methods are added for each field of type `File` in the entities:

**Resolver methods:**

- upload< FieldName in PascalCase >: Upload a file to the storage service.
- delete< FieldName in PascalCase >: Delete the file from the storage service.

**Controller methods:**

- upload< FieldName in PascalCase >: Upload a file to the storage service.
- delete< FieldName in PascalCase >: Delete the file from the storage service.
- download< FieldName in PascalCase >: Download the file from the storage service.

### Generates the configuration for file upload services

It adds graphqlUploadExpress middleware to the express app to let the app handle file uploads.

### Adds the storage core service abstract class

The plugin adds the `StorageService` abstract class which can be extended to create storage services for different storage providers. The class does the following:

- Checks if the file is of the correct mimetype and size.
- Generates a unique file name.
- Gives proper mime type while downloading the file.

### How is file upload handled?

When a file is uploaded, the file is saved through the storage service and the following JSON is saved in the database:

```json
{
"uuid": "/path/to/file", // UUID for the file (can be used to retrieve the file eg. URL or file path)
"filename": "profilePicture-<id of entity>",
"mimetype": "image/jpeg",
"encoding": "7bit",
"size": 123456, // File size in bytes
"metadata": {} // Provider specific metadata
}
```

## Scripts

### `build`

Running `npm run build` will bundle your plugin with Webpack for production.

### `dev`

Running `npm run dev` will watch your plugin's source code and automatically bundle it with every change.
Loading
Loading