perf: 支持查看原图

close #33
This commit is contained in:
clansty 2022-08-10 13:37:26 +08:00
parent 25703b2f61
commit b9357af06b
4 changed files with 34 additions and 8 deletions

View File

@ -12,6 +12,7 @@
"@types/cli-progress": "^3.11.0",
"@types/date-and-time": "^0.13.0",
"@types/fluent-ffmpeg": "^2.1.20",
"@types/lodash": "^4",
"@types/node": "^18.6.3",
"@types/prompts": "^2.0.14",
"@types/sharp": "^0.30.4",
@ -29,6 +30,7 @@
"eviltransform": "^0.2.2",
"file-type": "^17.1.4",
"fluent-ffmpeg": "^2.1.2",
"lodash": "^4.17.21",
"log4js": "^6.6.1",
"nodejs-base64": "^2.0.0",
"oicq": "^2.3.1",

5
src/constants/emoji.ts Normal file
View File

@ -0,0 +1,5 @@
import random from '../utils/random';
export default {
picture: () => random.pick('🎆', '🌃', '🌇', '🎇', '🌌', '🌠', '🌅', '🌉', '🏞', '🌆', '🌄', '🖼', '🗾', '🎑', '🏙', '🩻', '🌁'),
};

View File

@ -1,7 +1,7 @@
import Telegram from '../client/Telegram';
import { Group, GroupMessageEvent, PrivateMessageEvent, Quotable, segment, Sendable } from 'oicq';
import { fetchFile, getBigFaceUrl, getImageUrlByMd5 } from '../utils/urls';
import { FileLike, MarkupLike } from 'telegram/define';
import { ButtonLike, FileLike, MarkupLike } from 'telegram/define';
import { CustomFile } from 'telegram/client/uploads';
import { getLogger, Logger } from 'log4js';
import path from 'path';
@ -25,6 +25,8 @@ import sharp from 'sharp';
import convertWithFfmpeg from '../encoding/convertWithFfmpeg';
import OicqClient from '../client/OicqClient';
import lottie from '../constants/lottie';
import _ from 'lodash';
import emoji from '../constants/emoji';
const NOT_CHAINABLE_ELEMENTS = ['flash', 'record', 'video', 'location', 'share', 'json', 'xml', 'poke'];
@ -41,7 +43,7 @@ export default class ForwardService {
public async forwardFromQq(event: PrivateMessageEvent | GroupMessageEvent, pair: Pair) {
try {
const tempFiles: FileResult[] = [];
let message = '', files: FileLike[] = [], button: MarkupLike, replyTo = 0, tgs = -1;
let message = '', files: FileLike[] = [], buttons: ButtonLike[] = [], replyTo = 0, tgs = -1;
let messageHeader = '';
if (event.message_type === 'group') {
// 产生头部,这和工作模式没有关系
@ -92,6 +94,7 @@ export default class ForwardService {
url = elem.url;
try {
files.push(await helper.downloadToCustomFile(url, !(message || messageHeader)));
buttons.push(Button.url(`${emoji.picture()} 查看原图`, url));
}
catch (e) {
this.log.error('下载媒体失败', e);
@ -104,7 +107,7 @@ export default class ForwardService {
const dbEntry = await db.flashPhoto.create({
data: { photoMd5: (elem.file as string).substring(0, 32) },
});
button = Button.url('📸查看', `https://t.me/${this.tgBot.me.username}?start=flash-${dbEntry.id}`);
buttons.push(Button.url('📸查看', `https://t.me/${this.tgBot.me.username}?start=flash-${dbEntry.id}`));
break;
}
case 'file': {
@ -132,8 +135,8 @@ export default class ForwardService {
const dbEntry = await db.file.create({
data: { fileId: elem.fid, roomId: pair.qqRoomId, info: message },
});
button = Button.url('📎获取下载地址',
`https://t.me/${this.tgBot.me.username}?start=file-${dbEntry.id}`);
buttons.push(Button.url('📎获取下载地址',
`https://t.me/${this.tgBot.me.username}?start=file-${dbEntry.id}`));
break;
}
case 'record': {
@ -172,7 +175,7 @@ export default class ForwardService {
const messages = await pair.qq.getForwardMsg(result.resId);
message = helper.generateForwardBrief(messages);
const hash = md5Hex(result.resId);
button = Button.url('📃查看', `${process.env.CRV_API}/?hash=${hash}`);
buttons.push(Button.url('📃查看', `${process.env.CRV_API}/?hash=${hash}`));
// 传到 Cloudflare
axios.post(`${process.env.CRV_API}/add`, {
auth: process.env.CRV_KEY,
@ -237,12 +240,12 @@ export default class ForwardService {
else if (files.length) {
messageToSend.file = files;
}
button && (messageToSend.buttons = button);
buttons.length && (messageToSend.buttons = _.chunk(buttons, 3));
replyTo && (messageToSend.replyTo = replyTo);
const tgMessages: Api.Message[] = [];
if (message || files.length || button) {
if (message || files.length || buttons) {
tgMessages.push(await pair.tg.sendMessage(messageToSend));
}
if (tgs > -1) {

View File

@ -167,6 +167,13 @@ __metadata:
languageName: node
linkType: hard
"@types/lodash@npm:^4":
version: 4.14.182
resolution: "@types/lodash@npm:4.14.182"
checksum: 7dd137aa9dbabd632408bd37009d984655164fa1ecc3f2b6eb94afe35bf0a5852cbab6183148d883e9c73a958b7fec9a9bcf7c8e45d41195add6a18c34958209
languageName: node
linkType: hard
"@types/node@npm:*":
version: 17.0.21
resolution: "@types/node@npm:17.0.21"
@ -1170,6 +1177,13 @@ __metadata:
languageName: node
linkType: hard
"lodash@npm:^4.17.21":
version: 4.17.21
resolution: "lodash@npm:4.17.21"
checksum: eb835a2e51d381e561e508ce932ea50a8e5a68f4ebdd771ea240d3048244a8d13658acbd502cd4829768c56f2e16bdd4340b9ea141297d472517b83868e677f7
languageName: node
linkType: hard
"log4js@npm:^6.3.0":
version: 6.4.1
resolution: "log4js@npm:6.4.1"
@ -1676,6 +1690,7 @@ __metadata:
"@types/cli-progress": ^3.11.0
"@types/date-and-time": ^0.13.0
"@types/fluent-ffmpeg": ^2.1.20
"@types/lodash": ^4
"@types/node": ^18.6.3
"@types/prompts": ^2.0.14
"@types/sharp": ^0.30.4
@ -1686,6 +1701,7 @@ __metadata:
eviltransform: ^0.2.2
file-type: ^17.1.4
fluent-ffmpeg: ^2.1.2
lodash: ^4.17.21
log4js: ^6.6.1
nodejs-base64: ^2.0.0
oicq: ^2.3.1