@@ -90,17 +90,17 @@ async function sync() {
9090
9191 //const existingEntries = await Entries.find({ key: { $in: Object.keys(minioWriter.entries) } }); //TODO now this line is useless
9292
93- // let entries = Object.entries(minioWriter.entries).map(([key, value]) => ({ [key]: value }));
94- let entries = [ ]
93+ let entries = Object . entries ( minioWriter . entries ) . map ( ( [ key , value ] ) => ( { [ key ] : value } ) ) ;
94+ let entriesInDB = [ ]
9595 for ( let key in minioWriter . entries )
9696 for ( let value in minioWriter . entries [ key ] )
97- entries . push ( {
97+ entriesInDB . push ( {
9898 key,
9999 value,
100100 visibility : minioWriter . entries [ key ] [ value ]
101101 } )
102102 try {
103- if ( entries . length > 0 ) await Entries . insertMany ( entries ) ;
103+ if ( entriesInDB . length > 0 ) await Entries . insertMany ( entriesInDB ) ;
104104 } catch ( error ) {
105105 if ( ! error ?. errorResponse ?. message ?. includes ( "Document can't have" ) ) {
106106 log ( error ) ;
@@ -344,12 +344,26 @@ function objectFilter(obj, prefix, bucket, visibility) {
344344
345345module . exports = {
346346
347- async getKeys ( ) {
348- return await Key . find ( )
347+ async getKeys ( prefix , bucketName , visibility ) {
348+ if ( visibility == "private" )
349+ visibility = prefix . split ( "/" ) [ 0 ]
350+ else if ( visibility == "shared" )
351+ visibility = bucketName . toUpperCase ( ) + " SHARED Data"
352+ else
353+ visibility = "public-data"
354+ console . debug ( visibility )
355+ return await Key . find ( { visibility } , { "key" : 1 , "value" : 1 , "_id" : 0 , "visibility" :0 } )
349356 } ,
350357
351- async getValues ( ) {
352- return await Value . find ( )
358+ async getValues ( prefix , bucketName , visibility ) {
359+ if ( visibility == "private" )
360+ visibility = prefix . split ( "/" ) [ 0 ]
361+ else if ( visibility == "shared" )
362+ visibility = bucketName . toUpperCase ( ) + " SHARED Data"
363+ else
364+ visibility = "public-data"
365+ console . debug ( visibility )
366+ return await Value . find ( { visibility } , { "key" : 1 , "value" : 1 , "_id" : 0 , "visibility" :0 } )
353367 } ,
354368
355369 async getEntries ( prefix , bucketName , visibility ) {
@@ -361,7 +375,7 @@ module.exports = {
361375 else
362376 visibility = "public-data"
363377 console . debug ( visibility )
364- return await Entries . find ( { visibility } )
378+ return await Entries . find ( { visibility } , { "key" : 1 , "value" : 1 , "_id" : 0 , "visibility" : 0 } )
365379 } ,
366380
367381
0 commit comments