@byted-apaas/server-sdk-node 0.0.2-beta.2 → 0.0.2-beta.5

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.
Files changed (129) hide show
  1. package/LICENSE +7 -0
  2. package/NOTICE +3 -0
  3. package/application/impl/impl.js +2 -1
  4. package/application/impl/impl.js.map +1 -1
  5. package/constants/constants.js +2 -0
  6. package/constants/constants.js.map +1 -1
  7. package/context/context.js +2 -0
  8. package/context/context.js.map +1 -1
  9. package/context/db/db.js +2 -0
  10. package/context/db/db.js.map +1 -1
  11. package/context/db/impl/IObject.js +2 -0
  12. package/context/db/impl/IObject.js.map +1 -1
  13. package/context/db/impl/object.js +2 -0
  14. package/context/db/impl/object.js.map +1 -1
  15. package/context/db/impl/oql/ioql.js +2 -0
  16. package/context/db/impl/oql/ioql.js.map +1 -1
  17. package/context/db/impl/oql/oql.js +2 -0
  18. package/context/db/impl/oql/oql.js.map +1 -1
  19. package/context/db/impl/order.js +2 -0
  20. package/context/db/impl/order.js.map +1 -1
  21. package/context/db/impl/propertiesStore.js +2 -0
  22. package/context/db/impl/propertiesStore.js.map +1 -1
  23. package/context/db/impl/queryBuilder.js +2 -0
  24. package/context/db/impl/queryBuilder.js.map +1 -1
  25. package/context/db/impl/transaction/index.js +2 -0
  26. package/context/db/impl/transaction/index.js.map +1 -1
  27. package/context/db/impl/transaction.js +2 -0
  28. package/context/db/impl/transaction.js.map +1 -1
  29. package/context/globalConfig/globalConfig.js +2 -0
  30. package/context/globalConfig/globalConfig.js.map +1 -1
  31. package/context/metadata/components/common.js +2 -0
  32. package/context/metadata/components/common.js.map +1 -1
  33. package/context/metadata/components/components.js +2 -0
  34. package/context/metadata/components/components.js.map +1 -1
  35. package/context/metadata/components/desktop/recordDetail.js +2 -0
  36. package/context/metadata/components/desktop/recordDetail.js.map +1 -1
  37. package/context/metadata/components/mobile/list.js +2 -0
  38. package/context/metadata/components/mobile/list.js.map +1 -1
  39. package/context/metadata/metadata.js +2 -0
  40. package/context/metadata/metadata.js.map +1 -1
  41. package/context/metadata/objects/fields.js +2 -0
  42. package/context/metadata/objects/fields.js.map +1 -1
  43. package/context/metadata/objects/objects.js +2 -0
  44. package/context/metadata/objects/objects.js.map +1 -1
  45. package/context/metadata/types/common.js +2 -0
  46. package/context/metadata/types/common.js.map +1 -1
  47. package/context/metadata/types/components.js +2 -0
  48. package/context/metadata/types/components.js.map +1 -1
  49. package/context/metadata/types/objects.js +2 -0
  50. package/context/metadata/types/objects.js.map +1 -1
  51. package/context/msg/msg.js +2 -0
  52. package/context/msg/msg.js.map +1 -1
  53. package/context/resources/impl/resources.js +2 -0
  54. package/context/resources/impl/resources.js.map +1 -1
  55. package/kunlun/kunlun.js +2 -0
  56. package/kunlun/kunlun.js.map +1 -1
  57. package/kunlun/operator/IOperator.js +2 -0
  58. package/kunlun/operator/IOperator.js.map +1 -1
  59. package/kunlun/operator/impl/expression.js +2 -0
  60. package/kunlun/operator/impl/expression.js.map +1 -1
  61. package/kunlun/operator/impl/logic.js +2 -0
  62. package/kunlun/operator/impl/logic.js.map +1 -1
  63. package/kunlun/operator/impl/operator.js +2 -0
  64. package/kunlun/operator/impl/operator.js.map +1 -1
  65. package/lib/core.js +2 -0
  66. package/lib/core.js.map +1 -1
  67. package/package.json +3 -14
  68. package/request/innerapi.js +4 -2
  69. package/request/innerapi.js.map +1 -1
  70. package/request/interface.js +2 -0
  71. package/request/interface.js.map +1 -1
  72. package/request/openapi.js +2 -0
  73. package/request/openapi.js.map +1 -1
  74. package/types/types.js +2 -0
  75. package/types/types.js.map +1 -1
  76. package/LICENSE.md +0 -0
  77. package/application/application.ts +0 -40
  78. package/application/function/function.ts +0 -37
  79. package/application/impl/common.ts +0 -50
  80. package/application/impl/impl.ts +0 -48
  81. package/constants/constants.ts +0 -12
  82. package/context/context.ts +0 -127
  83. package/context/db/db.ts +0 -77
  84. package/context/db/impl/IObject.ts +0 -244
  85. package/context/db/impl/db.ts +0 -95
  86. package/context/db/impl/object.ts +0 -628
  87. package/context/db/impl/oql/ioql.ts +0 -6
  88. package/context/db/impl/oql/oql.ts +0 -22
  89. package/context/db/impl/order.ts +0 -16
  90. package/context/db/impl/propertiesStore.ts +0 -28
  91. package/context/db/impl/queryBuilder.ts +0 -103
  92. package/context/db/impl/transaction/index.ts +0 -337
  93. package/context/db/impl/transaction/operation.ts +0 -72
  94. package/context/db/impl/transaction.ts +0 -76
  95. package/context/globalConfig/globalConfig.ts +0 -11
  96. package/context/metadata/components/common.ts +0 -19
  97. package/context/metadata/components/components.ts +0 -19
  98. package/context/metadata/components/desktop/list.ts +0 -457
  99. package/context/metadata/components/desktop/recordDetail.ts +0 -64
  100. package/context/metadata/components/mobile/list.ts +0 -176
  101. package/context/metadata/metadata.ts +0 -175
  102. package/context/metadata/objects/fields.ts +0 -454
  103. package/context/metadata/objects/fields.util.ts +0 -360
  104. package/context/metadata/objects/objects.ts +0 -27
  105. package/context/metadata/types/common.ts +0 -10
  106. package/context/metadata/types/components.ts +0 -105
  107. package/context/metadata/types/objects.ts +0 -251
  108. package/context/msg/msg.ts +0 -49
  109. package/context/resources/IResources.ts +0 -73
  110. package/context/resources/impl/resources.ts +0 -170
  111. package/context/tasks/tasks.ts +0 -159
  112. package/data/index.ts +0 -30
  113. package/hooks/api.ts +0 -341
  114. package/hooks/hooks.ts +0 -100
  115. package/kunlun/kunlun.ts +0 -69
  116. package/kunlun/operator/IOperator.ts +0 -163
  117. package/kunlun/operator/impl/expression.ts +0 -71
  118. package/kunlun/operator/impl/logic.ts +0 -595
  119. package/kunlun/operator/impl/logicV2.ts +0 -254
  120. package/kunlun/operator/impl/operator.ts +0 -255
  121. package/kunlun/operator/impl/operatorV2.ts +0 -249
  122. package/lib/core.ts +0 -4
  123. package/request/common.ts +0 -91
  124. package/request/constants.ts +0 -25
  125. package/request/faasinfra.ts +0 -393
  126. package/request/innerapi.ts +0 -1645
  127. package/request/interface.ts +0 -166
  128. package/request/openapi.ts +0 -1220
  129. package/types/types.ts +0 -105
