Skip to content

Commit

Permalink
Merge eb717ea into b5ca5c2
Browse files Browse the repository at this point in the history
  • Loading branch information
tkrugg committed Aug 23, 2018
2 parents b5ca5c2 + eb717ea commit 2ee0dcf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
21 changes: 21 additions & 0 deletions lib/stores/DataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,27 @@ class DataStore extends EventEmitter {
return resolve({ size: 0, upload_length: 1 });
});
}

/**
* Parses the Base64 encoded metadata received from the client.
*
* @param {String} metadata_string tus' standard upload metadata
* @return {Object} metadata as key-value pair
*/
_parseMetadataString(metadata_string) {
const kv_pair_list = metadata_string.split(',');

return kv_pair_list.reduce((metadata, kv_pair) => {
const [key, base64_value] = kv_pair.split(' ');

metadata[key] = {
encoded: base64_value,
decoded: Buffer.from(base64_value, 'base64').toString('ascii'),
};

return metadata;
}, {});
}
}

module.exports = DataStore;
6 changes: 5 additions & 1 deletion lib/stores/GCSDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class GCSDataStore extends DataStore {

const file = new File(file_id, upload_length, upload_defer_length, upload_metadata);
const gcs_file = this.bucket.file(file.id);
const parsedMetadata = this._parseMetadataString(upload_metadata);
const options = {
contentType: parsedMetadata.type.decoded,
metadata: {
metadata: {
upload_length: file.upload_length,
Expand Down Expand Up @@ -131,10 +133,12 @@ class GCSDataStore extends DataStore {
return new Promise((resolve, reject) => {
const file = this.bucket.file(file_id);

const parsedMetadata = this._parseMetadataString(data.upload_metadata);
const options = {
offset,
metadata: {
metadata: {
contentType: parsedMetadata.type.decoded,
metadata: {
upload_length: data.upload_length,
tus_version: TUS_RESUMABLE,
upload_metadata: data.upload_metadata,
Expand Down
21 changes: 0 additions & 21 deletions lib/stores/S3Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,27 +233,6 @@ class S3Store extends DataStore {
});
}

/**
* Parses the Base64 encoded metadata received from the client.
*
* @param {String} metadata_string tus' standard upload metadata
* @return {Object} metadata as key-value pair
*/
_parseMetadataString(metadata_string) {
const kv_pair_list = metadata_string.split(',');

return kv_pair_list.reduce((metadata, kv_pair) => {
const [key, base64_value] = kv_pair.split(' ');

metadata[key] = {
encoded: base64_value,
decoded: Buffer.from(base64_value, 'base64').toString('ascii'),
};

return metadata;
}, {});
}

/**
* Uploads a part/chunk to S3 from a temporary part file.
*
Expand Down

0 comments on commit 2ee0dcf

Please sign in to comment.