File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { Application } from '@feathersjs/express' ;
2
+ import { Params } from '@feathersjs/feathers' ;
3
+ import { S3 } from 'aws-sdk' ;
4
+ import { v4 as uuidv4 } from 'uuid' ;
5
+
6
+
7
+ export default class Files {
8
+ app ! : Application ;
9
+ s3 ! : S3 ;
10
+ bucket ! : string ;
11
+
12
+ async find ( params : Params ) : Promise < string > {
13
+ // Return signed upload URL
14
+ return this . s3 . getSignedUrl ( 'putObject' , {
15
+ Bucket : this . bucket ,
16
+ Key : `${ params . user ?. username } /${ uuidv4 ( ) } .png` ,
17
+ ContentType : 'image/*' ,
18
+ Expires : 300 ,
19
+ } ) ;
20
+ }
21
+
22
+ setup ( app : Application ) : void {
23
+ this . app = app ;
24
+ this . s3 = new S3 ( {
25
+ accessKeyId : process . env . ACCESSKEYID ,
26
+ secretAccessKey : process . env . SECRETACCESSKEY ,
27
+ signatureVersion : 'v4' ,
28
+ region : 'eu-central-1'
29
+ } ) ;
30
+ this . bucket = process . env . BUCKET || '' ;
31
+ }
32
+ }
33
+
Original file line number Diff line number Diff line change
1
+ import { Application } from '@feathersjs/express' ;
2
+ import Files from './files.class' ;
3
+
4
+ export default ( app : Application ) : void => {
5
+ app . use ( '/files' , new Files ( ) ) ;
6
+ } ;
7
+
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import Votes from './votes/votes.service';
6
6
import Auth from './auth/auth.service' ;
7
7
import Feed from './feed/feed.service' ;
8
8
import Feedback from './feedback/feedback.service' ;
9
+ import Files from './files/files.service' ;
9
10
10
11
import tryAuthenticate from '../hooks/tryAuthenticate' ;
11
12
import logging from '../hooks/logging' ;
@@ -19,6 +20,7 @@ export default (app: Application): void => {
19
20
app . configure ( Votes ) ;
20
21
app . configure ( Feed ) ;
21
22
app . configure ( Feedback ) ;
23
+ app . configure ( Files ) ;
22
24
23
25
app . hooks ( {
24
26
before : {
You can’t perform that action at this time.
0 commit comments