wtfai 1.6.1 → 1.6.3
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/README.md +12 -0
- package/dist/iframe-bridge.js +4 -0
- package/dist/session.d.ts +7 -0
- package/dist/session.js +18 -0
- package/dist/upload.js +21 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -519,6 +519,18 @@ const id = await IframeBridge.createRecord('notes', {
|
|
|
519
519
|
console.log('创建成功, ID:', id);
|
|
520
520
|
```
|
|
521
521
|
|
|
522
|
+
#### `IframeBridge.createRecords(collection, dataList)`
|
|
523
|
+
|
|
524
|
+
批量在指定集合中创建多条记录。
|
|
525
|
+
|
|
526
|
+
```javascript
|
|
527
|
+
const ids = await IframeBridge.createRecords('logs', [
|
|
528
|
+
{ level: 'info', message: 'Task started' },
|
|
529
|
+
{ level: 'success', message: 'Task finished' }
|
|
530
|
+
]);
|
|
531
|
+
console.log('创建成功, IDs:', ids);
|
|
532
|
+
```
|
|
533
|
+
|
|
522
534
|
#### `IframeBridge.getRecord(collection, id)`
|
|
523
535
|
|
|
524
536
|
获取单条记录。
|
package/dist/iframe-bridge.js
CHANGED
|
@@ -58,6 +58,9 @@ class IframeBridgeHost {
|
|
|
58
58
|
} else if ('createRecord' === method) {
|
|
59
59
|
const [collection, data] = params;
|
|
60
60
|
result = await this.session.createRecord(collection, data);
|
|
61
|
+
} else if ('createRecords' === method) {
|
|
62
|
+
const [collection, dataList] = params;
|
|
63
|
+
result = await this.session.createRecords(collection, dataList);
|
|
61
64
|
} else if ('getRecord' === method) {
|
|
62
65
|
const [collection, id] = params;
|
|
63
66
|
result = await this.session.getRecord(collection, id);
|
|
@@ -99,6 +102,7 @@ class IframeBridgeHost {
|
|
|
99
102
|
'updateSessionTitle',
|
|
100
103
|
'getSessionId',
|
|
101
104
|
'createRecord',
|
|
105
|
+
'createRecords',
|
|
102
106
|
'getRecord',
|
|
103
107
|
'updateRecord',
|
|
104
108
|
'deleteRecord',
|
package/dist/session.d.ts
CHANGED
|
@@ -83,6 +83,13 @@ export declare class WorkflowSession {
|
|
|
83
83
|
* @returns 新创建记录的 ID
|
|
84
84
|
*/
|
|
85
85
|
createRecord(collection: string, data: Record<string, unknown>): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* 批量创建数据记录
|
|
88
|
+
* @param collection 集合名称
|
|
89
|
+
* @param dataList 数据列表
|
|
90
|
+
* @returns 新创建记录的 ID 列表
|
|
91
|
+
*/
|
|
92
|
+
createRecords(collection: string, dataList: Array<Record<string, unknown>>): Promise<string[]>;
|
|
86
93
|
/**
|
|
87
94
|
* 获取数据记录
|
|
88
95
|
* @param collection 集合名称
|
package/dist/session.js
CHANGED
|
@@ -179,6 +179,24 @@ class WorkflowSession {
|
|
|
179
179
|
const result = await response.json();
|
|
180
180
|
return result.id;
|
|
181
181
|
}
|
|
182
|
+
async createRecords(collection, dataList) {
|
|
183
|
+
this.assertNotDisposed();
|
|
184
|
+
if (!this.state.threadId) throw new Error('No active session (missing threadId)');
|
|
185
|
+
const response = await fetch(`${this.baseUrl}/workflows/${this.workflowId}/data/${encodeURIComponent(collection)}/batch`, {
|
|
186
|
+
method: 'POST',
|
|
187
|
+
headers: {
|
|
188
|
+
'Content-Type': 'application/json',
|
|
189
|
+
...this.headers
|
|
190
|
+
},
|
|
191
|
+
body: JSON.stringify({
|
|
192
|
+
threadId: this.state.threadId,
|
|
193
|
+
dataList
|
|
194
|
+
})
|
|
195
|
+
});
|
|
196
|
+
if (!response.ok) throw new Error('Failed to create records');
|
|
197
|
+
const result = await response.json();
|
|
198
|
+
return result.ids;
|
|
199
|
+
}
|
|
182
200
|
async getRecord(collection, id) {
|
|
183
201
|
this.assertNotDisposed();
|
|
184
202
|
if (!this.state.threadId) throw new Error('No active session (missing threadId)');
|
package/dist/upload.js
CHANGED
|
@@ -79,13 +79,7 @@ class UploadService {
|
|
|
79
79
|
'Content-Type': 'application/json',
|
|
80
80
|
...this.headers
|
|
81
81
|
},
|
|
82
|
-
body: JSON.stringify(
|
|
83
|
-
resourceType: params.resourceType,
|
|
84
|
-
filename: params.filename,
|
|
85
|
-
hash: params.hash,
|
|
86
|
-
size: params.size,
|
|
87
|
-
durationSeconds: params.durationSeconds
|
|
88
|
-
})
|
|
82
|
+
body: JSON.stringify(params)
|
|
89
83
|
});
|
|
90
84
|
if (!response.ok) {
|
|
91
85
|
const error = await response.json().catch(()=>({}));
|
|
@@ -112,7 +106,7 @@ class UploadService {
|
|
|
112
106
|
};
|
|
113
107
|
}
|
|
114
108
|
async uploadFile(params) {
|
|
115
|
-
const { file, resourceType, onProgress } = params;
|
|
109
|
+
const { file, resourceType, onProgress, ...rest } = params;
|
|
116
110
|
const hash = await this.computeFileHash(file);
|
|
117
111
|
let durationSeconds;
|
|
118
112
|
if (this.isMediaFile(file)) durationSeconds = await this.getMediaDuration(file);
|
|
@@ -121,7 +115,8 @@ class UploadService {
|
|
|
121
115
|
filename: file.name,
|
|
122
116
|
hash,
|
|
123
117
|
size: file.size,
|
|
124
|
-
durationSeconds
|
|
118
|
+
durationSeconds,
|
|
119
|
+
...rest
|
|
125
120
|
});
|
|
126
121
|
return new Promise((resolve, reject)=>{
|
|
127
122
|
cos.putObject({
|
|
@@ -132,22 +127,34 @@ class UploadService {
|
|
|
132
127
|
onProgress: (progressData)=>{
|
|
133
128
|
if (onProgress) onProgress(progressData.percent);
|
|
134
129
|
}
|
|
135
|
-
}, (err, _data)=>{
|
|
130
|
+
}, async (err, _data)=>{
|
|
136
131
|
if (err) reject(err);
|
|
137
132
|
else {
|
|
138
|
-
const
|
|
139
|
-
|
|
133
|
+
const searchParams = new URLSearchParams({
|
|
134
|
+
key,
|
|
135
|
+
...rest
|
|
136
|
+
});
|
|
137
|
+
const res = await fetch(`${this.baseUrl}/cos/signed-url?${searchParams.toString()}`, {
|
|
138
|
+
method: 'GET',
|
|
139
|
+
headers: {
|
|
140
|
+
'Content-Type': 'application/json',
|
|
141
|
+
...this.headers
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const data = await res.json();
|
|
145
|
+
resolve(data.url);
|
|
140
146
|
}
|
|
141
147
|
});
|
|
142
148
|
});
|
|
143
149
|
}
|
|
144
150
|
async uploadImage(params) {
|
|
145
|
-
const { file, resourceType, onProgress, compressOptions } = params;
|
|
151
|
+
const { file, resourceType, onProgress, compressOptions, ...rest } = params;
|
|
146
152
|
const compressedFile = await this.compressImage(file, compressOptions);
|
|
147
153
|
return this.uploadFile({
|
|
148
154
|
file: compressedFile,
|
|
149
155
|
resourceType,
|
|
150
|
-
onProgress
|
|
156
|
+
onProgress,
|
|
157
|
+
...rest
|
|
151
158
|
});
|
|
152
159
|
}
|
|
153
160
|
constructor(baseUrl, headers = {}){
|