diff --git a/docs/files.md b/docs/files.md index 6676bed4..f8174945 100644 --- a/docs/files.md +++ b/docs/files.md @@ -766,6 +766,12 @@ target folder. client.files.copy('12345', '0', {name: 'Renamed file.png'}, callback); ``` +You can specify specific file version to copy by passing optional `version` parameter. + +```js +client.files.copy('12345', '0', {version: '1'}, callback); +``` + ## Delete a File Calling the diff --git a/src/managers/files.ts b/src/managers/files.ts index f23a8278..00f9ef3c 100644 --- a/src/managers/files.ts +++ b/src/managers/files.ts @@ -12,9 +12,9 @@ import httpStatusCodes from 'http-status'; import { Readable, Writable } from 'stream'; import urlTemplate from 'url-template'; import BoxClient from '../box-client'; +import * as schemas from "../schemas"; import errors from '../util/errors'; import urlPath from '../util/url-path'; -import * as schemas from "../schemas"; const ChunkedUploader = require('../chunked-uploader'); @@ -512,6 +512,7 @@ class Files { * @param {string} newParentID - The Box ID for the new parent folder. '0' to copy to All Files. * @param {Object} [options] - Optional parameters for the copy operation, can be left null in most cases * @param {string} [options.name] - A new name to use if there is an identically-named item in the new parent folder + * @param {string} [options.version] - An optional ID of the specific file version to copy * @param {Function} [callback] - passed the new file info if call was successful * @returns {Promise} A promise resolving to the new file object */ @@ -521,6 +522,7 @@ class Files { options?: | { name?: string; + version?: string; } | Function, callback?: Function diff --git a/tests/lib/managers/files-test.js b/tests/lib/managers/files-test.js index 6eff4c8e..26588ae6 100644 --- a/tests/lib/managers/files-test.js +++ b/tests/lib/managers/files-test.js @@ -783,13 +783,15 @@ describe('Files', function() { it('should make POST request to copy the folder with optional parameters when passed', function() { var name = 'rename on copy'; + var version = '1'; expectedParams.body.name = name; + expectedParams.body.version = version; sandbox.stub(boxClientFake, 'wrapWithDefaultHandler').returnsArg(0); sandbox.mock(boxClientFake).expects('post') .withArgs('/files/1234/copy', expectedParams); - files.copy(FILE_ID, NEW_PARENT_ID, {name}); + files.copy(FILE_ID, NEW_PARENT_ID, {name, version}); }); it('should wrap with default handler when called', function() {