new(all): #329 MERGE keyword added.
This commit is contained in:
parent
3d500051fa
commit
be5cf3f190
4 changed files with 41 additions and 0 deletions
|
@ -105,6 +105,7 @@
|
|||
"google-libphonenumber": "3.2.31",
|
||||
"googleapis": "109.0.1",
|
||||
"ibm-watson": "7.1.2",
|
||||
"join-images-updated": "1.1.4",
|
||||
"keyv": "4.5.2",
|
||||
"koa": "2.13.4",
|
||||
"koa-body": "6.0.1",
|
||||
|
|
|
@ -32,9 +32,15 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
import Path from 'path';
|
||||
import { GBLog, GBMinInstance } from 'botlib';
|
||||
import { DialogKeywords } from './DialogKeywords.js';
|
||||
import sharp from 'sharp';
|
||||
import joinImages from 'join-images-updated';
|
||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
||||
import urlJoin from 'url-join';
|
||||
import { GBServer } from '../../../src/app.js';
|
||||
|
||||
/**
|
||||
* Image processing services of conversation to be called by BASIC.
|
||||
|
@ -95,6 +101,32 @@ export class ImageProcessingServices {
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* SET ORIENTATION VERTICAL
|
||||
*
|
||||
* file = MERGE file1, file2, file3
|
||||
*/
|
||||
public async mergeImage({pid, files})
|
||||
{
|
||||
const { min, user } = await DialogKeywords.getProcessInfo(pid);
|
||||
|
||||
let paths = [];
|
||||
await CollectionUtil.asyncForEach(files, async file => {
|
||||
const gbfile = DialogKeywords.getFileByHandle(file);
|
||||
paths.push(gbfile.path);
|
||||
});
|
||||
|
||||
const botId = this.min.instance.botId;
|
||||
const gbaiName = `${botId}.gbai`;
|
||||
const img = await joinImages(paths);
|
||||
const localName = Path.join('work', gbaiName, 'cache', `img-mrg${GBAdminService.getRndReadableIdentifier()}.png`);
|
||||
const url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||
img.toFile(localName);
|
||||
|
||||
return { localName: localName, url: url, data: null };
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sharpen the image.
|
||||
*
|
||||
|
|
|
@ -677,6 +677,13 @@ export class KeywordsExpressions {
|
|||
}
|
||||
];
|
||||
|
||||
keywords[i++] = [
|
||||
/^\s*(MERGE)(\s*)(.*)/gim,
|
||||
($0, $1, $2, $3) => {
|
||||
return `await img.mergeImage({pid: pid, files: [${$3}]})`;
|
||||
}
|
||||
];
|
||||
|
||||
keywords[i++] = [
|
||||
/^\s*PRESS\s*(.*)/gim,
|
||||
($0, $1, $2) => {
|
||||
|
|
|
@ -1412,6 +1412,7 @@ export class SystemKeywords {
|
|||
const images = [];
|
||||
let index = 0;
|
||||
path = Path.join(gbaiName, 'cache', `tmp${GBAdminService.getRndReadableIdentifier()}.docx`);
|
||||
url = urlJoin(GBServer.globals.publicAddress, min.botId, 'cache', Path.basename(localName));
|
||||
|
||||
const traverseDataToInjectImageUrl = async o => {
|
||||
for (var i in o) {
|
||||
|
|
Loading…
Add table
Reference in a new issue