@@ -1,251 +0,0 @@
1
- import {I18ns} from "./common";
2
-
3
- export interface BaseFieldType {
4
- type: string;
5
- apiName: string;
6
- label: I18ns;
7
- }
8
-
9
- export interface KTextFieldType extends BaseFieldType {
10
- required: boolean; // 默认值:false
11
- unique: boolean; // 默认值:false
12
- caseSensitive: boolean; // unique 为 false 时生效,默认值:true
13
- multiline: boolean; // 默认值:false
14
- maxLength: number; // 默认值:1000
15
- validationRegex: string; // 正则校验的表达式
16
- errorMsg: I18ns;
17
- }
18
-
19
- export interface RichTextType extends BaseFieldType {
20
- required: boolean; // 默认值:false
21
- maxLength: number;
22
- }
23
-
24
- export interface MultilingualType extends BaseFieldType {
25
- required: boolean; // 默认值:false
26
- unique: boolean; // 默认值:false
27
- caseSensitive: boolean; // unique 为 ture 时生效,默认值:true
28
- multiline: boolean; // 默认值:false
29
- maxLength: number; // 默认值:1000
30
- }
31
-
32
- export interface NumberType extends BaseFieldType {
33
- required: boolean; // 默认值:false
34
- unique: boolean; // 默认值:false
35
- displayAsPercentage: boolean; // 默认值:false
36
- decimalPlacesNumber: number;
37
- }
38
-
39
- export interface KDateType extends BaseFieldType {
40
- required: boolean; // 默认值:false
41
- }
42
-
43
- export interface DateTimeType extends BaseFieldType {
44
- required: boolean; // 默认值:false
45
- }
46
-
47
- export type SubOptionType = {
48
- label: I18ns;
49
- apiName: string;
50
- description: I18ns;
51
- color: ("grey" | "blue" | "cyan" | "green" | "yellow" | "orange" | "red" | "magenta" | "purple" | "blueMagenta"); // 按色阶顺序给默认值
52
- active: boolean; // 默认值: true
53
- }
54
-
55
- export interface OptionType extends BaseFieldType {
56
- required: boolean; // 默认值:false
57
- multiple: boolean; // 默认值:false
58
- optionSource: ("custom" | "global"); // 对应选项字段的「选项来源」属性(分为「自定义选项」和「使用全局选项), 默认值:"custom"
59
- globalOptionApiName: string; // 关联全局选项的 apiName(创建字段时,设定 optionSource 为 "custom",则无需传入,且生成的元数据中不包含该属性)
60
- optionList: SubOptionType[];
61
- }
62
-
63
- export interface Email extends BaseFieldType {
64
- required: boolean; // 默认值:false
65
- unique: boolean; // 默认值:false
66
- }
67
-
68
- export interface MobileNumber extends BaseFieldType {
69
- required: boolean; // 默认值:false
70
- unique: boolean; // 默认值:false
71
- }
72
-
73
- export interface Boolean extends BaseFieldType {
74
- descriptionWhenTrue: I18ns;
75
- descriptionWhenFalse: I18ns;
76
- defaultValue: boolean;
77
- }
78
-
79
- export interface AvatarOrLogo extends BaseFieldType {
80
- displayStyle: ("square" | "round"); // 默认值:"square"
81
- }
82
-
83
- export interface SortConditionType {
84
- fieldApiName: string;
85
- sort: ("asc" | "desc") // 默认值:"asc"
86
- }
87
-
88
- type ConditionType = {
89
- left: {
90
- objectApiName: string;
91
- fieldApiName: string;
92
- };
93
- operator: ("eq" | "neq" | "in" | "notIn" | "empty" | "notEmpty" | "lte" | "gte" | "hasAllOf" | "hasNoneOf" | "hasAnyOf");
94
- valueType: ("reference" | "specified");
95
- right: (object | string); // 当 valueType 为 "reference" 时,值类型同 left 属性;若为 "specified",值类型则为固定的字符串值
96
- }
97
-
98
- type CriterionType = {
99
- conditions: ConditionType[]; // filter 条件
100
- logic: string;
101
- }
102
-
103
- export type FilterType = {
104
- label: string; // 对应为查找字段设置过滤条件中的「名称」属性
105
- needTriggerCriterion: boolean; // 默认值:false
106
- triggerCriterion: CriterionType
107
- criterion: CriterionType
108
- errorMsg: I18ns;
109
- }
110
-
111
- export interface Lookup extends BaseFieldType {
112
- required: boolean; // 默认值:false
113
- multiple: boolean; // 默认值:false,对应查找字段的「关联记录数」属性(分为「单条」和「多条」)
114
- objectApiName: string; // 字段 look up 的对象
115
- hierarchy: boolean; // 默认值:false,multiple 为 false 时生效
116
- displayStyle: ("search" | "dropDown" | "tree"); // 默认值:"dropDown",对应查找字段的「关联记录展示方式」属性,仅当 hierarchy 为 true 时才可设置为 "tree"
117
- sortConditions: SortConditionType[];
118
- filter: FilterType[];
119
- }
120
-
121
- export interface FormulaType extends BaseFieldType {
122
- returnType: string; // 对应公式字段的「公式返回值类型」属性
123
- formula: I18ns;
124
- }
125
-
126
- export interface AutoIDType extends BaseFieldType {
127
- generateMethod: ("random" | "incremental"); // 默认值: "random"
128
- digitsNumber: number;
129
- prefix: string;
130
- suffix: string;
131
- }
132
-
133
- export interface ReferenceFieldType extends BaseFieldType {
134
- guideFieldApiName: string;
135
- fieldApiName: string;
136
- }
137
-
138
- export interface FileType extends BaseFieldType {
139
- required: boolean; // 默认值: false
140
- multiple: boolean; // 默认值: false
141
- fileTypes: string[]; // 支持 "jpeg"|"jpg"|"png"|"gif"|"pdf"|"docx"|"doc"|"xlsx"|"xls"|"pptx"|"ppt"|"csv"|"txt"|"json"|"mp4"|"zip"|"rar",同时支持 "*.doc" 的描述方式,当为空数组,或 null、undefined 时,默认支持「全部类型」
142
- }
143
-
144
- export interface BackLookuType extends BaseFieldType {
145
- objectApiName: string;
146
- fieldApiName: string; // 由于下游提供仍是 api ID 版本,因此禁用
147
- }
148
-
149
- export interface CompositeType extends BaseFieldType {
150
- compositeTypeApiName: string; // 关联组合类型的 apiName,「主子对象」需求调整后,将不存在该 key
151
- subFields: BaseFieldType[]; // 组合类型中的子字段的元数据
152
- required: boolean; // 默认值: false
153
- multiple: boolean; // 默认值: false
154
- }
155
-
156
- export interface ExtractSingleRecordType extends BaseFieldType {
157
- compositeTypeApiName: string; // 关联组合类型的 apiName,「主子对象」需求调整后,将调整为「子表单」类型字段的 apiName
158
- subFields: BaseFieldType[]; // 组合类型中的子字段的元数据
159
- filter: FilterType[];
160
- sortConditions: SortConditionType[];
161
- recordPosition: number; // 默认值: 1,对应多值取单值字段的「返回记录」(分为「第一条」、「最后一条」和「第 {{n}} 条」),取值为正整数时为相应位置的记录,取值为 -1 时为「最后一条」记录
162
- }
163
-
164
- export type FieldType = {
165
- "allow_search": boolean,
166
- "api_name": string,
167
- "calculated": boolean,
168
- "description": I18ns,
169
- "domain": number,
170
- "encryption_mode": string,
171
- "field_permission": number,
172
- "formula_id": number,
173
- "id": number,
174
- "indexed": number,
175
- "inherit_settings": object,
176
- "is_encrypted": boolean,
177
- "is_inherit": boolean,
178
- "is_progress_field": boolean,
179
- "label": I18ns,
180
- "namespace": string,
181
- "object_api_name": string,
182
- "object_id": number,
183
- "order": number,
184
- "required": boolean,
185
- "tenant_id": number,
186
- "type": {
187
- "name": string,
188
- "settings": {
189
- "multiline": boolean,
190
- "text_version": number,
191
- "decimal_places": number,
192
- "display_as_percentage": boolean,
193
- "placeholder": object,
194
- "max_length": number,
195
- "regexp_expression": string,
196
- "regexp_err_msg": I18ns,
197
- "is_array": boolean,
198
- "option_type": string,
199
- "related_to_global_option": {
200
- "apiName": string,
201
- "id": number,
202
- "name": string,
203
- },
204
- "options": {
205
- "name": I18ns,
206
- "api_name": string,
207
- "description": I18ns,
208
- "color_id": string,
209
- "active": boolean,
210
- }[],
211
- "description_if_true": I18ns,
212
- "description_if_false": I18ns,
213
- "display_style": string,
214
- "default_value": boolean,
215
- "referenced_object_api_name": string,
216
- "is_hierarchy": boolean,
217
- "return_type": string,
218
- "formulas": I18ns,
219
- "generation_method": string,
220
- "digits": number,
221
- "prefix": string,
222
- "suffix": string,
223
- "target_referenced_object_api_name": string,
224
- "target_reference_field_api_name": string,
225
- "multiple": boolean,
226
- "mime_types": string[],
227
- "related_to_object_api_name": string,
228
- "related_to_field_api_name": string,
229
- "related_to_api_name": string,
230
- "related_to_fields": object[],
231
- "filter": FilterType[],
232
- "sort": {
233
- "field": string,
234
- "type": "string",
235
- "direction": ("asc" | "desc")
236
- }[],
237
- "filter_record": {
238
- "index": number,
239
- "type": string,
240
- },
241
- "is_extract": boolean,
242
- }
243
- },
244
- "unique_type": number,
245
- "updated_at": number,
246
- "updated_by": {
247
- "avatar": object,
248
- "id": number,
249
- "name": string,
250
- },
251
- }
@@ -1,49 +0,0 @@
1
- import * as Request from "../../request/interface";
2
- import * as common from "@byted-apaas/server-common-node"
3
- import Multilingual = common.fieldType.Multilingual
4
-
5
- export type _IconType = "success" | "error" | "progress" | "info"
6
-
7
- export class _NotifyCenter {
8
- /**
9
- * 消息中心推送消息
10
- * @param msg 消息
11
- */
12
- public async create(msg: {
13
- icon: _IconType,
14
- percent: Number,
15
- target_users: number[],
16
- title: Multilingual,
17
- detail: Multilingual,
18
- }): Promise<number> {
19
- return await Request.GetInstance().createMessage(msg);
20
- };
21
- /**
22
- * 消息中心更新消息
23
- * @param msgId 消息 ID
24
- * @param msg 消息
25
- */
26
- public async update(msgId: number, msg: {
27
- icon?: _IconType,
28
- percent?: Number,
29
- target_users?: number[],
30
- title?: Multilingual,
31
- detail?: Multilingual,
32
- }): Promise<void> {
33
- return await Request.GetInstance().updateMessage(msgId, msg);
34
- };
35
- }
36
-
37
- /**
38
- * 消息类
39
- */
40
- export class Message {
41
- /**
42
- * 消息中心
43
- */
44
- notifyCenter: _NotifyCenter;
45
-
46
- constructor() {
47
- this.notifyCenter = new _NotifyCenter();
48
- }
49
- }
@@ -1,73 +0,0 @@
1
- import { Stream } from "stream";
2
- import { _KunlunOpenSDKFile } from "./impl/resources";
3
- import { UploadFileResp } from "../../request/interface";
4
-
5
- export interface _FileInfo {
6
- id: string;
7
- }
8
-
9
- export interface _IKunlunFile {
10
- /**
11
- * 上传文件
12
- * @param filePath 文件路径
13
- * @param expire 文件过期时间,可选,单位:秒
14
- */
15
- upload(filePath: string, expire?: number): Promise<UploadFileResp>;
16
- /**
17
- * 上传文件
18
- * @param stream 文件流
19
- * @param expire 文件过期时间,可选,单位:秒
20
- */
21
- upload(stream: Stream, expire?: number): Promise<UploadFileResp>;
22
- /**
23
- * 下载文件
24
- * @param fileToken 文件令牌
25
- */
26
- download(fileToken: string): Promise<Buffer>;
27
-
28
- /**
29
- * 下载文件
30
- * @param fileToken 文件令牌
31
- * @param filePath 文件保存的路径
32
- */
33
- download(fileToken: string, filePath: string): Promise<void>;
34
-
35
- /**
36
- * 下载文件
37
- * @param fileInfo 文件信息
38
- */
39
- download(fileInfo: _FileInfo): Promise<Buffer>;
40
-
41
- /**
42
- * 下载文件
43
- * @param fileInfo 文件信息
44
- * @param filePath 文件保存的路径
45
- */
46
- download(fileInfo: _FileInfo, filePath: string): Promise<void>;
47
- }
48
-
49
- export type FileUploadResult = {
50
- fileId: string;
51
- type: string;
52
- name: string;
53
- size: number;
54
- };
55
-
56
- export type UploadAvatarResult = {
57
- ImageId: string;
58
- PreviewImageId: string;
59
- };
60
- export interface _IOpenSDKFile {
61
- Upload(fileName: string, path: string): Promise<FileUploadResult>;
62
- Upload(fileName: string, reader: Stream): Promise<FileUploadResult>;
63
- Upload(fileName: string, buffer: Buffer): Promise<FileUploadResult>;
64
- UploadAvatar(fileName: string, path: string): Promise<UploadAvatarResult>;
65
- UploadAvatar(fileName: string, reader: Stream): Promise<UploadAvatarResult>;
66
- UploadAvatar(fileName: string, buffer: Buffer): Promise<UploadAvatarResult>;
67
- Download(fileID: string): Promise<Buffer>;
68
- DownloadAvatar(imageID: string): Promise<Buffer>;
69
- }
70
-
71
- export interface _IOpenSDKResources {
72
- file: _IOpenSDKFile;
73
- }
@@ -1,170 +0,0 @@
1
- import { Stream } from "stream";
2
- import { _FileInfo, _IKunlunFile, _IOpenSDKFile, UploadAvatarResult, FileUploadResult } from "../IResources";
3
- import * as Request from "../../../request/interface";
4
- import { runCtxForOpenSDK } from "../../../application/impl/common";
5
- import * as common from "@byted-apaas/server-common-node"
6
- import { AppCtx } from "../../../application/application";
7
- import { streamToBuffer } from "@jorgeferrero/stream-to-buffer";
8
-
9
- const exceptions = common.exceptions;
10
-
11
- const fs = require('fs');
12
-
13
- export class _KunlunOpenSDKFile implements _IOpenSDKFile {
14
- appCtx: AppCtx
15
-
16
- constructor(appCtx: AppCtx) {
17
- this.appCtx = appCtx;
18
- }
19
-
20
- async Upload(fileName: string, path: string): Promise<FileUploadResult>;
21
- async Upload(fileName: string, reader: Stream): Promise<FileUploadResult>;
22
- async Upload(fileName: string, buffer: Buffer): Promise<FileUploadResult>;
23
- async Upload(fileName: string, source: string | Stream | Buffer): Promise<FileUploadResult> {
24
- // 1. check parameters type
25
- if (typeof fileName !== 'string') {
26
- throw new exceptions.InvalidParamError('upload method parameter fileName must be string. ');
27
- }
28
- if (typeof source !== 'string' && !(source instanceof Stream) && !(source instanceof Buffer)) {
29
- throw new exceptions.InvalidParamError('upload method parameter source must be string or stream or buffer. ');
30
- }
31
- // 2. divide by source type
32
- if (typeof source === 'string') {
33
- // upload from path
34
- if (!fs.existsSync(source)) {
35
- throw new exceptions.InvalidParamError(`no such file '${source}'`)
36
- }
37
- source = fs.createReadStream(source);
38
- }
39
- if (source instanceof Stream) {
40
- // upload from stream
41
- source = await streamToBuffer(source as any);
42
- }
43
- if (source instanceof Buffer) {
44
- return await runCtxForOpenSDK(this.appCtx, async () => {
45
- return await Request.GetInstance().openSDKUploadFile(fileName, source as Buffer);
46
- });
47
- }
48
- return null;
49
- };
50
- async UploadAvatar(fileName: string, path: string): Promise<UploadAvatarResult>;
51
- async UploadAvatar(fileName: string, reader: Stream): Promise<UploadAvatarResult>;
52
- async UploadAvatar(fileName: string, buffer: Buffer): Promise<UploadAvatarResult>;
53
- async UploadAvatar(fileName: string, source: string | Stream | Buffer): Promise<UploadAvatarResult> {
54
- // 1. check parameters type
55
- if (typeof fileName !== 'string') {
56
- throw new exceptions.InvalidParamError('upload method parameter fileName must be string. ');
57
- }
58
- if (typeof source !== 'string' && !(source instanceof Stream) && !(source instanceof Buffer)) {
59
- throw new exceptions.InvalidParamError('upload method parameter source must be string or stream or buffer. ');
60
- }
61
- // 2. divide by source type
62
- if (typeof source === 'string') {
63
- // upload from path
64
- if (!fs.existsSync(source)) {
65
- throw new exceptions.InvalidParamError(`no such file '${source}'`)
66
- }
67
- source = fs.createReadStream(source);
68
- }
69
- if (source instanceof Stream) {
70
- // upload from stream
71
- source = await streamToBuffer(source as any);
72
- }
73
- if (source instanceof Buffer) {
74
- // upload from buffer
75
- return await runCtxForOpenSDK(this.appCtx, async () => {
76
- return await Request.GetInstance().openSDKUploadAvatar(fileName, source as Buffer);
77
- })
78
- }
79
- return null;
80
- };
81
- async Download(fileID: string): Promise<Buffer> {
82
- // 1. check parameters type
83
- if (typeof fileID !== 'string') {
84
- throw new exceptions.InvalidParamError('download method parameter fileID must be string. ');
85
- }
86
- return await runCtxForOpenSDK(this.appCtx, async () => {
87
- return await Request.GetInstance().downloadFileByID(fileID) as Buffer;
88
- })
89
- };
90
- async DownloadAvatar(imageID: string): Promise<Buffer> {
91
- // 1. check parameters type
92
- if (typeof imageID !== 'string') {
93
- throw new exceptions.InvalidParamError('download method parameter imageID must be string. ');
94
- }
95
- return await runCtxForOpenSDK(this.appCtx, async () => {
96
- return await Request.GetInstance().openSDKDownloadAvatar(imageID) as Buffer;
97
- })
98
- };
99
- }
100
-
101
- export class _KunlunFile implements _IKunlunFile {
102
- async download(fileToken: string): Promise<Buffer>;
103
- async download(fileToken: string, filePath?: string): Promise<void>;
104
- async download(fileToken: _FileInfo): Promise<Buffer>;
105
- async download(fileInfo: _FileInfo, filePath: string): Promise<void>;
106
- async download(fileTokenOrInfo: string | _FileInfo, filePath?: string): Promise<Buffer | void> {
107
- if (typeof (fileTokenOrInfo) === "string") {
108
- return await Request.GetInstance().downloadFileByToken(fileTokenOrInfo, filePath);
109
- } else if (typeof (fileTokenOrInfo) === "object") {
110
- if (!fileTokenOrInfo.id) {
111
- throw new exceptions.InvalidParamError(`The value of fileInfo.id is empty`);
112
- }
113
-
114
- if (typeof (fileTokenOrInfo.id) !== "string") {
115
- throw new exceptions.InvalidParamError(`The type of fileInfo.id should be string, but ${typeof (fileTokenOrInfo)}`);
116
- }
117
- return await Request.GetInstance().downloadFileByID(fileTokenOrInfo.id, filePath);
118
- } else {
119
- throw new exceptions.InvalidParamError(`The type of first param should be string or object, but ${typeof (fileTokenOrInfo)}`);
120
- }
121
- }
122
-
123
- async upload(filePath: string): Promise<Request.UploadFileResp>;
124
- async upload(stream: Stream): Promise<Request.UploadFileResp>;
125
- async upload(filePath: string, expire: number): Promise<Request.UploadFileResp>;
126
- async upload(stream: Stream, expire: number): Promise<Request.UploadFileResp>;
127
- async upload(data: string | Stream, expire?: number, ...ret: string[]): Promise<Request.UploadFileResp> {
128
- if (ret.length > 0) {
129
- throw new exceptions.InvalidParamError(`params is too many, as ${ret.length + 2}`)
130
- }
131
- if (!data) {
132
- throw new exceptions.InvalidParamError(`params is null`)
133
- }
134
-
135
- // 1. data is filePath, read it from disk, convert it to Steam.
136
- if (typeof (data) === 'string') {
137
- if (!fs.existsSync(data)) {
138
- throw new exceptions.InvalidParamError(`no such file '${data}'`)
139
- }
140
- data = fs.createReadStream(data);
141
- }
142
-
143
- // 2. data must be Stream at here.
144
- return await Request.GetInstance().uploadFile(data as Stream, expire);
145
- }
146
- }
147
-
148
- /**
149
- * OpenSDK 静态资源操作类
150
- */
151
- export class _OpenSDKResources {
152
- file: _IOpenSDKFile;
153
-
154
- constructor(appCtx: AppCtx) {
155
- this.file = new _KunlunOpenSDKFile(appCtx);
156
- }
157
- }
158
-
159
- /**
160
- * 静态资源操作类
161
- */
162
- export class _Resources {
163
-
164
- file: _IKunlunFile;
165
-
166
- constructor() {
167
- this.file = new _KunlunFile();
168
- }
169
-
170
- }