@cpzxrobot/sdk 1.3.55 → 1.3.57
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/dist/user_gateway.js +6 -2
- package/dist/web_platform.js +82 -1
- package/package.json +1 -1
- package/user_gateway.ts +6 -2
- package/web_platform.ts +87 -8
package/dist/user_gateway.js
CHANGED
|
@@ -266,10 +266,14 @@ class UserGateway extends Object {
|
|
|
266
266
|
},
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
|
-
async info() {
|
|
269
|
+
async info(userId) {
|
|
270
270
|
var axios = await this.context.ready;
|
|
271
271
|
var factory = await this.context.user.getSelectedFarm();
|
|
272
|
-
|
|
272
|
+
var url = '/api/v1/user/info';
|
|
273
|
+
if (userId) {
|
|
274
|
+
url += `/${userId}`;
|
|
275
|
+
}
|
|
276
|
+
return axios.get(url, {
|
|
273
277
|
params: {
|
|
274
278
|
selected_factory: factory,
|
|
275
279
|
},
|
package/dist/web_platform.js
CHANGED
|
@@ -186,8 +186,89 @@ class WebPlatform {
|
|
|
186
186
|
return { data: blob };
|
|
187
187
|
},
|
|
188
188
|
getAndPreview: async function (url, config) {
|
|
189
|
+
var _a;
|
|
189
190
|
url = instance.processQueryParams(url, config);
|
|
190
|
-
|
|
191
|
+
const response = await instance.fetchWithAuth(url, {
|
|
192
|
+
method: 'GET',
|
|
193
|
+
});
|
|
194
|
+
const blob = await response.blob();
|
|
195
|
+
const contentType = response.headers.get('Content-Type') || '';
|
|
196
|
+
// 解析文件名
|
|
197
|
+
const contentDisposition = response.headers.get('Content-Disposition');
|
|
198
|
+
let filename = (_a = config === null || config === void 0 ? void 0 : config.fileName) !== null && _a !== void 0 ? _a : "";
|
|
199
|
+
if (filename === "") {
|
|
200
|
+
if (contentDisposition) {
|
|
201
|
+
const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
|
|
202
|
+
if (utf8FilenameMatch) {
|
|
203
|
+
filename = decodeURIComponent(utf8FilenameMatch[1]);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
|
|
207
|
+
if (filenameMatch)
|
|
208
|
+
filename = filenameMatch[1];
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
filename = "file";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
// 支持预览的文件类型
|
|
216
|
+
const previewableTypes = [
|
|
217
|
+
'image/jpeg', 'image/png', 'image/gif', 'image/svg+xml',
|
|
218
|
+
'application/pdf',
|
|
219
|
+
'text/plain', 'application/json', 'text/csv', 'text/xml',
|
|
220
|
+
'video/mp4', 'audio/mpeg'
|
|
221
|
+
];
|
|
222
|
+
if (previewableTypes.some(type => contentType.includes(type))) {
|
|
223
|
+
const previewUrl = URL.createObjectURL(blob);
|
|
224
|
+
if (contentType.includes('image')) {
|
|
225
|
+
// 图片预览 - 直接在新窗口打开 blob URL
|
|
226
|
+
const win = window.open(previewUrl, '_blank');
|
|
227
|
+
if (win) {
|
|
228
|
+
win.document.title = filename;
|
|
229
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
230
|
+
}
|
|
231
|
+
return { data: blob };
|
|
232
|
+
}
|
|
233
|
+
else if (contentType.includes('pdf')) {
|
|
234
|
+
// PDF预览 - 直接在新窗口打开 blob URL
|
|
235
|
+
const win = window.open(previewUrl, '_blank');
|
|
236
|
+
if (win) {
|
|
237
|
+
win.document.title = filename;
|
|
238
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
239
|
+
}
|
|
240
|
+
return { data: blob };
|
|
241
|
+
}
|
|
242
|
+
else if (contentType.includes('text') || contentType.includes('json') || contentType.includes('xml') || contentType.includes('csv')) {
|
|
243
|
+
// 文本文件预览 - 创建下载链接并自动点击
|
|
244
|
+
const text = await blob.text();
|
|
245
|
+
const blobObj = new Blob([text], { type: contentType });
|
|
246
|
+
const url = URL.createObjectURL(blobObj);
|
|
247
|
+
const a = document.createElement('a');
|
|
248
|
+
a.href = url;
|
|
249
|
+
a.target = '_blank';
|
|
250
|
+
a.style.display = 'none';
|
|
251
|
+
document.body.appendChild(a);
|
|
252
|
+
a.click();
|
|
253
|
+
setTimeout(() => {
|
|
254
|
+
document.body.removeChild(a);
|
|
255
|
+
URL.revokeObjectURL(url);
|
|
256
|
+
}, 100);
|
|
257
|
+
return { data: blob };
|
|
258
|
+
}
|
|
259
|
+
else if (contentType.includes('video') || contentType.includes('audio')) {
|
|
260
|
+
// 视频/音频预览 - 直接在新窗口打开 blob URL
|
|
261
|
+
const win = window.open(previewUrl, '_blank');
|
|
262
|
+
if (win) {
|
|
263
|
+
win.document.title = filename;
|
|
264
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
265
|
+
}
|
|
266
|
+
return { data: blob };
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// 不支持的预览类型或preview=false时,直接下载
|
|
270
|
+
await instance.saveBlob(blob, filename);
|
|
271
|
+
return { data: blob };
|
|
191
272
|
},
|
|
192
273
|
upload: async (url, option) => {
|
|
193
274
|
return new Promise((resolve, reject) => {
|
package/package.json
CHANGED
package/user_gateway.ts
CHANGED
|
@@ -322,10 +322,14 @@ export class UserGateway extends Object {
|
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
-
async info() {
|
|
325
|
+
async info(userId: number|undefined) {
|
|
326
326
|
var axios = await this.context.ready
|
|
327
327
|
var factory = await this.context.user.getSelectedFarm()
|
|
328
|
-
|
|
328
|
+
var url = '/api/v1/user/info'
|
|
329
|
+
if (userId) {
|
|
330
|
+
url += `/${userId}`
|
|
331
|
+
}
|
|
332
|
+
return axios.get(url, {
|
|
329
333
|
params: {
|
|
330
334
|
selected_factory: factory,
|
|
331
335
|
},
|
package/web_platform.ts
CHANGED
|
@@ -98,7 +98,7 @@ export class WebPlatform implements PlatformInterface {
|
|
|
98
98
|
if (config && config.params) {
|
|
99
99
|
// 检查URL是否已包含查询参数
|
|
100
100
|
const hasExistingParams = url.includes('?');
|
|
101
|
-
|
|
101
|
+
|
|
102
102
|
const flattenParams = (params: any, prefix = '') => {
|
|
103
103
|
const result: Record<string, string> = {};
|
|
104
104
|
Object.keys(params).forEach(key => {
|
|
@@ -112,10 +112,10 @@ export class WebPlatform implements PlatformInterface {
|
|
|
112
112
|
});
|
|
113
113
|
return result;
|
|
114
114
|
};
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
const flattened = flattenParams(config.params);
|
|
117
117
|
const newParams = new URLSearchParams(flattened).toString();
|
|
118
|
-
|
|
118
|
+
|
|
119
119
|
// 根据是否已有参数决定使用?还是&连接
|
|
120
120
|
url += (hasExistingParams ? '&' : '?') + newParams;
|
|
121
121
|
delete config.params;
|
|
@@ -135,7 +135,7 @@ export class WebPlatform implements PlatformInterface {
|
|
|
135
135
|
//test content-type, if it is json, then parse it
|
|
136
136
|
if (response.headers.get('Content-Type')?.includes('application/json')) {
|
|
137
137
|
return { data: await response.json() };
|
|
138
|
-
}else {
|
|
138
|
+
} else {
|
|
139
139
|
return response.blob();
|
|
140
140
|
}
|
|
141
141
|
},
|
|
@@ -172,7 +172,7 @@ export class WebPlatform implements PlatformInterface {
|
|
|
172
172
|
});
|
|
173
173
|
return { data: await response.json() };
|
|
174
174
|
},
|
|
175
|
-
getAndSave: async function(url: string, config?: any) {
|
|
175
|
+
getAndSave: async function (url: string, config?: any) {
|
|
176
176
|
url = instance.processQueryParams(url, config);
|
|
177
177
|
const response = await instance.fetchWithAuth(url, {
|
|
178
178
|
method: 'GET',
|
|
@@ -201,13 +201,92 @@ export class WebPlatform implements PlatformInterface {
|
|
|
201
201
|
await instance.saveBlob(blob, filename);
|
|
202
202
|
return { data: blob };
|
|
203
203
|
},
|
|
204
|
-
getAndPreview: async function(url: string, config?: {
|
|
204
|
+
getAndPreview: async function (url: string, config?: {
|
|
205
205
|
fileName?: string;
|
|
206
206
|
params?: any;
|
|
207
207
|
preview?: boolean;
|
|
208
|
-
}){
|
|
208
|
+
}) {
|
|
209
209
|
url = instance.processQueryParams(url, config);
|
|
210
|
-
|
|
210
|
+
const response = await instance.fetchWithAuth(url, {
|
|
211
|
+
method: 'GET',
|
|
212
|
+
});
|
|
213
|
+
const blob = await response.blob();
|
|
214
|
+
const contentType = response.headers.get('Content-Type') || '';
|
|
215
|
+
|
|
216
|
+
// 解析文件名
|
|
217
|
+
const contentDisposition = response.headers.get('Content-Disposition');
|
|
218
|
+
let filename = config?.fileName ?? "";
|
|
219
|
+
if (filename === "") {
|
|
220
|
+
if (contentDisposition) {
|
|
221
|
+
const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
|
|
222
|
+
if (utf8FilenameMatch) {
|
|
223
|
+
filename = decodeURIComponent(utf8FilenameMatch[1]);
|
|
224
|
+
} else {
|
|
225
|
+
const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
|
|
226
|
+
if (filenameMatch) filename = filenameMatch[1];
|
|
227
|
+
}
|
|
228
|
+
} else {
|
|
229
|
+
filename = "file";
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// 支持预览的文件类型
|
|
234
|
+
const previewableTypes = [
|
|
235
|
+
'image/jpeg', 'image/png', 'image/gif', 'image/svg+xml',
|
|
236
|
+
'application/pdf',
|
|
237
|
+
'text/plain', 'application/json', 'text/csv', 'text/xml',
|
|
238
|
+
'video/mp4', 'audio/mpeg'
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
if (previewableTypes.some(type => contentType.includes(type))) {
|
|
242
|
+
const previewUrl = URL.createObjectURL(blob);
|
|
243
|
+
|
|
244
|
+
if (contentType.includes('image')) {
|
|
245
|
+
// 图片预览 - 直接在新窗口打开 blob URL
|
|
246
|
+
const win = window.open(previewUrl, '_blank');
|
|
247
|
+
if (win) {
|
|
248
|
+
win.document.title = filename;
|
|
249
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
250
|
+
}
|
|
251
|
+
return { data: blob };
|
|
252
|
+
} else if (contentType.includes('pdf')) {
|
|
253
|
+
// PDF预览 - 直接在新窗口打开 blob URL
|
|
254
|
+
const win = window.open(previewUrl, '_blank');
|
|
255
|
+
if (win) {
|
|
256
|
+
win.document.title = filename;
|
|
257
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
258
|
+
}
|
|
259
|
+
return { data: blob };
|
|
260
|
+
} else if (contentType.includes('text') || contentType.includes('json') || contentType.includes('xml') || contentType.includes('csv')) {
|
|
261
|
+
// 文本文件预览 - 创建下载链接并自动点击
|
|
262
|
+
const text = await blob.text();
|
|
263
|
+
const blobObj = new Blob([text], { type: contentType });
|
|
264
|
+
const url = URL.createObjectURL(blobObj);
|
|
265
|
+
const a = document.createElement('a');
|
|
266
|
+
a.href = url;
|
|
267
|
+
a.target = '_blank';
|
|
268
|
+
a.style.display = 'none';
|
|
269
|
+
document.body.appendChild(a);
|
|
270
|
+
a.click();
|
|
271
|
+
setTimeout(() => {
|
|
272
|
+
document.body.removeChild(a);
|
|
273
|
+
URL.revokeObjectURL(url);
|
|
274
|
+
}, 100);
|
|
275
|
+
return { data: blob };
|
|
276
|
+
} else if (contentType.includes('video') || contentType.includes('audio')) {
|
|
277
|
+
// 视频/音频预览 - 直接在新窗口打开 blob URL
|
|
278
|
+
const win = window.open(previewUrl, '_blank');
|
|
279
|
+
if (win) {
|
|
280
|
+
win.document.title = filename;
|
|
281
|
+
win.addEventListener('beforeunload', () => URL.revokeObjectURL(previewUrl));
|
|
282
|
+
}
|
|
283
|
+
return { data: blob };
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// 不支持的预览类型或preview=false时,直接下载
|
|
288
|
+
await instance.saveBlob(blob, filename);
|
|
289
|
+
return { data: blob };
|
|
211
290
|
},
|
|
212
291
|
upload: async (url: string, option?: any) => {
|
|
213
292
|
return new Promise<any>((resolve, reject) => {
|