Skip to content

Commit

Permalink
feat: add google storage
Browse files Browse the repository at this point in the history
closes  #6
* organise exports from the library
* organise documentatation - move to .md file
  • Loading branch information
wojtek-krysiak committed Sep 30, 2020
1 parent c3b3955 commit 8344450
Show file tree
Hide file tree
Showing 25 changed files with 1,188 additions and 308 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
'*.txt',
'yarn.lock',
'*.yaml',
'*.md',
'*/public/**/*',
],
parser: '@typescript-eslint/parser',
Expand Down
3 changes: 2 additions & 1 deletion example-app/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ POSTGRES_USER=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
AWS_BUCKET=
AWS_BUCKET=
GOOGLE_APPLICATION_CREDENTIALS=
7 changes: 5 additions & 2 deletions example-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"build": "tsc",
"start": "yarn build && node build/index.js",
"start:dev": "concurrently \"yarn build --watch\" \"nodemon --ext '.js' --watch ../build --watch ./build --ignore 'cypress/**/*.js' node build/src/index.js\"",
"clean": "rm -rf build && mkdir build",
"dev": "yarn clean && concurrently \"wait-on build/src/index.js && nodemon --ext '.js' --watch ../build --watch ./build --ignore 'cypress/**/*.js' node build/src/index.js\" \"yarn build --watch\"",
"cypress:open": "cypress open",
"cypress:run": "cypress run"
},
Expand All @@ -16,12 +17,14 @@
"cypress": "^4.11.0",
"nodemon": "^2.0.4",
"ts-node": "^8.10.2",
"typescript": "^3.9.7"
"typescript": "^3.9.7",
"wait-on": "^5.2.0"
},
"dependencies": {
"@admin-bro/express": "^3.0.0",
"@admin-bro/typeorm": "1.2.0",
"@admin-bro/upload": "v1.0.0-beta.3",
"@google-cloud/storage": "^5.3.0",
"admin-bro": "^3.2.5",
"dotenv": "^8.2.0",
"express": "^4.17.1",
Expand Down
22 changes: 22 additions & 0 deletions example-app/src/admin/resources/post/post.resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import uploadFeature from '@admin-bro/upload'

import { CreateResourceResult } from '../create-resource-result.type'
import { Post } from '../../../post/post.entity'

const createPostResource = (): CreateResourceResult<typeof Post> => ({
resource: Post,
options: {
listProperties: ['id', 'bucketKey', 'bucket', 'path'],
},
features: [uploadFeature({
provider: {
gcp: {
bucket: 'admin-bro-demo-app-uploads',
expires: 0,
},
},
properties: { file: 'file', key: 'bucketKey', bucket: 'bucket', mimeType: 'mime' },
})],
})

export default createPostResource
3 changes: 3 additions & 0 deletions example-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createConnection } from 'typeorm'
import createPhotoResource from './admin/resources/photo/photo.resource'
import createUserResource from './admin/resources/user/user.resource'
import createCustomResource from './admin/resources/custom/custom.resource'
import createPostResource from './admin/resources/post/post.resource'

const PORT = 3000

Expand All @@ -26,6 +27,7 @@ const run = async () => {
createPhotoResource(),
createUserResource(),
createCustomResource(),
createPostResource(),
],
locale: {
language: 'en',
Expand All @@ -34,6 +36,7 @@ const run = async () => {
Photo: 'photos (Local)',
User: 'users (AWS)',
Custom: 'custom provider',
Post: 'posts (GCP)',
},
},
},
Expand Down
39 changes: 39 additions & 0 deletions example-app/src/post/post.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-disable import/prefer-default-export */
/* eslint-disable import/no-cycle */
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
BaseEntity,
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn,
UpdateDateColumn,
OneToMany,
} from 'typeorm'

@Entity({ name: 'posts' })
export class Post extends BaseEntity {
@PrimaryGeneratedColumn()
public id: number;

@Column({ nullable: true })
public name: string;

@Column({ nullable: true, name: 'key' })
public bucketKey: string;

@Column({ nullable: true })
public bucket: string;

@Column({ nullable: true })
public path: string;

@Column({ nullable: true })
public mime: string;

@CreateDateColumn({ name: 'created_at' })
public createdAt: Date;

@UpdateDateColumn({ name: 'updated_at' })
public updatedAt: Date;
}
Loading

0 comments on commit 8344450

Please sign in to comment.