Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JameelB authored and wtrocki committed Oct 24, 2017
1 parent e1f5822 commit 53f72ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions cloud/filestore/src/impl/GridFsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,27 @@ export class GridFsStorage implements FileStorage {
* @param mongoConnectionURl - MongoDB connection url
*/
constructor(mongoConnectionUrl: string) {
const self = this;
MongoClient.connect(mongoConnectionUrl, function(err, connection) {
if (err) {
getLogger().error('Cannot connect to mongodb server. Gridfs storage will be disabled');
return;
}
this.gridFileSystem = gridfs(connection, mongo);
self.gridFileSystem = gridfs(connection, mongo);
});
}

public writeFile(metadata: FileMetadata, fileLocation: string): Promise<any> {
if (this.gridFileSystem) {
const self = this;
if (!self.gridFileSystem) {
return BlueBird.reject('Not initialized');
}
const options = {
root: metadata.namespace,
filename: metadata.id
};
return new BlueBird(function(resolve, reject) {
const writeStream = this.gridFileSystem.createWriteStream(options);
const writeStream = self.gridFileSystem.createWriteStream(options);
writeStream.on('error', function(err) {
getLogger().error('An error occurred!', err);
reject(err);
Expand All @@ -51,15 +53,16 @@ export class GridFsStorage implements FileStorage {
}

public streamFile(namespace: string, fileName: string): Promise<any> {
if (this.gridFileSystem) {
const self = this;
if (!self.gridFileSystem) {
return BlueBird.reject('Not initialized');
}
const options = {
filename: fileName,
root: namespace
};
return new BlueBird(function(resolve, reject) {
const readstream = this.gridFileSystem.createReadStream(options);
const readstream = self.gridFileSystem.createReadStream(options);
readstream.on('error', function(err) {
getLogger().error('An error occurred when reading file from gridfs!', err);
reject(err);
Expand Down
2 changes: 1 addition & 1 deletion cloud/filestore/src/impl/S3Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class LocalStorage implements FileStorage {
Key: file
}
};
let uploader = this.awsClient.uploadFile(params);
const uploader = this.awsClient.uploadFile(params);
return new BlueBird(function(resolve, reject) {
uploader.on('error', function(err) {
getLogger().error('An error occurred when reading file from s3', err);
Expand Down

0 comments on commit 53f72ea

Please sign in to comment.