-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat google storage * feat google storage * add google storage writablestream * add google storage writablestream * add google storage writablestream * add metadata to google storage * add metadata to google storage * add metadata to google storage * add tags to google storage * fix * fix * fix * fix
- Loading branch information
Showing
10 changed files
with
326 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { Storage } = require('@google-cloud/storage'); | ||
const { Writable } = require('stream'); | ||
|
||
class GoogleStorageUploadStream extends Writable { | ||
|
||
constructor(logger, opts) { | ||
super(opts); | ||
this.logger = logger; | ||
this.metadata = opts.metadata; | ||
|
||
const storage = new Storage(opts.bucketCredential); | ||
this.gcsFile = storage.bucket(opts.bucketName).file(opts.Key); | ||
this.writeStream = this.gcsFile.createWriteStream(); | ||
|
||
this.writeStream.on('error', (err) => this.logger.error(err)); | ||
this.writeStream.on('finish', () => { | ||
this.logger.info('google storage Upload completed.'); | ||
this._addMetadata(); | ||
}); | ||
} | ||
|
||
_write(chunk, encoding, callback) { | ||
this.writeStream.write(chunk, encoding, callback); | ||
} | ||
|
||
_final(callback) { | ||
this.writeStream.end(); | ||
this.writeStream.once('finish', callback); | ||
} | ||
|
||
async _addMetadata() { | ||
try { | ||
await this.gcsFile.setMetadata({metadata: this.metadata}); | ||
this.logger.info('Google storage Upload and metadata setting completed.'); | ||
} catch (err) { | ||
this.logger.error(err, 'Google storage An error occurred while setting metadata'); | ||
} | ||
} | ||
} | ||
|
||
module.exports = GoogleStorageUploadStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,6 @@ | ||
|
||
const path = require('node:path'); | ||
async function record(logger, socket, url) { | ||
const p = path.basename(url); | ||
const idx = p.lastIndexOf('/'); | ||
const vendor = p.substring(idx + 1); | ||
switch (vendor) { | ||
case 'aws_s3': | ||
return require('./s3')(logger, socket); | ||
default: | ||
logger.info(`unknown bucket vendor: ${vendor}`); | ||
socket.send(`unknown bucket vendor: ${vendor}`); | ||
socket.close(); | ||
} | ||
async function record(logger, socket) { | ||
return require('./upload')(logger, socket); | ||
} | ||
|
||
module.exports = record; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const GoogleStorageUploadStream = require('./google-storage'); | ||
const S3MultipartUploadStream = require('./s3-multipart-upload-stream'); | ||
|
||
const getUploader = (Key, metadata, bucket_credential, logger) => { | ||
const uploaderOpts = { | ||
bucketName: bucket_credential.name, | ||
Key, | ||
metadata | ||
}; | ||
switch (bucket_credential.vendor) { | ||
case 'aws_s3': | ||
uploaderOpts.bucketCredential = { | ||
credentials: { | ||
accessKeyId: bucket_credential.access_key_id, | ||
secretAccessKey: bucket_credential.secret_access_key, | ||
}, | ||
region: bucket_credential.region || 'us-east-1' | ||
}; | ||
return new S3MultipartUploadStream(logger, uploaderOpts); | ||
case 'google': | ||
const serviceKey = JSON.parse(bucket_credential.service_key); | ||
uploaderOpts.bucketCredential = { | ||
projectId: serviceKey.project_id, | ||
credentials: { | ||
client_email: serviceKey.client_email, | ||
private_key: serviceKey.private_key | ||
} | ||
}; | ||
return new GoogleStorageUploadStream(logger, uploaderOpts); | ||
|
||
default: | ||
logger.error(`unknown bucket vendor: ${bucket_credential.vendor}`); | ||
break; | ||
} | ||
return null; | ||
}; | ||
|
||
module.exports = { | ||
getUploader | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello From Jambonz. This file was created because Record all call bucket credential test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.