@alemonjs/qq-bot 2.1.0-alpha.25 → 2.1.0-alpha.26
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/lib/sends.js +23 -31
- package/package.json +1 -1
package/lib/sends.js
CHANGED
|
@@ -230,45 +230,37 @@ const filterImages = (val) => {
|
|
|
230
230
|
return val.filter(item => item.type === 'Image' || item.type === 'ImageFile' || item.type === 'ImageURL');
|
|
231
231
|
};
|
|
232
232
|
const resolveRichMediaUrl = async (images, uploadMedia) => {
|
|
233
|
-
let url = '';
|
|
234
233
|
for (const item of images) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
234
|
+
let fileData;
|
|
235
|
+
let fileInfo;
|
|
238
236
|
if (item.type === 'ImageURL') {
|
|
239
|
-
|
|
237
|
+
fileData = await axios.get(item.value, { responseType: 'arraybuffer' }).then(res => Buffer.from(res.data, 'binary').toString('base64'));
|
|
240
238
|
}
|
|
241
|
-
else if (item.type === '
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
239
|
+
else if (item.type === 'Image') {
|
|
240
|
+
if (typeof item.value === 'string' && (item.value.startsWith('https://') || item.value.startsWith('http://'))) {
|
|
241
|
+
fileData = await axios.get(item.value, { responseType: 'arraybuffer' }).then(res => Buffer.from(res.data, 'binary').toString('base64'));
|
|
242
|
+
}
|
|
243
|
+
else if (typeof item.value === 'string' && item.value.startsWith('file://')) {
|
|
244
|
+
const localFilePath = item.value.replace('file://', '');
|
|
245
|
+
fileData = readFileSync(localFilePath, 'base64');
|
|
245
246
|
}
|
|
246
|
-
else {
|
|
247
|
-
|
|
248
|
-
fileData = await axios.get(item.value, { responseType: 'arraybuffer' }).then(res => Buffer.from(res.data, 'binary').toString('base64'));
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
else if (typeof item.value === 'string' && item.value.startsWith('file://')) {
|
|
252
|
-
const localFilePath = item.value.replace('file://', '');
|
|
253
|
-
fileData = readFileSync(localFilePath, 'base64');
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
else if (typeof item.value === 'string' && item.value.startsWith('base64://')) {
|
|
257
|
-
fileData = item.value.replace('base64://', '');
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
else if (Buffer.isBuffer(item.value)) {
|
|
261
|
-
fileData = item.value.toString('base64');
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
247
|
+
else if (typeof item.value === 'string' && item.value.startsWith('base64://')) {
|
|
248
|
+
fileData = item.value.replace('base64://', '');
|
|
264
249
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
url = fileInfo;
|
|
250
|
+
else if (Buffer.isBuffer(item.value)) {
|
|
251
|
+
fileData = item.value.toString('base64');
|
|
268
252
|
}
|
|
269
253
|
}
|
|
254
|
+
else if (item.type === 'ImageFile') {
|
|
255
|
+
fileData = readFileSync(item.value, 'base64');
|
|
256
|
+
}
|
|
257
|
+
if (fileData) {
|
|
258
|
+
fileInfo = await uploadMedia({ file_type: 1, file_data: fileData }).then(res => res?.file_info);
|
|
259
|
+
}
|
|
260
|
+
if (fileInfo) {
|
|
261
|
+
return fileInfo;
|
|
262
|
+
}
|
|
270
263
|
}
|
|
271
|
-
return url;
|
|
272
264
|
};
|
|
273
265
|
const sendOpenApiMessage = async (content, val, baseParams, uploadMedia, sendMessage, label) => {
|
|
274
266
|
const images = filterImages(val);
|