@@ -60,22 +60,22 @@ export function deleteObjectsFromS3(keyList, callback) {
6060}
6161
6262export 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 } ` ;
6767 } else {
68- objectKey = object_key ;
68+ fullObjectKey = objectKey ;
6969 }
70- deleteObjectsFromS3 ( [ objectKey ] , ( ) => {
70+ deleteObjectsFromS3 ( [ fullObjectKey ] , ( ) => {
7171 res . json ( { success : true } ) ;
7272 } ) ;
7373}
7474
7575export function signS3 ( req , res ) {
7676 const limit = process . env . UPLOAD_LIMIT || 250000000 ;
7777 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.' } ) ;
7979 return ;
8080 }
8181 const fileExtension = getExtension ( req . body . name ) ;
@@ -95,7 +95,7 @@ export function signS3(req, res) {
9595 policy : p . policy ,
9696 signature : p . signature
9797 } ;
98- return res . json ( result ) ;
98+ res . json ( result ) ;
9999}
100100
101101export function copyObjectInS3 ( req , res ) {
@@ -135,43 +135,41 @@ export function listObjectsInS3ForUser(userId) {
135135 . on ( 'end' , ( ) => {
136136 resolve ( ) ;
137137 } ) ;
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 ;
167163 } ) ;
168- projectAssets . push ( foundAsset ) ;
164+ return found ;
169165 } ) ;
170- return Promise . resolve ( { assets : projectAssets , totalSize} ) ;
171- } ) . catch ( ( err ) => {
172- console . log ( 'got an error' ) ;
173- console . log ( err ) ;
166+ projectAssets . push ( foundAsset ) ;
174167 } ) ;
168+ return Promise . resolve ( { assets : projectAssets , totalSize } ) ;
169+ } ) . catch ( ( err ) => {
170+ console . log ( 'got an error' ) ;
171+ console . log ( err ) ;
172+ } ) ;
175173}
176174
177175export function listObjectsInS3ForUserRequestHandler ( req , res ) {
0 commit comments