Firebase Update
This commit is contained in:
7
express-server/node_modules/gcs-resumable-upload/LICENSE
generated
vendored
Normal file
7
express-server/node_modules/gcs-resumable-upload/LICENSE
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright 2017 Stephen Sawchuk <sawchuk@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
express-server/node_modules/gcs-resumable-upload/build/src/cli.d.ts
generated
vendored
Normal file
1
express-server/node_modules/gcs-resumable-upload/build/src/cli.d.ts
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
export {};
|
18
express-server/node_modules/gcs-resumable-upload/build/src/cli.js
generated
vendored
Normal file
18
express-server/node_modules/gcs-resumable-upload/build/src/cli.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var upload = require('./');
|
||||
var args = process.argv.slice(2);
|
||||
var opts = {
|
||||
bucket: args[0],
|
||||
file: args[1]
|
||||
};
|
||||
process.stdin.pipe(upload(opts))
|
||||
.on('error', console.error)
|
||||
.on('response', function (resp, metadata) {
|
||||
if (!metadata || !metadata.mediaLink)
|
||||
return;
|
||||
console.log('uploaded!');
|
||||
console.log(metadata.mediaLink);
|
||||
});
|
||||
//# sourceMappingURL=cli.js.map
|
1
express-server/node_modules/gcs-resumable-upload/build/src/cli.js.map
generated
vendored
Normal file
1
express-server/node_modules/gcs-resumable-upload/build/src/cli.js.map
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";;;AACA,IAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAC7B,IAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,IAAM,IAAI,GAAG;IACX,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IACf,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;CACd,CAAC;AAGF,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;KAC3B,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;KAC1B,EAAE,CAAC,UAAU,EAAE,UAAC,IAAgB,EAAE,QAA6B;IAC9D,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,SAAS;QAAE,OAAO;IAC7C,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC"}
|
8
express-server/node_modules/gcs-resumable-upload/build/src/index.d.ts
generated
vendored
Normal file
8
express-server/node_modules/gcs-resumable-upload/build/src/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/// <reference types="request" />
|
||||
import * as r from 'request';
|
||||
export declare type RequestBody = any;
|
||||
export declare type RequestResponse = r.Response;
|
||||
export declare type Request = r.Request;
|
||||
export declare type RequestOptions = r.OptionsWithUri;
|
||||
export declare type RequestCallback = (err: Error | null, response?: r.Response, body?: RequestBody) => void;
|
||||
export declare type AuthorizeRequestCallback = (err: Error | null, authorizedReqOpts: RequestOptions) => void;
|
340
express-server/node_modules/gcs-resumable-upload/build/src/index.js
generated
vendored
Normal file
340
express-server/node_modules/gcs-resumable-upload/build/src/index.js
generated
vendored
Normal file
@ -0,0 +1,340 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var ConfigStore = require("configstore");
|
||||
var crypto = require("crypto");
|
||||
var r = require("request");
|
||||
var stream_1 = require("stream");
|
||||
var util = require("util");
|
||||
var streamEvents = require('stream-events');
|
||||
var googleAuth = require('google-auto-auth');
|
||||
var pumpify = require('pumpify');
|
||||
var request = r.defaults({ json: true, pool: { maxSockets: Infinity } });
|
||||
var BASE_URI = 'https://www.googleapis.com/upload/storage/v1/b';
|
||||
var TERMINATED_UPLOAD_STATUS_CODE = 410;
|
||||
var RESUMABLE_INCOMPLETE_STATUS_CODE = 308;
|
||||
var RETRY_LIMIT = 5;
|
||||
var wrapError = function (message, err) {
|
||||
return new Error([message, err.message].join('\n'));
|
||||
};
|
||||
function Upload(cfg) {
|
||||
var _this = this;
|
||||
pumpify.call(this);
|
||||
streamEvents.call(this);
|
||||
cfg = cfg || {};
|
||||
if (!cfg.bucket || !cfg.file) {
|
||||
throw new Error('A bucket and file name are required');
|
||||
}
|
||||
cfg.authConfig = cfg.authConfig || {};
|
||||
cfg.authConfig.scopes =
|
||||
['https://www.googleapis.com/auth/devstorage.full_control'];
|
||||
this.authClient = cfg.authClient || googleAuth(cfg.authConfig);
|
||||
this.bucket = cfg.bucket;
|
||||
this.file = cfg.file;
|
||||
this.generation = cfg.generation;
|
||||
this.kmsKeyName = cfg.kmsKeyName;
|
||||
this.metadata = cfg.metadata || {};
|
||||
this.offset = cfg.offset;
|
||||
this.origin = cfg.origin;
|
||||
this.userProject = cfg.userProject;
|
||||
if (cfg.key) {
|
||||
/**
|
||||
* NOTE: This is `as string` because there appears to be some weird kind
|
||||
* of TypeScript bug as 2.8. Tracking the issue here:
|
||||
* https://github.com/Microsoft/TypeScript/issues/23155
|
||||
*/
|
||||
var base64Key = Buffer.from(cfg.key).toString('base64');
|
||||
this.encryption = {
|
||||
key: base64Key,
|
||||
hash: crypto.createHash('sha256').update(cfg.key).digest('base64')
|
||||
};
|
||||
}
|
||||
this.predefinedAcl = cfg.predefinedAcl;
|
||||
if (cfg.private)
|
||||
this.predefinedAcl = 'private';
|
||||
if (cfg.public)
|
||||
this.predefinedAcl = 'publicRead';
|
||||
this.configStore = new ConfigStore('gcs-resumable-upload');
|
||||
this.uriProvidedManually = !!cfg.uri;
|
||||
this.uri = cfg.uri || this.get('uri');
|
||||
this.numBytesWritten = 0;
|
||||
this.numRetries = 0;
|
||||
var contentLength = cfg.metadata ? Number(cfg.metadata.contentLength) : NaN;
|
||||
this.contentLength = isNaN(contentLength) ? '*' : contentLength;
|
||||
this.once('writing', function () {
|
||||
if (_this.uri) {
|
||||
_this.continueUploading();
|
||||
}
|
||||
else {
|
||||
_this.createURI(function (err) {
|
||||
if (err) {
|
||||
return _this.destroy(err);
|
||||
}
|
||||
_this.startUploading();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
util.inherits(Upload, pumpify);
|
||||
Upload.prototype.createURI = function (callback) {
|
||||
var _this = this;
|
||||
var metadata = this.metadata;
|
||||
var reqOpts = {
|
||||
method: 'POST',
|
||||
uri: [BASE_URI, this.bucket, 'o'].join('/'),
|
||||
qs: { name: this.file, uploadType: 'resumable' },
|
||||
json: metadata,
|
||||
headers: {}
|
||||
};
|
||||
if (metadata.contentLength) {
|
||||
reqOpts.headers['X-Upload-Content-Length'] = metadata.contentLength;
|
||||
}
|
||||
if (metadata.contentType) {
|
||||
reqOpts.headers['X-Upload-Content-Type'] = metadata.contentType;
|
||||
}
|
||||
if (typeof this.generation !== 'undefined') {
|
||||
reqOpts.qs.ifGenerationMatch = this.generation;
|
||||
}
|
||||
if (this.kmsKeyName) {
|
||||
reqOpts.qs.kmsKeyName = this.kmsKeyName;
|
||||
}
|
||||
if (this.predefinedAcl) {
|
||||
reqOpts.qs.predefinedAcl = this.predefinedAcl;
|
||||
}
|
||||
if (this.origin) {
|
||||
reqOpts.headers.Origin = this.origin;
|
||||
}
|
||||
this.makeRequest(reqOpts, function (err, resp) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
var uri = resp.headers.location;
|
||||
_this.uri = uri;
|
||||
_this.set({ uri: uri });
|
||||
_this.offset = 0;
|
||||
callback(null, uri);
|
||||
});
|
||||
};
|
||||
Upload.prototype.continueUploading = function () {
|
||||
if (typeof this.offset === 'number') {
|
||||
return this.startUploading();
|
||||
}
|
||||
this.getAndSetOffset(this.startUploading.bind(this));
|
||||
};
|
||||
Upload.prototype.startUploading = function () {
|
||||
var _this = this;
|
||||
var reqOpts = {
|
||||
method: 'PUT',
|
||||
uri: this.uri,
|
||||
headers: { 'Content-Range': 'bytes ' + this.offset + '-*/' + this.contentLength }
|
||||
};
|
||||
var bufferStream = this.bufferStream = new stream_1.PassThrough();
|
||||
var offsetStream = this.offsetStream =
|
||||
new stream_1.PassThrough({ transform: this.onChunk.bind(this) });
|
||||
var delayStream = new stream_1.PassThrough();
|
||||
this.getRequestStream(reqOpts, function (requestStream) {
|
||||
_this.setPipeline(bufferStream, offsetStream, requestStream, delayStream);
|
||||
// wait for "complete" from request before letting the stream finish
|
||||
delayStream.on('prefinish', function () {
|
||||
_this.cork();
|
||||
});
|
||||
requestStream.on('complete', function (resp) {
|
||||
if (resp.statusCode < 200 || resp.statusCode > 299) {
|
||||
_this.destroy(new Error('Upload failed'));
|
||||
return;
|
||||
}
|
||||
_this.emit('metadata', resp.body);
|
||||
_this.deleteConfig();
|
||||
_this.uncork();
|
||||
});
|
||||
});
|
||||
};
|
||||
Upload.prototype.onChunk = function (chunk, enc, next) {
|
||||
var offset = this.offset;
|
||||
var numBytesWritten = this.numBytesWritten;
|
||||
// check if this is the same content uploaded previously. this caches a slice
|
||||
// of the first chunk, then compares it with the first byte of incoming data
|
||||
if (numBytesWritten === 0) {
|
||||
var cachedFirstChunk = this.get('firstChunk');
|
||||
var firstChunk = chunk.slice(0, 16).valueOf();
|
||||
if (!cachedFirstChunk) {
|
||||
// This is a new upload. Cache the first chunk.
|
||||
this.set({ uri: this.uri, firstChunk: firstChunk });
|
||||
}
|
||||
else {
|
||||
// this continues an upload in progress. check if the bytes are the same
|
||||
cachedFirstChunk = Buffer.from(cachedFirstChunk);
|
||||
var nextChunk = Buffer.from(firstChunk);
|
||||
if (Buffer.compare(cachedFirstChunk, nextChunk) !== 0) {
|
||||
// this data is not the same. start a new upload
|
||||
this.bufferStream.unshift(chunk);
|
||||
this.bufferStream.unpipe(this.offsetStream);
|
||||
this.restart();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
var length = chunk.length;
|
||||
if (typeof chunk === 'string')
|
||||
length = Buffer.byteLength(chunk, enc);
|
||||
if (numBytesWritten < offset)
|
||||
chunk = chunk.slice(offset - numBytesWritten);
|
||||
this.numBytesWritten += length;
|
||||
// only push data from the byte after the one we left off on
|
||||
next(null, this.numBytesWritten > offset ? chunk : undefined);
|
||||
};
|
||||
Upload.prototype.getAndSetOffset = function (callback) {
|
||||
var _this = this;
|
||||
this.makeRequest({
|
||||
method: 'PUT',
|
||||
uri: this.uri,
|
||||
headers: { 'Content-Length': 0, 'Content-Range': 'bytes */*' }
|
||||
}, function (err, resp) {
|
||||
if (err) {
|
||||
// we don't return a 404 to the user if they provided the resumable
|
||||
// URI. if we're just using the configstore file to tell us that this
|
||||
// file exists, and it turns out that it doesn't (the 404), that's
|
||||
// probably stale config data.
|
||||
if (resp && resp.statusCode === 404 && !_this.uriProvidedManually) {
|
||||
return _this.restart();
|
||||
}
|
||||
// this resumable upload is unrecoverable (bad data or service error).
|
||||
// -
|
||||
// https://github.com/stephenplusplus/gcs-resumable-upload/issues/15
|
||||
// -
|
||||
// https://github.com/stephenplusplus/gcs-resumable-upload/pull/16#discussion_r80363774
|
||||
if (resp && resp.statusCode === TERMINATED_UPLOAD_STATUS_CODE) {
|
||||
return _this.restart();
|
||||
}
|
||||
return _this.destroy(err);
|
||||
}
|
||||
if (resp.statusCode === RESUMABLE_INCOMPLETE_STATUS_CODE) {
|
||||
if (resp.headers.range) {
|
||||
var range = resp.headers.range;
|
||||
_this.offset = Number(range.split('-')[1]) + 1;
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
_this.offset = 0;
|
||||
callback();
|
||||
});
|
||||
};
|
||||
Upload.prototype.makeRequest = function (reqOpts, callback) {
|
||||
if (this.encryption) {
|
||||
reqOpts.headers = reqOpts.headers || {};
|
||||
reqOpts.headers['x-goog-encryption-algorithm'] = 'AES256';
|
||||
reqOpts.headers['x-goog-encryption-key'] = this.encryption.key;
|
||||
reqOpts.headers['x-goog-encryption-key-sha256'] = this.encryption.hash;
|
||||
}
|
||||
if (this.userProject) {
|
||||
reqOpts.qs = reqOpts.qs || {};
|
||||
reqOpts.qs.userProject = this.userProject;
|
||||
}
|
||||
this.authClient.authorizeRequest(reqOpts, function (err, authorizedReqOpts) {
|
||||
if (err) {
|
||||
err = wrapError('Could not authenticate request', err);
|
||||
return callback(err, null, null);
|
||||
}
|
||||
request(authorizedReqOpts, function (err, resp, body) {
|
||||
if (err) {
|
||||
return callback(err, resp, body);
|
||||
}
|
||||
if (body && body.error) {
|
||||
return callback(body.error, resp, body);
|
||||
}
|
||||
var nonSuccess = Math.floor(resp.statusCode / 100) !== 2; // 200-299 status code
|
||||
if (nonSuccess &&
|
||||
resp.statusCode !== RESUMABLE_INCOMPLETE_STATUS_CODE) {
|
||||
return callback(new Error(body), resp, body);
|
||||
}
|
||||
callback(null, resp, body);
|
||||
});
|
||||
});
|
||||
};
|
||||
Upload.prototype.getRequestStream = function (reqOpts, callback) {
|
||||
var _this = this;
|
||||
if (this.userProject) {
|
||||
reqOpts.qs = reqOpts.qs || {};
|
||||
reqOpts.qs.userProject = this.userProject;
|
||||
}
|
||||
this.authClient.authorizeRequest(reqOpts, function (err, authorizedReqOpts) {
|
||||
if (err) {
|
||||
return _this.destroy(wrapError('Could not authenticate request', err));
|
||||
}
|
||||
var requestStream = request(authorizedReqOpts);
|
||||
requestStream.on('error', _this.destroy.bind(_this));
|
||||
requestStream.on('response', _this.onResponse.bind(_this));
|
||||
requestStream.on('complete', function (resp) {
|
||||
var body = resp.body;
|
||||
if (body && body.error)
|
||||
_this.destroy(body.error);
|
||||
});
|
||||
// this makes the response body come back in the response (weird?)
|
||||
requestStream.callback = function () { };
|
||||
callback(requestStream);
|
||||
});
|
||||
};
|
||||
Upload.prototype.restart = function () {
|
||||
var _this = this;
|
||||
this.numBytesWritten = 0;
|
||||
this.deleteConfig();
|
||||
this.createURI(function (err) {
|
||||
if (err) {
|
||||
return _this.destroy(err);
|
||||
}
|
||||
_this.startUploading();
|
||||
});
|
||||
};
|
||||
Upload.prototype.get = function (prop) {
|
||||
var store = this.configStore.get([this.bucket, this.file].join('/'));
|
||||
return store && store[prop];
|
||||
};
|
||||
// tslint:disable-next-line no-any
|
||||
Upload.prototype.set = function (props) {
|
||||
this.configStore.set([this.bucket, this.file].join('/'), props);
|
||||
};
|
||||
Upload.prototype.deleteConfig = function () {
|
||||
this.configStore.delete([this.bucket, this.file].join('/'));
|
||||
};
|
||||
/**
|
||||
* @return {bool} is the request good?
|
||||
*/
|
||||
Upload.prototype.onResponse = function (resp) {
|
||||
if (resp.statusCode === 404) {
|
||||
if (this.numRetries < RETRY_LIMIT) {
|
||||
this.numRetries++;
|
||||
this.startUploading();
|
||||
}
|
||||
else {
|
||||
this.destroy(new Error('Retry limit exceeded'));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (resp.statusCode > 499 && resp.statusCode < 600) {
|
||||
if (this.numRetries < RETRY_LIMIT) {
|
||||
var randomMs = Math.round(Math.random() * 1000);
|
||||
var waitTime = Math.pow(2, this.numRetries) * 1000 + randomMs;
|
||||
this.numRetries++;
|
||||
setTimeout(this.continueUploading.bind(this), waitTime);
|
||||
}
|
||||
else {
|
||||
this.destroy(new Error('Retry limit exceeded'));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.emit('response', resp);
|
||||
return true;
|
||||
};
|
||||
function upload(cfg) {
|
||||
// tslint:disable-next-line no-any
|
||||
return new Upload(cfg);
|
||||
}
|
||||
// tslint:disable-next-line no-any
|
||||
upload.createURI =
|
||||
function (cfg, callback) {
|
||||
// tslint:disable-next-line no-any
|
||||
var up = new Upload(cfg);
|
||||
up.createURI(callback);
|
||||
};
|
||||
module.exports = upload;
|
||||
//# sourceMappingURL=index.js.map
|
1
express-server/node_modules/gcs-resumable-upload/build/src/index.js.map
generated
vendored
Normal file
1
express-server/node_modules/gcs-resumable-upload/build/src/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
95
express-server/node_modules/gcs-resumable-upload/package.json
generated
vendored
Normal file
95
express-server/node_modules/gcs-resumable-upload/package.json
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
{
|
||||
"_from": "gcs-resumable-upload@^0.10.2",
|
||||
"_id": "gcs-resumable-upload@0.10.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-fymz7iPc7EFwNnwHEUGCScZgVF8=",
|
||||
"_location": "/gcs-resumable-upload",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "gcs-resumable-upload@^0.10.2",
|
||||
"name": "gcs-resumable-upload",
|
||||
"escapedName": "gcs-resumable-upload",
|
||||
"rawSpec": "^0.10.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.10.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@google-cloud/storage"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/gcs-resumable-upload/-/gcs-resumable-upload-0.10.2.tgz",
|
||||
"_shasum": "7f29b3ee23dcec4170367c0711418249c660545f",
|
||||
"_spec": "gcs-resumable-upload@^0.10.2",
|
||||
"_where": "D:\\Desktop\\Git\\Firebase\\SmartShopperFirebase\\node_modules\\@google-cloud\\storage",
|
||||
"author": {
|
||||
"name": "Stephen Sawchuk",
|
||||
"email": "sawchuk@gmail.com"
|
||||
},
|
||||
"bin": {
|
||||
"gcs-upload": "build/src/cli.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/stephenplusplus/gcs-resumable-upload/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"configstore": "^3.1.2",
|
||||
"google-auto-auth": "^0.10.0",
|
||||
"pumpify": "^1.4.0",
|
||||
"request": "^2.85.0",
|
||||
"stream-events": "^1.0.3"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Upload a file to Google Cloud Storage with built-in resumable behavior",
|
||||
"devDependencies": {
|
||||
"@types/configstore": "^2.1.1",
|
||||
"@types/is-stream": "^1.1.0",
|
||||
"@types/mocha": "^5.0.0",
|
||||
"@types/mockery": "^1.4.29",
|
||||
"@types/nock": "^9.1.3",
|
||||
"@types/node": "^9.6.1",
|
||||
"@types/request": "^2.47.0",
|
||||
"@types/through2": "^2.0.33",
|
||||
"gts": "^0.5.4",
|
||||
"is-stream": "^1.1.0",
|
||||
"mocha": "^5.0.5",
|
||||
"mockery": "^2.1.0",
|
||||
"nock": "^9.2.5",
|
||||
"source-map-support": "^0.5.4",
|
||||
"through2": "^2.0.3",
|
||||
"typescript": "~2.8.0"
|
||||
},
|
||||
"files": [
|
||||
"build/src"
|
||||
],
|
||||
"homepage": "https://github.com/stephenplusplus/gcs-resumable-upload#readme",
|
||||
"keywords": [
|
||||
"google",
|
||||
"gcloud",
|
||||
"storage",
|
||||
"gcs",
|
||||
"upload",
|
||||
"resumable"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "build/src/index.js",
|
||||
"name": "gcs-resumable-upload",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/stephenplusplus/gcs-resumable-upload.git"
|
||||
},
|
||||
"scripts": {
|
||||
"check": "gts check",
|
||||
"clean": "gts clean",
|
||||
"compile": "tsc -p .",
|
||||
"fix": "gts fix",
|
||||
"posttest": "npm run check",
|
||||
"prepare": "npm run compile",
|
||||
"pretest": "npm run compile",
|
||||
"system-tests": "mocha build/test/system-tests -r source-map-support/register --timeout 20000",
|
||||
"test": "mocha build/test -r source-map-support/register"
|
||||
},
|
||||
"types": "build/src/index.d.ts",
|
||||
"version": "0.10.2"
|
||||
}
|
226
express-server/node_modules/gcs-resumable-upload/readme.md
generated
vendored
Normal file
226
express-server/node_modules/gcs-resumable-upload/readme.md
generated
vendored
Normal file
@ -0,0 +1,226 @@
|
||||
# gcs-resumable-upload
|
||||
> Upload a file to Google Cloud Storage with built-in resumable behavior
|
||||
|
||||
```sh
|
||||
$ npm install --save gcs-resumable-upload
|
||||
```
|
||||
```js
|
||||
var upload = require('gcs-resumable-upload');
|
||||
var fs = require('fs');
|
||||
|
||||
fs.createReadStream('titanic.mov')
|
||||
.pipe(upload({ bucket: 'legally-owned-movies', file: 'titanic.mov' }))
|
||||
.on('finish', function () {
|
||||
// Uploaded!
|
||||
});
|
||||
```
|
||||
|
||||
Or from the command line:
|
||||
|
||||
```sh
|
||||
$ npm install -g gcs-resumable-upload
|
||||
$ cat titanic.mov | gcs-upload legally-owned-movies titanic.mov
|
||||
```
|
||||
|
||||
If somewhere during the operation, you lose your connection to the internet or your tough-guy brother slammed your laptop shut when he saw what you were uploading, the next time you try to upload to that file, it will resume automatically from where you left off.
|
||||
|
||||
## How it works
|
||||
|
||||
This module stores a file using [ConfigStore](http://gitnpm.com/configstore) that is written to when you first start an upload. It is aliased by the file name you are uploading to and holds the first 16kb chunk of data* as well as the unique resumable upload URI. ([Resumable uploads are complicated](https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload#resumable))
|
||||
|
||||
If your upload was interrupted, next time you run the code, we ask the API how much data it has already, then simply dump all of the data coming through the pipe that it already has.
|
||||
|
||||
After the upload completes, the entry in the config file is removed. Done!
|
||||
|
||||
\* The first 16kb chunk is stored to validate if you are sending the same data when you resume the upload. If not, a new resumable upload is started with the new data.
|
||||
|
||||
## Authentication
|
||||
|
||||
Oh, right. This module uses [google-auto-auth](http://gitnpm.com/google-auto-auth) and accepts all of the configuration that module does to strike up a connection as `config.authConfig`. See [`authConfig`](https://github.com/stephenplusplus/google-auto-auth#authconfig).
|
||||
|
||||
## API
|
||||
|
||||
### upload = require('gcs-resumable-upload')
|
||||
|
||||
---
|
||||
|
||||
#### upload(config)
|
||||
|
||||
- Returns: [`Duplexify`](http://gitnpm.com/duplexify)
|
||||
|
||||
<a name="config"></a>
|
||||
##### config
|
||||
|
||||
- Type: `object`
|
||||
|
||||
Configuration object.
|
||||
|
||||
###### config.authClient
|
||||
|
||||
- Type: [`GoogleAutoAuth`](http://gitnpm.com/google-auto-auth)
|
||||
- *Optional*
|
||||
|
||||
If you want to re-use an auth client from [google-auto-auth](http://gitnpm.com/google-auto-auth), pass an instance here.
|
||||
|
||||
###### config.authConfig
|
||||
|
||||
- Type: `object`
|
||||
- *Optional*
|
||||
|
||||
See [`authConfig`](https://github.com/stephenplusplus/google-auto-auth#authconfig).
|
||||
|
||||
###### config.bucket
|
||||
|
||||
- Type: `string`
|
||||
- **Required**
|
||||
|
||||
The name of the destination bucket.
|
||||
|
||||
###### config.file
|
||||
|
||||
- Type: `string`
|
||||
- **Required**
|
||||
|
||||
The name of the destination file.
|
||||
|
||||
###### config.generation
|
||||
|
||||
- Type: `number`
|
||||
- *Optional*
|
||||
|
||||
This will cause the upload to fail if the current generation of the remote object does not match the one provided here.
|
||||
|
||||
###### config.key
|
||||
|
||||
- Type: `string|buffer`
|
||||
- *Optional*
|
||||
|
||||
A [customer-supplied encryption key](https://cloud.google.com/storage/docs/encryption#customer-supplied).
|
||||
|
||||
###### config.kmsKeyName
|
||||
|
||||
- Type: `string`
|
||||
- *Optional*
|
||||
|
||||
Resource name of the Cloud KMS key, of the form `projects/my-project/locations/global/keyRings/my-kr/cryptoKeys/my-key`, that will be used to encrypt the object. Overrides the object metadata's `kms_key_name` value, if any.
|
||||
|
||||
###### config.metadata
|
||||
|
||||
- Type: `object`
|
||||
- *Optional*
|
||||
|
||||
Any metadata you wish to set on the object.
|
||||
|
||||
###### *config.metadata.contentLength*
|
||||
|
||||
Set the length of the file being uploaded.
|
||||
|
||||
###### *config.metadata.contentType*
|
||||
|
||||
Set the content type of the incoming data.
|
||||
|
||||
###### config.offset
|
||||
|
||||
- Type: `number`
|
||||
- *Optional*
|
||||
|
||||
The starting byte of the upload stream, for [resuming an interrupted upload](https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload#resume-upload).
|
||||
|
||||
###### config.origin
|
||||
|
||||
- Type: `string`
|
||||
- *Optional*
|
||||
|
||||
Set an Origin header when creating the resumable upload URI.
|
||||
|
||||
###### config.predefinedAcl
|
||||
|
||||
- Type: `string`
|
||||
- *Optional*
|
||||
|
||||
Apply a predefined set of access controls to the created file.
|
||||
|
||||
Acceptable values are:
|
||||
|
||||
- **`authenticatedRead`** - Object owner gets `OWNER` access, and `allAuthenticatedUsers` get `READER` access.
|
||||
- **`bucketOwnerFullControl`** - Object owner gets `OWNER` access, and project team owners get `OWNER` access.
|
||||
- **`bucketOwnerRead`** - Object owner gets `OWNER` access, and project team owners get `READER` access.
|
||||
- **`private`** - Object owner gets `OWNER` access.
|
||||
- **`projectPrivate`** - Object owner gets `OWNER` access, and project team members get access according to their roles.
|
||||
- **`publicRead`** - Object owner gets `OWNER` access, and `allUsers` get `READER` access.
|
||||
|
||||
###### config.private
|
||||
|
||||
- Type: `boolean`
|
||||
- *Optional*
|
||||
|
||||
Make the uploaded file private. (Alias for `config.predefinedAcl = 'private'`)
|
||||
|
||||
###### config.public
|
||||
|
||||
- Type: `boolean`
|
||||
- *Optional*
|
||||
|
||||
Make the uploaded file public. (Alias for `config.predefinedAcl = 'publicRead'`)
|
||||
|
||||
###### config.uri
|
||||
|
||||
- Type: `string`
|
||||
- *Optional*
|
||||
|
||||
If you already have a resumable URI from a previously-created resumable upload, just pass it in here and we'll use that.
|
||||
|
||||
###### config.userProject
|
||||
|
||||
- Type: `string`
|
||||
- *Optional*
|
||||
|
||||
If the bucket being accessed has `requesterPays` functionality enabled, this can be set to control which project is billed for the access of this file.
|
||||
|
||||
--
|
||||
|
||||
#### Events
|
||||
|
||||
##### .on('error', function (err) {})
|
||||
|
||||
###### err
|
||||
|
||||
- Type: `Error`
|
||||
|
||||
Invoked if the authorization failed, the request failed, or the file wasn't successfully uploaded.
|
||||
|
||||
##### .on('response', function (resp, metadata) {})
|
||||
|
||||
###### resp
|
||||
|
||||
- Type: `Object`
|
||||
|
||||
The HTTP response from [`request`](http://gitnpm.com/request).
|
||||
|
||||
###### metadata
|
||||
|
||||
- Type: `Object`
|
||||
|
||||
The file's new metadata.
|
||||
|
||||
##### .on('finish', function () {})
|
||||
|
||||
The file was uploaded successfully.
|
||||
|
||||
---
|
||||
|
||||
#### upload.createURI([config](#config), callback)
|
||||
|
||||
##### callback(err, resumableURI)
|
||||
|
||||
###### callback.err
|
||||
|
||||
- Type: `Error`
|
||||
|
||||
Invoked if the authorization failed or the request to start a resumable session failed.
|
||||
|
||||
###### callback.resumableURI
|
||||
|
||||
- Type: `String`
|
||||
|
||||
The resumable upload session URI.
|
Reference in New Issue
Block a user