Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timeout arg for file actions #49

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/actions/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ exports.uploadFile = function(b2, args) {

var options = {
url: uploadUrl,
timeout: args.timeout || null,
method: 'POST',
headers: {
Authorization: uploadAuthToken,
Expand All @@ -34,6 +35,7 @@ exports.uploadFile = function(b2, args) {
exports.startLargeFile = function(b2, args) {
var options = {
url: getStartLargeFileUrl(b2),
timeout: args.timeout || null,
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
Expand All @@ -48,6 +50,7 @@ exports.startLargeFile = function(b2, args) {
exports.getUploadPartUrl = function(b2, args) {
var options = {
url: getGetUploadPartUrl(b2),
timeout: args.timeout || null,
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
Expand All @@ -60,6 +63,7 @@ exports.getUploadPartUrl = function(b2, args) {
exports.uploadPart = function(b2, args) {
var options = {
url: args.uploadUrl,
timeout: args.timeout || null,
method: 'POST',
headers: {
Authorization: args.uploadAuthToken,
Expand All @@ -75,6 +79,7 @@ exports.uploadPart = function(b2, args) {
exports.finishLargeFile = function(b2, args) {
var options = {
url: getFinishLargeFileUrl(b2),
timeout: args.timeout || null,
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
Expand All @@ -88,6 +93,7 @@ exports.finishLargeFile = function(b2, args) {
exports.cancelLargeFile = function(b2, args) {
var options = {
url: getCancelLargeFileUrl(b2),
timeout: args.timeout || null,
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
Expand All @@ -107,6 +113,7 @@ exports.listFileNames = function(b2, args) {

var options = {
url: getListFilesUrl(b2),
timeout: args.timeout || null,
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
Expand All @@ -128,6 +135,7 @@ exports.listFileVersions = function(b2, args) {

var options = {
url: getListFileVersionsUrl(b2),
timeout: args.timeout || null,
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
Expand All @@ -145,6 +153,7 @@ exports.hideFile = function(b2, args) {

var options = {
url: getHideFileUrl(b2),
timeout: args.timeout || null,
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
Expand Down Expand Up @@ -175,6 +184,7 @@ exports.getDownloadAuthorization = function (b2, args) {

var options = {
url: getDownloadAuthorizationUrl(b2),
timeout: args.timeout || null,
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
Expand All @@ -194,6 +204,7 @@ exports.downloadFileByName = function(b2, args) {

var options = {
url: getDownloadFileByNameUrl(b2, bucketName, fileName),
timeout: args.timeout || null,
headers: utils.getAuthHeaderObjectWithToken(b2),
responseType: args.responseType || null,
encoding: null,
Expand All @@ -208,6 +219,7 @@ exports.downloadFileByName = function(b2, args) {
exports.downloadFileById = function(b2, args) {
var options = {
url: getDownloadFileByIdUrl(b2, args.fileId),
timeout: args.timeout || null,
headers: utils.getAuthHeaderObjectWithToken(b2),
responseType: args.responseType || null,
encoding: null,
Expand All @@ -225,6 +237,7 @@ exports.deleteFileVersion = function(b2, args) {

var options = {
url: getDeleteFileVersionUrl(b2),
timeout: args.timeout || null,
method: 'POST',
headers: utils.getAuthHeaderObjectWithToken(b2),
data: {
Expand Down
9 changes: 9 additions & 0 deletions test/unit/lib/actions/fileTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ describe('actions/file', function() {
it('should set correct options and resolve with good response', function() {
expect(requestOptions).to.eql({
url: 'https://uploadUrl',
timeout: null,
method: 'POST',
headers:
{ Authorization: 'uploadauthtoken',
Expand Down Expand Up @@ -111,6 +112,7 @@ describe('actions/file', function() {
it('should properly add x-bz-info headers', function() {
expect(requestOptions).to.eql({
url: 'https://uploadUrl',
timeout: null,
method: 'POST',
headers:
{
Expand Down Expand Up @@ -250,6 +252,7 @@ describe('actions/file', function() {
it('should set correct options and resolve with good response', function() {
expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_list_file_names',
timeout: null,
method: 'POST',
headers:
{
Expand Down Expand Up @@ -309,6 +312,7 @@ describe('actions/file', function() {
it('should set correct options and resolve with good response', function() {
expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_list_file_versions',
timeout: null,
method: 'POST',
headers:
{
Expand Down Expand Up @@ -365,6 +369,7 @@ describe('actions/file', function() {
it('should set correct options and resolve with good response (filename to be encoded)', function() {
expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_hide_file',
timeout: null,
method: 'POST',
headers:
{
Expand Down Expand Up @@ -467,6 +472,7 @@ describe('actions/file', function() {
it('should set correct options and resolve with good response', function() {
expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_get_download_authorization',
timeout: null,
method: 'POST',
headers:
{
Expand Down Expand Up @@ -543,6 +549,7 @@ describe('actions/file', function() {
it('should set correct options and resolve with good response (filename to be encoded)', function() {
expect(requestOptions).to.eql({
url: 'https://download/file/unicornBox/unicorns-and_rainbows!%40%23%24%25%5E%26.png',
timeout: null,
encoding: null,
headers: {
Authorization: 'unicorns and rainbows'
Expand Down Expand Up @@ -606,6 +613,7 @@ describe('actions/file', function() {
it('should set correct options and resolve with good response', function() {
expect(requestOptions).to.eql({
url: 'https://download/b2api/v1/b2_download_file_by_id?fileId=abcd1234',
timeout: null,
headers: {
Authorization: 'unicorns and rainbows'
},
Expand Down Expand Up @@ -666,6 +674,7 @@ describe('actions/file', function() {
it('should set correct options and resolve with good response (filename to be encoded)', function() {
expect(requestOptions).to.eql({
url: 'https://foo/b2api/v1/b2_delete_file_version',
timeout: null,
method: 'POST',
headers: {
Authorization: 'unicorns and rainbows'
Expand Down