Skip to content
Open
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
36 changes: 36 additions & 0 deletions lib/mutable-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/helpers/test-runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions types/cjs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ declare namespace megajs {
setAttributes (attributes: JSON, cb?: noop): Promise<void>
delete (permanent?: boolean, cb?: (error: err, data?: any) => void): Promise<void>
moveTo (target: File | string, cb?: (error: err, data?: any) => void): Promise<void>
copyTo (target: File | string, cb?: (error: err, data?: any) => void): Promise<void>
upload (opts: uploadOpts | string, source?: BufferString, cb?: uploadCb): Writable
mkdir (opts: mkdirOpts | string, cb?: (error: err, file: MutableFile) => void): Promise<MutableFile>
navigate (query: string | string[]): MutableFile | undefined
Expand Down
1 change: 1 addition & 0 deletions types/es.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ declare class MutableFile extends File {
setAttributes (attributes: JSON, cb?: noop): Promise<void>
delete (permanent?: boolean, cb?: (error: err, data?: any) => void): Promise<void>
moveTo (target: File | string, cb?: (error: err, data?: any) => void): Promise<void>
copyTo (target: File | string, cb?: (error: err, data?: any) => void): Promise<void>
upload (opts: uploadOpts | string, source?: BufferString, cb?: uploadCb): Writable
mkdir (opts: mkdirOpts | string, cb?: (error: err, file: MutableFile) => void): Promise<MutableFile>
navigate (query: string | string[]): MutableFile | undefined
Expand Down
Loading