@@ -60,22 +60,22 @@ export function deleteObjectsFromS3(keyList, callback) {
60
60
}
61
61
62
62
export function deleteObjectFromS3 ( req , res ) {
63
- const { object_key , user_id } = req . params ;
64
- let objectKey ;
65
- if ( user_id ) {
66
- objectKey = `${ user_id } /${ object_key } `
63
+ const { objectKey , userId } = req . params ;
64
+ let fullObjectKey ;
65
+ if ( userId ) {
66
+ fullObjectKey = `${ userId } /${ objectKey } ` ;
67
67
} else {
68
- objectKey = object_key ;
68
+ fullObjectKey = objectKey ;
69
69
}
70
- deleteObjectsFromS3 ( [ objectKey ] , ( ) => {
70
+ deleteObjectsFromS3 ( [ fullObjectKey ] , ( ) => {
71
71
res . json ( { success : true } ) ;
72
72
} ) ;
73
73
}
74
74
75
75
export function signS3 ( req , res ) {
76
76
const limit = process . env . UPLOAD_LIMIT || 250000000 ;
77
77
if ( req . user . totalSize > limit ) {
78
- res . status ( 403 ) . send ( { message : 'user has uploaded the maximum size of assets.' } ) ;
78
+ res . status ( 403 ) . send ( { message : 'user has uploaded the maximum size of assets.' } ) ;
79
79
return ;
80
80
}
81
81
const fileExtension = getExtension ( req . body . name ) ;
@@ -95,7 +95,7 @@ export function signS3(req, res) {
95
95
policy : p . policy ,
96
96
signature : p . signature
97
97
} ;
98
- return res . json ( result ) ;
98
+ res . json ( result ) ;
99
99
}
100
100
101
101
export function copyObjectInS3 ( req , res ) {
@@ -135,43 +135,41 @@ export function listObjectsInS3ForUser(userId) {
135
135
. on ( 'end' , ( ) => {
136
136
resolve ( ) ;
137
137
} ) ;
138
- } ) . then ( ( ) => {
139
- return getProjectsForUserId ( userId ) ;
140
- } ) . then ( ( projects ) => {
141
- const projectAssets = [ ] ;
142
- let totalSize = 0 ;
143
- assets . forEach ( ( asset ) => {
144
- const name = asset . key . split ( '/' ) . pop ( ) ;
145
- const foundAsset = {
146
- key : asset . key ,
147
- name,
148
- size : asset . size ,
149
- url : `${ process . env . S3_BUCKET_URL_BASE } ${ asset . key } `
150
- } ;
151
- totalSize += asset . size ;
152
- projects . some ( ( project ) => {
153
- let found = false ;
154
- project . files . some ( ( file ) => {
155
- if ( ! file . url ) return false ;
156
- if ( file . url . includes ( asset . key ) ) {
157
- found = true ;
158
- foundAsset . name = file . name ;
159
- foundAsset . sketchName = project . name ;
160
- foundAsset . sketchId = project . id ;
161
- foundAsset . url = file . url ;
162
- return true ;
163
- }
164
- return false ;
165
- } ) ;
166
- return found ;
138
+ } ) . then ( ( ) => getProjectsForUserId ( userId ) ) . then ( ( projects ) => {
139
+ const projectAssets = [ ] ;
140
+ let totalSize = 0 ;
141
+ assets . forEach ( ( asset ) => {
142
+ const name = asset . key . split ( '/' ) . pop ( ) ;
143
+ const foundAsset = {
144
+ key : asset . key ,
145
+ name,
146
+ size : asset . size ,
147
+ url : `${ process . env . S3_BUCKET_URL_BASE } ${ asset . key } `
148
+ } ;
149
+ totalSize += asset . size ;
150
+ projects . some ( ( project ) => {
151
+ let found = false ;
152
+ project . files . some ( ( file ) => {
153
+ if ( ! file . url ) return false ;
154
+ if ( file . url . includes ( asset . key ) ) {
155
+ found = true ;
156
+ foundAsset . name = file . name ;
157
+ foundAsset . sketchName = project . name ;
158
+ foundAsset . sketchId = project . id ;
159
+ foundAsset . url = file . url ;
160
+ return true ;
161
+ }
162
+ return false ;
167
163
} ) ;
168
- projectAssets . push ( foundAsset ) ;
164
+ return found ;
169
165
} ) ;
170
- return Promise . resolve ( { assets : projectAssets , totalSize} ) ;
171
- } ) . catch ( ( err ) => {
172
- console . log ( 'got an error' ) ;
173
- console . log ( err ) ;
166
+ projectAssets . push ( foundAsset ) ;
174
167
} ) ;
168
+ return Promise . resolve ( { assets : projectAssets , totalSize } ) ;
169
+ } ) . catch ( ( err ) => {
170
+ console . log ( 'got an error' ) ;
171
+ console . log ( err ) ;
172
+ } ) ;
175
173
}
176
174
177
175
export function listObjectsInS3ForUserRequestHandler ( req , res ) {
0 commit comments