File tree Expand file tree Collapse file tree 6 files changed +39
-13
lines changed
Expand file tree Collapse file tree 6 files changed +39
-13
lines changed Original file line number Diff line number Diff line change 44 CreateBucketRequest ,
55 PutObjectOutput ,
66 GetObjectOutput ,
7- ListObjectsOutput ,
7+ _Object ,
88 S3 ,
99} from "$deps" ;
1010import {
@@ -72,19 +72,19 @@ export class SimpleCloudStorage {
7272 }
7373 }
7474
75- public async listObjects ( ) : Promise < ListObjectsOutput | undefined > {
75+ public async listObjects ( ) {
7676 return this . handleListObjects ( ) ;
7777 }
7878
79- private async handleListObjects ( ) {
79+ private async handleListObjects ( ) : Promise < Array < _Object > | undefined > {
8080 const s3 = this . makeNewBucket ( ) ;
8181
8282 try {
83- const listObjects = await s3 . listObjects ( {
83+ const listObjects = await s3 . listObjectsV2 ( {
8484 Bucket : this . bucketName ,
8585 } ) ;
8686
87- return listObjects ;
87+ return listObjects . Contents ;
8888 } catch ( er ) {
8989 log . error ( er . message ) ;
9090 }
Original file line number Diff line number Diff line change @@ -52,6 +52,16 @@ class Files implements IFileController {
5252 log . error ( er . message ) ;
5353 }
5454 }
55+
56+ public async listAllObjectsBuckets ( ctx : RouterContext < string > ) {
57+ try {
58+ ctx . response . status = Status . OK ;
59+ return ctx . response . body = await FileService . listAllObjectsFromBucket ( )
60+ } catch ( er ) {
61+ ctx . response . status = Status . BadRequest ;
62+ log . error ( er . message ) ;
63+ }
64+ }
5565}
5666
5767export default new Files ( ) ;
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ class FileRepository extends File {
4646 return this . mysql . buildQuery (
4747 `
4848 SELECT
49+ id,
4950 name,
5051 status
5152 FROM ${ this . table }
@@ -54,17 +55,17 @@ class FileRepository extends File {
5455 ) ;
5556 }
5657
57- public updatedAfterListenAll ( ) {
58- return this . updateStatusAfterListenAll ( ) ;
58+ public updatedAfterListenAll ( id : string ) {
59+ return this . updateStatusAfterListenAll ( id ) ;
5960 }
6061
61- private updateStatusAfterListenAll ( ) {
62+ private updateStatusAfterListenAll ( id : string ) {
6263 return this . mysql . buildQuery (
6364 `
6465 UPDATE ${ this . table }
6566 SET status = ?
66- WHERE status = ?;
67- ` , [ FilenameEnum . LAUNCHED , FilenameEnum . PENDING ]
67+ WHERE id = ?;
68+ ` , [ FilenameEnum . LAUNCHED , id ]
6869 ) ;
6970 }
7071}
Original file line number Diff line number Diff line change @@ -6,5 +6,6 @@ const file = new Router();
66file . post ( "uploadFile/" , FileController . uploadCsv ) ;
77file . get ( "listAllFiles/" , FileController . listAllFiles ) ;
88file . get ( "listenAllFiles/" , FileController . listenFiles )
9+ file . get ( "listAllObjectsBuckets/" , FileController . listAllObjectsBuckets )
910
1011export { file } ;
Original file line number Diff line number Diff line change 1- import { FormDataFile } from "$deps" ;
1+ import { FormDataFile , _Object } from "$deps" ;
22import { S3 } from "$components" ;
33import {
44 FilenameEnum ,
@@ -69,15 +69,28 @@ export class FileService implements IFileService {
6969 ) ;
7070
7171 for ( const pending of pendings ) {
72- if ( pending . status === 0 ) {
72+ if ( pending . status === FilenameEnum . PENDING ) {
7373 this . personService . listenAndCreatePerson ( pending . name ) ;
74- await this . fileRepository . updatedAfterListenAll ( ) ;
74+ await this . fileRepository . updatedAfterListenAll ( pending . id )
7575 continue ;
7676 } ;
7777 }
7878
7979 return files ;
8080 }
81+
82+ public async listAllObjectsFromBucket ( ) {
83+ const objects = await this . s3 . listObjects ( ) as Array < _Object > ;
84+
85+ const objectsFiltered = objects . map ( object => {
86+ return {
87+ name : object . Key ,
88+ size : object . Size ,
89+ }
90+ } ) ;
91+
92+ return objectsFiltered ;
93+ }
8194}
8295
8396export default new FileService ( )
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ export {
2626 type CreateBucketRequest ,
2727 type PutObjectOutput ,
2828 type ListObjectsOutput ,
29+ type _Object ,
2930} from "https://deno.land/x/[email protected] /services/s3/structs.ts" ; 3031
3132export {
You can’t perform that action at this time.
0 commit comments