From d1a9b006982a244d3ee589d0d10cb9b496995bed Mon Sep 17 00:00:00 2001 From: Manoj <88134633+ravindu01manoj@users.noreply.github.com> Date: Wed, 30 Jul 2025 14:21:39 +0530 Subject: [PATCH 1/5] Update mutable-file.mjs --- lib/mutable-file.mjs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/mutable-file.mjs b/lib/mutable-file.mjs index 1721121..8f46a79 100644 --- a/lib/mutable-file.mjs +++ b/lib/mutable-file.mjs @@ -503,6 +503,41 @@ 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 ? target.nodeId : target, + 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) From 85ce4eb12a9fa6200a2a9152cf81e63b1dc64eac Mon Sep 17 00:00:00 2001 From: Manoj <88134633+ravindu01manoj@users.noreply.github.com> Date: Wed, 30 Jul 2025 14:23:08 +0530 Subject: [PATCH 2/5] Update cjs.d.ts --- types/cjs.d.ts | 1 + 1 file changed, 1 insertion(+) 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 From 978b9711018ee2c1617a46f49f2b8664ad17a210 Mon Sep 17 00:00:00 2001 From: Manoj <88134633+ravindu01manoj@users.noreply.github.com> Date: Wed, 30 Jul 2025 14:23:52 +0530 Subject: [PATCH 3/5] Update es.d.ts --- types/es.d.ts | 1 + 1 file changed, 1 insertion(+) 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 From ff23b65b9c2a95575ea94b28d5291ede7f7c704d Mon Sep 17 00:00:00 2001 From: qgustavor Date: Sat, 30 Aug 2025 09:39:46 -0300 Subject: [PATCH 4/5] Linting fixes Also simplified the `target.nodeId ? target.nodeId : target` ternary because, if target is a File, then it doesn't make sense stringifying it. --- lib/mutable-file.mjs | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/mutable-file.mjs b/lib/mutable-file.mjs index 8f46a79..cf76415 100644 --- a/lib/mutable-file.mjs +++ b/lib/mutable-file.mjs @@ -503,6 +503,7 @@ class MutableFile extends File { return this.api.request(request, cb) } + copyTo (target, cb) { if (typeof target === 'string') { target = this.storage.files[target] @@ -511,31 +512,31 @@ class MutableFile extends File { if (!(target instanceof File)) { throw Error('target must be a folder or a nodeId') } - - const attributes = _MutableFile.packAttributes(this.attributes) + + const attributes = MutableFile.packAttributes(this.attributes) getCipher(this.key).encryptCBC(attributes) - + const request = { - a: "p", - sm: 1, - v: 3, - t: target.nodeId ? target.nodeId : target, - n: [{ - k: e64(this.storage.aes.encryptECB(this.key)), - a: e64(attributes), - h: this.nodeId, - t: 0 - }] - } - + 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, [{ + request.cr = makeCryptoRequest(this.storage, [{ nodeId: this.nodeId, key: this.key - }], shares); + }], shares) } - + return this.api.request(request, cb) } From 11fd289a9ff91110acf5fe5ed608a7727f8ad5d6 Mon Sep 17 00:00:00 2001 From: qgustavor Date: Sat, 30 Aug 2025 09:53:31 -0300 Subject: [PATCH 5/5] Attempt 1 to fix Deno tests Added --no-check because of this: info: The program failed type-checking, but it still might work correctly. hint: Re-run with --no-check to skip type-checking. It should not type check the tests! Why is it doing that? It works on my machine! --- test/helpers/test-runner.mjs | 1 + 1 file changed, 1 insertion(+) 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