@alemonjs/qq-bot 2.1.0-alpha.24 → 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 +25 -11
  2. package/package.json +1 -1
package/lib/sends.js CHANGED
@@ -230,23 +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
- const fileData = item.type === 'ImageFile' ? readFileSync(item.value, 'base64') : item.value;
243
- const fileInfo = await uploadMedia({ file_type: 1, file_data: fileData }).then(res => res?.file_info);
244
- if (fileInfo) {
245
- url = fileInfo;
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');
246
+ }
247
+ else if (typeof item.value === 'string' && item.value.startsWith('base64://')) {
248
+ fileData = item.value.replace('base64://', '');
249
+ }
250
+ else if (Buffer.isBuffer(item.value)) {
251
+ fileData = item.value.toString('base64');
246
252
  }
247
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
+ }
248
263
  }
249
- return url;
250
264
  };
251
265
  const sendOpenApiMessage = async (content, val, baseParams, uploadMedia, sendMessage, label) => {
252
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.24",
3
+ "version": "2.1.0-alpha.26",
4
4
  "description": "阿柠檬qq-bot平台连接",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",