Merge remote-tracking branch 'origin/rainbowcat' into private-icqq

# Conflicts:
#	main/src/services/ForwardService.ts
This commit is contained in:
Clansty 2024-03-29 20:58:15 +08:00
commit c64eb8768d
3 changed files with 10 additions and 4 deletions

View File

@ -7,7 +7,7 @@ import { ForwardMessage } from '@icqqjs/icqq';
import { Api } from 'telegram';
import { imageSize } from 'image-size';
import env from '../models/env';
import { md5B64 } from '../utils/hashing';
import { md5Hex } from '../utils/hashing';
const log = getLogger('ForwardHelper');
@ -198,7 +198,7 @@ export default {
generateRichHeaderUrl(apiKey: string, userId: number, messageHeader = '') {
const url = new URL(`${env.WEB_ENDPOINT}/richHeader/${apiKey}/${userId}`);
// 防止群名片刷新慢
messageHeader && url.searchParams.set('hash', md5B64(messageHeader).substring(0, 10));
messageHeader && url.searchParams.set('hash', md5Hex(messageHeader).substring(0, 10));
return url.toString();
},

View File

@ -11,7 +11,7 @@ import {
segment,
Sendable,
} from '@icqqjs/icqq';
import { fetchFile, getBigFaceUrl, getImageUrlByMd5 } from '../utils/urls';
import { fetchFile, getBigFaceUrl, getImageUrlByMd5, isContainsUrl } from '../utils/urls';
import { ButtonLike, FileLike } from 'telegram/define';
import { getLogger, Logger } from 'log4js';
import path from 'path';
@ -389,7 +389,9 @@ export default class ForwardService {
else if (files.length) {
messageToSend.file = files;
}
else if (event.message_type === 'group' && (pair.flags | this.instance.flags) & flags.RICH_HEADER && env.WEB_ENDPOINT) {
else if (event.message_type === 'group' && (pair.flags | this.instance.flags) & flags.RICH_HEADER && env.WEB_ENDPOINT
// 当消息包含链接时不显示 RICH HEADER
&& !isContainsUrl(message)) {
// 没有文件时才能显示链接预览
richHeaderUsed = true;
// https://github.com/tdlib/td/blob/437c2d0c6e0ad104022d5ad86ddc8aedc41cb7a8/td/telegram/MessageContent.cpp#L2575

View File

@ -32,3 +32,7 @@ export async function fetchFile(url: string): Promise<Buffer> {
export function getAvatar(room: number | Friend | Group) {
return fetchFile(getAvatarUrl(room));
}
export function isContainsUrl(msg: string): boolean {
return msg.includes("https://") || msg.includes("http://")
}