diff --git a/lib/mutable-file.mjs b/lib/mutable-file.mjs index 1721121..cf76415 100644 --- a/lib/mutable-file.mjs +++ b/lib/mutable-file.mjs @@ -504,6 +504,42 @@ class MutableFile extends File { return this.api.request(request, cb) } + copyTo (target, cb) { + if (typeof target === 'string') { + target = this.storage.files[target] + } + + if (!(target instanceof File)) { + throw Error('target must be a folder or a nodeId') + } + + const attributes = MutableFile.packAttributes(this.attributes) + getCipher(this.key).encryptCBC(attributes) + + const request = { + a: 'p', + sm: 1, + v: 3, + t: target.nodeId, + n: [{ + k: e64(this.storage.aes.encryptECB(this.key)), + a: e64(attributes), + h: this.nodeId, + t: 0 + }] + } + + const shares = getShares(this.storage.shareKeys, target) + if (shares.length > 0) { + request.cr = makeCryptoRequest(this.storage, [{ + nodeId: this.nodeId, + key: this.key + }], shares) + } + + return this.api.request(request, cb) + } + setAttributes (attributes, originalCb) { const [cb, promise] = createPromise(originalCb) Object.assign(this.attributes, attributes) diff --git a/test/helpers/test-runner.mjs b/test/helpers/test-runner.mjs index a0b1b81..1ab8953 100644 --- a/test/helpers/test-runner.mjs +++ b/test/helpers/test-runner.mjs @@ -162,6 +162,7 @@ if (testedPlatform === 'node') { await new Promise(resolve => { const subprocess = cp.spawn('deno', [ 'test', + '--no-check', '--allow-env=MEGA_MOCK_URL', '--allow-net=' + gateway.slice(7, -1), ...extraArguments diff --git a/types/cjs.d.ts b/types/cjs.d.ts index 76689de..a9040b9 100644 --- a/types/cjs.d.ts +++ b/types/cjs.d.ts @@ -124,6 +124,7 @@ declare namespace megajs { setAttributes (attributes: JSON, cb?: noop): Promise delete (permanent?: boolean, cb?: (error: err, data?: any) => void): Promise moveTo (target: File | string, cb?: (error: err, data?: any) => void): Promise + copyTo (target: File | string, cb?: (error: err, data?: any) => void): Promise upload (opts: uploadOpts | string, source?: BufferString, cb?: uploadCb): Writable mkdir (opts: mkdirOpts | string, cb?: (error: err, file: MutableFile) => void): Promise navigate (query: string | string[]): MutableFile | undefined diff --git a/types/es.d.ts b/types/es.d.ts index acf2372..a0a5ee0 100644 --- a/types/es.d.ts +++ b/types/es.d.ts @@ -120,6 +120,7 @@ declare class MutableFile extends File { setAttributes (attributes: JSON, cb?: noop): Promise delete (permanent?: boolean, cb?: (error: err, data?: any) => void): Promise moveTo (target: File | string, cb?: (error: err, data?: any) => void): Promise + copyTo (target: File | string, cb?: (error: err, data?: any) => void): Promise upload (opts: uploadOpts | string, source?: BufferString, cb?: uploadCb): Writable mkdir (opts: mkdirOpts | string, cb?: (error: err, file: MutableFile) => void): Promise navigate (query: string | string[]): MutableFile | undefined