@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.
Files changed (2) hide show
  1. package/lib/sends.js +23 -31
  2. 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
- if (url) {
236
- break;
237
- }
234
+ let fileData;
235
+ let fileInfo;
238
236
  if (item.type === 'ImageURL') {
239
- url = item.value;
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 === 'ImageFile' || item.type === 'Image') {
242
- let fileData;
243
- if (item.type === 'ImageFile') {
244
- fileData = readFileSync(item.value, 'base64');
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
- if (typeof item.value === 'string' && (item.value.startsWith('https://') || item.value.startsWith('http://'))) {
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
- const fileInfo = await uploadMedia({ file_type: 1, file_data: fileData }).then(res => res?.file_info);
266
- if (fileInfo) {
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alemonjs/qq-bot",
3
- "version": "2.1.0-alpha.25",
3
+ "version": "2.1.0-alpha.26",
4
4
  "description": "阿柠檬qq-bot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",