files.com 1.1.18 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +0 -3
- package/_VERSION +1 -1
- package/docs/Errors.md +1 -0
- package/lib/Api.js +1 -1
- package/lib/Errors.js +957 -933
- package/lib/Files.js +1 -1
- package/lib/models/ActionNotificationExport.js +25 -25
- package/lib/models/ActionNotificationExportResult.js +10 -10
- package/lib/models/ActionWebhookFailure.js +5 -9
- package/lib/models/ApiKey.js +62 -70
- package/lib/models/App.js +5 -5
- package/lib/models/As2IncomingMessage.js +7 -7
- package/lib/models/As2OutgoingMessage.js +7 -7
- package/lib/models/As2Partner.js +54 -58
- package/lib/models/As2Station.js +51 -55
- package/lib/models/Automation.js +102 -110
- package/lib/models/AutomationRun.js +13 -13
- package/lib/models/BandwidthSnapshot.js +5 -5
- package/lib/models/Behavior.js +77 -85
- package/lib/models/Bundle.js +102 -110
- package/lib/models/BundleDownload.js +9 -9
- package/lib/models/BundleNotification.js +37 -41
- package/lib/models/BundleRecipient.js +22 -22
- package/lib/models/BundleRegistration.js +7 -7
- package/lib/models/Clickwrap.js +52 -56
- package/lib/models/DnsRecord.js +5 -5
- package/lib/models/EmailIncomingMessage.js +5 -5
- package/lib/models/ExternalEvent.js +18 -18
- package/lib/models/File.js +89 -93
- package/lib/models/FileComment.js +41 -45
- package/lib/models/FileCommentReaction.js +15 -19
- package/lib/models/FileMigration.js +5 -5
- package/lib/models/Folder.js +24 -24
- package/lib/models/FormFieldSet.js +44 -48
- package/lib/models/GpgKey.js +53 -57
- package/lib/models/Group.js +51 -55
- package/lib/models/GroupUser.js +53 -57
- package/lib/models/History.js +72 -72
- package/lib/models/HistoryExport.js +51 -51
- package/lib/models/HistoryExportResult.js +10 -10
- package/lib/models/InboxRecipient.js +22 -22
- package/lib/models/InboxRegistration.js +7 -7
- package/lib/models/InboxUpload.js +9 -9
- package/lib/models/Invoice.js +12 -12
- package/lib/models/IpAddress.js +17 -17
- package/lib/models/Lock.js +27 -31
- package/lib/models/Message.js +60 -64
- package/lib/models/MessageComment.js +46 -50
- package/lib/models/MessageCommentReaction.js +27 -31
- package/lib/models/MessageReaction.js +27 -31
- package/lib/models/Notification.js +66 -70
- package/lib/models/Payment.js +12 -12
- package/lib/models/Permission.js +28 -32
- package/lib/models/Priority.js +9 -9
- package/lib/models/Project.js +39 -43
- package/lib/models/PublicKey.js +46 -50
- package/lib/models/RemoteBandwidthSnapshot.js +5 -5
- package/lib/models/RemoteServer.js +306 -310
- package/lib/models/Request.js +33 -37
- package/lib/models/Session.js +11 -15
- package/lib/models/SettingsChange.js +5 -5
- package/lib/models/SftpHostKey.js +40 -44
- package/lib/models/ShareGroup.js +50 -54
- package/lib/models/Site.js +138 -138
- package/lib/models/Snapshot.js +44 -48
- package/lib/models/SsoStrategy.js +15 -19
- package/lib/models/Style.js +17 -21
- package/lib/models/UsageDailySnapshot.js +5 -5
- package/lib/models/UsageSnapshot.js +5 -5
- package/lib/models/User.js +156 -172
- package/lib/models/UserCipherUse.js +7 -7
- package/lib/models/UserRequest.js +26 -30
- package/lib/models/WebhookTest.js +15 -15
- package/package.json +6 -2
- package/src/Api.js +2 -1
- package/src/Errors.js +189 -177
- package/src/Files.js +1 -1
- package/src/models/AccountLineItem.js +5 -2
- package/src/models/Action.js +5 -2
- package/src/models/ActionNotificationExport.js +36 -35
- package/src/models/ActionNotificationExportResult.js +15 -13
- package/src/models/ActionWebhookFailure.js +9 -8
- package/src/models/ApiKey.js +69 -72
- package/src/models/App.js +10 -8
- package/src/models/As2IncomingMessage.js +12 -10
- package/src/models/As2OutgoingMessage.js +12 -10
- package/src/models/As2Partner.js +61 -60
- package/src/models/As2Station.js +58 -57
- package/src/models/Auto.js +5 -2
- package/src/models/Automation.js +121 -110
- package/src/models/AutomationRun.js +18 -17
- package/src/models/BandwidthSnapshot.js +10 -8
- package/src/models/Behavior.js +85 -86
- package/src/models/Bundle.js +121 -110
- package/src/models/BundleDownload.js +14 -12
- package/src/models/BundleNotification.js +40 -43
- package/src/models/BundleRecipient.js +33 -32
- package/src/models/BundleRegistration.js +12 -10
- package/src/models/Clickwrap.js +60 -58
- package/src/models/DnsRecord.js +10 -8
- package/src/models/EmailIncomingMessage.js +10 -8
- package/src/models/Errors.js +5 -2
- package/src/models/ExternalEvent.js +29 -29
- package/src/models/File.js +116 -108
- package/src/models/FileAction.js +5 -2
- package/src/models/FileComment.js +45 -46
- package/src/models/FileCommentReaction.js +26 -26
- package/src/models/FileMigration.js +10 -8
- package/src/models/FileUploadPart.js +5 -2
- package/src/models/Folder.js +32 -29
- package/src/models/FormField.js +5 -2
- package/src/models/FormFieldSet.js +49 -50
- package/src/models/GpgKey.js +60 -59
- package/src/models/Group.js +58 -57
- package/src/models/GroupUser.js +60 -58
- package/src/models/History.js +77 -74
- package/src/models/HistoryExport.js +62 -61
- package/src/models/HistoryExportResult.js +15 -13
- package/src/models/Image.js +5 -2
- package/src/models/InboxRecipient.js +33 -32
- package/src/models/InboxRegistration.js +12 -10
- package/src/models/InboxUpload.js +14 -12
- package/src/models/Invoice.js +17 -14
- package/src/models/InvoiceLineItem.js +5 -2
- package/src/models/IpAddress.js +22 -20
- package/src/models/Lock.js +36 -36
- package/src/models/Message.js +66 -66
- package/src/models/MessageComment.js +50 -52
- package/src/models/MessageCommentReaction.js +38 -40
- package/src/models/MessageReaction.js +38 -40
- package/src/models/Notification.js +74 -72
- package/src/models/Payment.js +17 -14
- package/src/models/PaymentLineItem.js +5 -2
- package/src/models/Permission.js +39 -40
- package/src/models/Preview.js +5 -2
- package/src/models/Priority.js +14 -12
- package/src/models/Project.js +43 -45
- package/src/models/PublicIpAddress.js +5 -2
- package/src/models/PublicKey.js +50 -52
- package/src/models/RemoteBandwidthSnapshot.js +10 -8
- package/src/models/RemoteServer.js +380 -312
- package/src/models/RemoteServerConfigurationFile.js +5 -2
- package/src/models/Request.js +44 -46
- package/src/models/Session.js +22 -22
- package/src/models/SettingsChange.js +10 -8
- package/src/models/SftpHostKey.js +45 -46
- package/src/models/ShareGroup.js +56 -56
- package/src/models/ShareGroupMember.js +5 -2
- package/src/models/Site.js +143 -142
- package/src/models/Snapshot.js +50 -50
- package/src/models/SsoStrategy.js +20 -21
- package/src/models/Status.js +5 -2
- package/src/models/Style.js +22 -23
- package/src/models/UsageDailySnapshot.js +10 -8
- package/src/models/UsageSnapshot.js +10 -8
- package/src/models/User.js +185 -168
- package/src/models/UserCipherUse.js +12 -10
- package/src/models/UserRequest.js +37 -39
- package/src/models/WebhookTest.js +26 -24
- package/test/Api.test.js +163 -0
- package/test/{package.json → integration/package.json} +1 -1
- package/test/{src → integration/src}/index.js +1 -1
- package/test.sh +2 -1
- /package/test/{.babelrc → integration/.babelrc} +0 -0
- /package/test/{index.js → integration/index.js} +0 -0
package/src/models/File.js
CHANGED
|
@@ -4,7 +4,9 @@ import { Buffer } from 'safe-buffer'
|
|
|
4
4
|
/* eslint-disable no-unused-vars */
|
|
5
5
|
import Api from '../Api'
|
|
6
6
|
import * as errors from '../Errors'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
isBrowser, getType, isArray, isInt, isObject, isString,
|
|
9
|
+
} from '../utils'
|
|
8
10
|
/* eslint-enable no-unused-vars */
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -12,6 +14,7 @@ import { isBrowser, getType, isArray, isInt, isObject, isString } from '../utils
|
|
|
12
14
|
*/
|
|
13
15
|
class File {
|
|
14
16
|
attributes = {}
|
|
17
|
+
|
|
15
18
|
options = {}
|
|
16
19
|
|
|
17
20
|
constructor(attributes = {}, options = {}) {
|
|
@@ -27,6 +30,7 @@ class File {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
isLoaded = () => !!this.attributes.path
|
|
33
|
+
|
|
30
34
|
static _openUpload = async (path, paramsRaw, options) => {
|
|
31
35
|
const params = { ...paramsRaw, action: 'put' }
|
|
32
36
|
const response = await Api.sendRequest(`/files/${encodeURIComponent(path)}`, 'POST', params, options)
|
|
@@ -105,25 +109,25 @@ class File {
|
|
|
105
109
|
if (chunkBuffer !== null || !streamEnded) {
|
|
106
110
|
return
|
|
107
111
|
}
|
|
108
|
-
|
|
112
|
+
|
|
109
113
|
try {
|
|
110
114
|
if (chunks.length > 0) {
|
|
111
115
|
const buffer = Buffer.concat(chunks)
|
|
112
116
|
const nextFileUploadPart = await File._continueUpload(destinationPath, ++part, firstFileUploadPart, options)
|
|
113
|
-
|
|
117
|
+
|
|
114
118
|
const uploadUri = determinePartUploadUri(nextFileUploadPart)
|
|
115
|
-
|
|
119
|
+
|
|
116
120
|
// instantiate an httpsAgent dynamically if needed
|
|
117
121
|
const agent = options.getAgentForUrl?.(uploadUri) || options?.agent
|
|
118
|
-
|
|
122
|
+
|
|
119
123
|
concurrentUploads.push(Api.sendFilePart(uploadUri, 'PUT', buffer, { agent }))
|
|
120
124
|
}
|
|
121
|
-
|
|
125
|
+
|
|
122
126
|
await Promise.all(concurrentUploads)
|
|
123
|
-
|
|
127
|
+
|
|
124
128
|
const response = await File._completeUpload(firstFileUploadPart, options)
|
|
125
129
|
const createdFile = new File(response.data, options)
|
|
126
|
-
|
|
130
|
+
|
|
127
131
|
resolve(createdFile)
|
|
128
132
|
} catch (error) {
|
|
129
133
|
reject(error)
|
|
@@ -212,7 +216,7 @@ class File {
|
|
|
212
216
|
// note that this event may occur while there is still data being processed above
|
|
213
217
|
readableStream.on('end', () => {
|
|
214
218
|
streamEnded = true
|
|
215
|
-
|
|
219
|
+
|
|
216
220
|
handleStreamEnd()
|
|
217
221
|
})
|
|
218
222
|
})
|
|
@@ -490,7 +494,6 @@ class File {
|
|
|
490
494
|
this.attributes.with_rename = value
|
|
491
495
|
}
|
|
492
496
|
|
|
493
|
-
|
|
494
497
|
// Download file
|
|
495
498
|
//
|
|
496
499
|
// Parameters:
|
|
@@ -508,27 +511,28 @@ class File {
|
|
|
508
511
|
}
|
|
509
512
|
|
|
510
513
|
params.path = this.attributes.path
|
|
511
|
-
if (params
|
|
512
|
-
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params
|
|
514
|
+
if (params.path && !isString(params.path)) {
|
|
515
|
+
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params.path)}`)
|
|
513
516
|
}
|
|
514
|
-
|
|
515
|
-
|
|
517
|
+
|
|
518
|
+
if (params.action && !isString(params.action)) {
|
|
519
|
+
throw new errors.InvalidParameterError(`Bad parameter: action must be of type String, received ${getType(params.action)}`)
|
|
516
520
|
}
|
|
517
|
-
|
|
518
|
-
|
|
521
|
+
|
|
522
|
+
if (params.preview_size && !isString(params.preview_size)) {
|
|
523
|
+
throw new errors.InvalidParameterError(`Bad parameter: preview_size must be of type String, received ${getType(params.preview_size)}`)
|
|
519
524
|
}
|
|
520
525
|
|
|
521
|
-
if (!params
|
|
526
|
+
if (!params.path) {
|
|
522
527
|
if (this.attributes.path) {
|
|
523
|
-
params
|
|
528
|
+
params.path = this.path
|
|
524
529
|
} else {
|
|
525
530
|
throw new errors.MissingParameterError('Parameter missing: path')
|
|
526
531
|
}
|
|
527
532
|
}
|
|
528
533
|
|
|
529
|
-
const response = await Api.sendRequest(`/files/${encodeURIComponent(params
|
|
534
|
+
const response = await Api.sendRequest(`/files/${encodeURIComponent(params.path)}`, 'GET', params, this.options)
|
|
530
535
|
|
|
531
|
-
|
|
532
536
|
return new File(response?.data, this.options)
|
|
533
537
|
}
|
|
534
538
|
|
|
@@ -545,27 +549,28 @@ class File {
|
|
|
545
549
|
}
|
|
546
550
|
|
|
547
551
|
params.path = this.attributes.path
|
|
548
|
-
if (params
|
|
549
|
-
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params
|
|
552
|
+
if (params.path && !isString(params.path)) {
|
|
553
|
+
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params.path)}`)
|
|
550
554
|
}
|
|
551
|
-
|
|
552
|
-
|
|
555
|
+
|
|
556
|
+
if (params.provided_mtime && !isString(params.provided_mtime)) {
|
|
557
|
+
throw new errors.InvalidParameterError(`Bad parameter: provided_mtime must be of type String, received ${getType(params.provided_mtime)}`)
|
|
553
558
|
}
|
|
554
|
-
|
|
555
|
-
|
|
559
|
+
|
|
560
|
+
if (params.priority_color && !isString(params.priority_color)) {
|
|
561
|
+
throw new errors.InvalidParameterError(`Bad parameter: priority_color must be of type String, received ${getType(params.priority_color)}`)
|
|
556
562
|
}
|
|
557
563
|
|
|
558
|
-
if (!params
|
|
564
|
+
if (!params.path) {
|
|
559
565
|
if (this.attributes.path) {
|
|
560
|
-
params
|
|
566
|
+
params.path = this.path
|
|
561
567
|
} else {
|
|
562
568
|
throw new errors.MissingParameterError('Parameter missing: path')
|
|
563
569
|
}
|
|
564
570
|
}
|
|
565
571
|
|
|
566
|
-
const response = await Api.sendRequest(`/files/${encodeURIComponent(params
|
|
572
|
+
const response = await Api.sendRequest(`/files/${encodeURIComponent(params.path)}`, 'PATCH', params, this.options)
|
|
567
573
|
|
|
568
|
-
|
|
569
574
|
return new File(response?.data, this.options)
|
|
570
575
|
}
|
|
571
576
|
|
|
@@ -581,21 +586,19 @@ class File {
|
|
|
581
586
|
}
|
|
582
587
|
|
|
583
588
|
params.path = this.attributes.path
|
|
584
|
-
if (params
|
|
585
|
-
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params
|
|
589
|
+
if (params.path && !isString(params.path)) {
|
|
590
|
+
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params.path)}`)
|
|
586
591
|
}
|
|
587
592
|
|
|
588
|
-
if (!params
|
|
593
|
+
if (!params.path) {
|
|
589
594
|
if (this.attributes.path) {
|
|
590
|
-
params
|
|
595
|
+
params.path = this.path
|
|
591
596
|
} else {
|
|
592
597
|
throw new errors.MissingParameterError('Parameter missing: path')
|
|
593
598
|
}
|
|
594
599
|
}
|
|
595
600
|
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
return
|
|
601
|
+
await Api.sendRequest(`/files/${encodeURIComponent(params.path)}`, 'DELETE', params, this.options)
|
|
599
602
|
}
|
|
600
603
|
|
|
601
604
|
destroy = (params = {}) =>
|
|
@@ -616,32 +619,33 @@ class File {
|
|
|
616
619
|
}
|
|
617
620
|
|
|
618
621
|
params.path = this.attributes.path
|
|
619
|
-
if (params
|
|
620
|
-
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params
|
|
622
|
+
if (params.path && !isString(params.path)) {
|
|
623
|
+
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params.path)}`)
|
|
621
624
|
}
|
|
622
|
-
|
|
623
|
-
|
|
625
|
+
|
|
626
|
+
if (params.destination && !isString(params.destination)) {
|
|
627
|
+
throw new errors.InvalidParameterError(`Bad parameter: destination must be of type String, received ${getType(params.destination)}`)
|
|
624
628
|
}
|
|
625
629
|
|
|
626
|
-
if (!params
|
|
630
|
+
if (!params.path) {
|
|
627
631
|
if (this.attributes.path) {
|
|
628
|
-
params
|
|
632
|
+
params.path = this.path
|
|
629
633
|
} else {
|
|
630
634
|
throw new errors.MissingParameterError('Parameter missing: path')
|
|
631
635
|
}
|
|
632
636
|
}
|
|
633
637
|
|
|
634
|
-
if (!params
|
|
638
|
+
if (!params.destination) {
|
|
635
639
|
if (this.attributes.destination) {
|
|
636
|
-
params
|
|
640
|
+
params.destination = this.destination
|
|
637
641
|
} else {
|
|
638
642
|
throw new errors.MissingParameterError('Parameter missing: destination')
|
|
639
643
|
}
|
|
640
644
|
}
|
|
641
645
|
|
|
642
|
-
const response = await Api.sendRequest(`/file_actions/copy/${encodeURIComponent(params
|
|
646
|
+
const response = await Api.sendRequest(`/file_actions/copy/${encodeURIComponent(params.path)}`, 'POST', params, this.options)
|
|
643
647
|
|
|
644
|
-
const FileAction = require(
|
|
648
|
+
const FileAction = require('./FileAction.js').default
|
|
645
649
|
return new FileAction(response?.data, this.options)
|
|
646
650
|
}
|
|
647
651
|
|
|
@@ -659,32 +663,33 @@ class File {
|
|
|
659
663
|
}
|
|
660
664
|
|
|
661
665
|
params.path = this.attributes.path
|
|
662
|
-
if (params
|
|
663
|
-
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params
|
|
666
|
+
if (params.path && !isString(params.path)) {
|
|
667
|
+
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params.path)}`)
|
|
664
668
|
}
|
|
665
|
-
|
|
666
|
-
|
|
669
|
+
|
|
670
|
+
if (params.destination && !isString(params.destination)) {
|
|
671
|
+
throw new errors.InvalidParameterError(`Bad parameter: destination must be of type String, received ${getType(params.destination)}`)
|
|
667
672
|
}
|
|
668
673
|
|
|
669
|
-
if (!params
|
|
674
|
+
if (!params.path) {
|
|
670
675
|
if (this.attributes.path) {
|
|
671
|
-
params
|
|
676
|
+
params.path = this.path
|
|
672
677
|
} else {
|
|
673
678
|
throw new errors.MissingParameterError('Parameter missing: path')
|
|
674
679
|
}
|
|
675
680
|
}
|
|
676
681
|
|
|
677
|
-
if (!params
|
|
682
|
+
if (!params.destination) {
|
|
678
683
|
if (this.attributes.destination) {
|
|
679
|
-
params
|
|
684
|
+
params.destination = this.destination
|
|
680
685
|
} else {
|
|
681
686
|
throw new errors.MissingParameterError('Parameter missing: destination')
|
|
682
687
|
}
|
|
683
688
|
}
|
|
684
689
|
|
|
685
|
-
const response = await Api.sendRequest(`/file_actions/move/${encodeURIComponent(params
|
|
690
|
+
const response = await Api.sendRequest(`/file_actions/move/${encodeURIComponent(params.path)}`, 'POST', params, this.options)
|
|
686
691
|
|
|
687
|
-
const FileAction = require(
|
|
692
|
+
const FileAction = require('./FileAction.js').default
|
|
688
693
|
return new FileAction(response?.data, this.options)
|
|
689
694
|
}
|
|
690
695
|
|
|
@@ -708,43 +713,48 @@ class File {
|
|
|
708
713
|
}
|
|
709
714
|
|
|
710
715
|
params.path = this.attributes.path
|
|
711
|
-
if (params
|
|
712
|
-
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params
|
|
716
|
+
if (params.path && !isString(params.path)) {
|
|
717
|
+
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params.path)}`)
|
|
713
718
|
}
|
|
714
|
-
|
|
715
|
-
|
|
719
|
+
|
|
720
|
+
if (params.part && !isInt(params.part)) {
|
|
721
|
+
throw new errors.InvalidParameterError(`Bad parameter: part must be of type Int, received ${getType(params.part)}`)
|
|
716
722
|
}
|
|
717
|
-
|
|
718
|
-
|
|
723
|
+
|
|
724
|
+
if (params.parts && !isInt(params.parts)) {
|
|
725
|
+
throw new errors.InvalidParameterError(`Bad parameter: parts must be of type Int, received ${getType(params.parts)}`)
|
|
719
726
|
}
|
|
720
|
-
|
|
721
|
-
|
|
727
|
+
|
|
728
|
+
if (params.ref && !isString(params.ref)) {
|
|
729
|
+
throw new errors.InvalidParameterError(`Bad parameter: ref must be of type String, received ${getType(params.ref)}`)
|
|
722
730
|
}
|
|
723
|
-
|
|
724
|
-
|
|
731
|
+
|
|
732
|
+
if (params.restart && !isInt(params.restart)) {
|
|
733
|
+
throw new errors.InvalidParameterError(`Bad parameter: restart must be of type Int, received ${getType(params.restart)}`)
|
|
725
734
|
}
|
|
726
|
-
|
|
727
|
-
|
|
735
|
+
|
|
736
|
+
if (params.size && !isInt(params.size)) {
|
|
737
|
+
throw new errors.InvalidParameterError(`Bad parameter: size must be of type Int, received ${getType(params.size)}`)
|
|
728
738
|
}
|
|
729
739
|
|
|
730
|
-
if (!params
|
|
740
|
+
if (!params.path) {
|
|
731
741
|
if (this.attributes.path) {
|
|
732
|
-
params
|
|
742
|
+
params.path = this.path
|
|
733
743
|
} else {
|
|
734
744
|
throw new errors.MissingParameterError('Parameter missing: path')
|
|
735
745
|
}
|
|
736
746
|
}
|
|
737
747
|
|
|
738
|
-
const response = await Api.sendRequest(`/file_actions/begin_upload/${encodeURIComponent(params
|
|
748
|
+
const response = await Api.sendRequest(`/file_actions/begin_upload/${encodeURIComponent(params.path)}`, 'POST', params, this.options)
|
|
739
749
|
|
|
740
|
-
const FileUploadPart = require(
|
|
750
|
+
const FileUploadPart = require('./FileUploadPart.js').default
|
|
741
751
|
return response?.data?.map(obj => new FileUploadPart(obj, this.options)) || []
|
|
742
752
|
}
|
|
743
753
|
|
|
744
754
|
save = async () => {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
755
|
+
const newObject = await File.create(this.attributes.path, this.attributes, this.options)
|
|
756
|
+
this.attributes = { ...newObject.attributes }
|
|
757
|
+
return true
|
|
748
758
|
}
|
|
749
759
|
|
|
750
760
|
// Parameters:
|
|
@@ -767,55 +777,54 @@ class File {
|
|
|
767
777
|
throw new errors.InvalidParameterError(`Bad parameter: params must be of type object, received ${getType(params)}`)
|
|
768
778
|
}
|
|
769
779
|
|
|
770
|
-
params
|
|
780
|
+
params.path = path
|
|
771
781
|
|
|
772
|
-
if (!params
|
|
782
|
+
if (!params.path) {
|
|
773
783
|
throw new errors.MissingParameterError('Parameter missing: path')
|
|
774
784
|
}
|
|
775
785
|
|
|
776
|
-
if (params
|
|
777
|
-
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params
|
|
786
|
+
if (params.path && !isString(params.path)) {
|
|
787
|
+
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params.path)}`)
|
|
778
788
|
}
|
|
779
789
|
|
|
780
|
-
if (params
|
|
781
|
-
throw new errors.InvalidParameterError(`Bad parameter: action must be of type String, received ${getType(params
|
|
790
|
+
if (params.action && !isString(params.action)) {
|
|
791
|
+
throw new errors.InvalidParameterError(`Bad parameter: action must be of type String, received ${getType(params.action)}`)
|
|
782
792
|
}
|
|
783
793
|
|
|
784
|
-
if (params
|
|
785
|
-
throw new errors.InvalidParameterError(`Bad parameter: length must be of type Int, received ${getType(params
|
|
794
|
+
if (params.length && !isInt(params.length)) {
|
|
795
|
+
throw new errors.InvalidParameterError(`Bad parameter: length must be of type Int, received ${getType(params.length)}`)
|
|
786
796
|
}
|
|
787
797
|
|
|
788
|
-
if (params
|
|
789
|
-
throw new errors.InvalidParameterError(`Bad parameter: part must be of type Int, received ${getType(params
|
|
798
|
+
if (params.part && !isInt(params.part)) {
|
|
799
|
+
throw new errors.InvalidParameterError(`Bad parameter: part must be of type Int, received ${getType(params.part)}`)
|
|
790
800
|
}
|
|
791
801
|
|
|
792
|
-
if (params
|
|
793
|
-
throw new errors.InvalidParameterError(`Bad parameter: parts must be of type Int, received ${getType(params
|
|
802
|
+
if (params.parts && !isInt(params.parts)) {
|
|
803
|
+
throw new errors.InvalidParameterError(`Bad parameter: parts must be of type Int, received ${getType(params.parts)}`)
|
|
794
804
|
}
|
|
795
805
|
|
|
796
|
-
if (params
|
|
797
|
-
throw new errors.InvalidParameterError(`Bad parameter: provided_mtime must be of type String, received ${getType(params
|
|
806
|
+
if (params.provided_mtime && !isString(params.provided_mtime)) {
|
|
807
|
+
throw new errors.InvalidParameterError(`Bad parameter: provided_mtime must be of type String, received ${getType(params.provided_mtime)}`)
|
|
798
808
|
}
|
|
799
809
|
|
|
800
|
-
if (params
|
|
801
|
-
throw new errors.InvalidParameterError(`Bad parameter: ref must be of type String, received ${getType(params
|
|
810
|
+
if (params.ref && !isString(params.ref)) {
|
|
811
|
+
throw new errors.InvalidParameterError(`Bad parameter: ref must be of type String, received ${getType(params.ref)}`)
|
|
802
812
|
}
|
|
803
813
|
|
|
804
|
-
if (params
|
|
805
|
-
throw new errors.InvalidParameterError(`Bad parameter: restart must be of type Int, received ${getType(params
|
|
814
|
+
if (params.restart && !isInt(params.restart)) {
|
|
815
|
+
throw new errors.InvalidParameterError(`Bad parameter: restart must be of type Int, received ${getType(params.restart)}`)
|
|
806
816
|
}
|
|
807
817
|
|
|
808
|
-
if (params
|
|
809
|
-
throw new errors.InvalidParameterError(`Bad parameter: size must be of type Int, received ${getType(params
|
|
818
|
+
if (params.size && !isInt(params.size)) {
|
|
819
|
+
throw new errors.InvalidParameterError(`Bad parameter: size must be of type Int, received ${getType(params.size)}`)
|
|
810
820
|
}
|
|
811
821
|
|
|
812
|
-
if (params
|
|
813
|
-
throw new errors.InvalidParameterError(`Bad parameter: structure must be of type String, received ${getType(params
|
|
822
|
+
if (params.structure && !isString(params.structure)) {
|
|
823
|
+
throw new errors.InvalidParameterError(`Bad parameter: structure must be of type String, received ${getType(params.structure)}`)
|
|
814
824
|
}
|
|
815
825
|
|
|
816
|
-
const response = await Api.sendRequest(`/files/${encodeURIComponent(params
|
|
826
|
+
const response = await Api.sendRequest(`/files/${encodeURIComponent(params.path)}`, 'POST', params, options)
|
|
817
827
|
|
|
818
|
-
|
|
819
828
|
return new File(response?.data, options)
|
|
820
829
|
}
|
|
821
830
|
|
|
@@ -829,23 +838,22 @@ class File {
|
|
|
829
838
|
throw new errors.InvalidParameterError(`Bad parameter: params must be of type object, received ${getType(params)}`)
|
|
830
839
|
}
|
|
831
840
|
|
|
832
|
-
params
|
|
841
|
+
params.path = path
|
|
833
842
|
|
|
834
|
-
if (!params
|
|
843
|
+
if (!params.path) {
|
|
835
844
|
throw new errors.MissingParameterError('Parameter missing: path')
|
|
836
845
|
}
|
|
837
846
|
|
|
838
|
-
if (params
|
|
839
|
-
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params
|
|
847
|
+
if (params.path && !isString(params.path)) {
|
|
848
|
+
throw new errors.InvalidParameterError(`Bad parameter: path must be of type String, received ${getType(params.path)}`)
|
|
840
849
|
}
|
|
841
850
|
|
|
842
|
-
if (params
|
|
843
|
-
throw new errors.InvalidParameterError(`Bad parameter: preview_size must be of type String, received ${getType(params
|
|
851
|
+
if (params.preview_size && !isString(params.preview_size)) {
|
|
852
|
+
throw new errors.InvalidParameterError(`Bad parameter: preview_size must be of type String, received ${getType(params.preview_size)}`)
|
|
844
853
|
}
|
|
845
854
|
|
|
846
|
-
const response = await Api.sendRequest(`/file_actions/metadata/${encodeURIComponent(params
|
|
855
|
+
const response = await Api.sendRequest(`/file_actions/metadata/${encodeURIComponent(params.path)}`, 'GET', params, options)
|
|
847
856
|
|
|
848
|
-
|
|
849
857
|
return new File(response?.data, options)
|
|
850
858
|
}
|
|
851
859
|
|
package/src/models/FileAction.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-unused-vars */
|
|
2
2
|
import Api from '../Api'
|
|
3
3
|
import * as errors from '../Errors'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getType, isArray, isInt, isObject, isString,
|
|
6
|
+
} from '../utils'
|
|
5
7
|
/* eslint-enable no-unused-vars */
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -9,6 +11,7 @@ import { getType, isArray, isInt, isObject, isString } from '../utils'
|
|
|
9
11
|
*/
|
|
10
12
|
class FileAction {
|
|
11
13
|
attributes = {}
|
|
14
|
+
|
|
12
15
|
options = {}
|
|
13
16
|
|
|
14
17
|
constructor(attributes = {}, options = {}) {
|
|
@@ -24,12 +27,12 @@ class FileAction {
|
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
isLoaded = () => !!this.attributes.path
|
|
30
|
+
|
|
27
31
|
// string # Status of file operation.
|
|
28
32
|
getStatus = () => this.attributes.status
|
|
29
33
|
|
|
30
34
|
// int64 # If status is pending, this is the id of the FileMigration to check for status updates.
|
|
31
35
|
getFileMigrationId = () => this.attributes.file_migration_id
|
|
32
|
-
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
export default FileAction
|