15 files changed
+1284
-58
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
type MediaSubFileUpload,
|
||||
} from './pipeline';
|
||||
import { computeHashes, detectImageFormat, loadBinarySource } from './utils';
|
||||
import { ntImageUrlFromMsgInfo } from '../msg-push/helpers';
|
||||
|
||||
const moduleLog = createLogger('Highway.Image');
|
||||
|
||||
@@ -208,8 +209,16 @@ export async function uploadImageMsgInfo(
|
||||
});
|
||||
|
||||
const encoded = finalizeMediaMsgInfo(upload, pic);
|
||||
const imageUrl = ntImageUrlFromMsgInfo(upload.msgInfo?.msgInfoBody?.[0], isGroup);
|
||||
|
||||
if (!imageUrl) {
|
||||
throw new Error('image upload response is missing a download reference');
|
||||
}
|
||||
|
||||
// Retain successful upload metadata for the caller's self-sent history.
|
||||
Object.assign(element, {
|
||||
imageUrl,
|
||||
fileId: image.fileName,
|
||||
md5Hex: image.md5Hex,
|
||||
sha1Hex: image.sha1Hex,
|
||||
fileSize: image.fileSize,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { hexPreview } from '@snowluma/common/hex';
|
||||
import { inflateSync } from 'zlib';
|
||||
import type { IdentityService } from '../identity-service';
|
||||
import type { OperatorInfo } from '@snowluma/proto-defs/notify';
|
||||
import type { MsgInfoBody } from '@snowluma/proto-defs/element';
|
||||
|
||||
export const MAX_RICH_CARD_OUTPUT_BYTES = 4 * 1024 * 1024;
|
||||
export const MAX_RICH_CARD_MESSAGE_OUTPUT_BYTES = 8 * 1024 * 1024;
|
||||
@@ -51,6 +52,16 @@ export function ntImageUrlFromFileId(fileId: string, isGroup: boolean): string {
|
||||
return `https://multimedia.nt.qq.com.cn/download?appid=${appid}&fileid=${encodeURIComponent(fileId)}`;
|
||||
}
|
||||
|
||||
/** Upload receipts and received messages carry the same NT image reference. */
|
||||
export function ntImageUrlFromMsgInfo(body: MsgInfoBody | undefined, isGroup: boolean): string {
|
||||
if (body?.picture?.urlPath) {
|
||||
const { domain, urlPath, ext } = body.picture;
|
||||
return `https://${domain ?? 'multimedia.nt.qq.com.cn'}${urlPath}${ext?.originalParameter ?? ''}`;
|
||||
}
|
||||
|
||||
return ntImageUrlFromFileId(body?.index?.fileUuid ?? '', isGroup);
|
||||
}
|
||||
|
||||
export function decompressData(
|
||||
data: Uint8Array,
|
||||
maxOutputBytes = MAX_RICH_CARD_OUTPUT_BYTES,
|
||||
|
||||
@@ -33,7 +33,7 @@ import {
|
||||
makeImageUrl,
|
||||
MAX_RICH_CARD_MESSAGE_OUTPUT_BYTES,
|
||||
MAX_RICH_CARD_OUTPUT_BYTES,
|
||||
ntImageUrlFromFileId,
|
||||
ntImageUrlFromMsgInfo,
|
||||
} from './helpers';
|
||||
import { readXmlMsgAttributes } from './xml-card';
|
||||
|
||||
@@ -1096,27 +1096,9 @@ function convertElements(elems: ElemDecoded[], isGroup: boolean): MessageElement
|
||||
|
||||
if (bizType === 10 || bizType === 20) {
|
||||
// Image
|
||||
let url = '';
|
||||
|
||||
if (body.picture) {
|
||||
const domain = body.picture.domain ?? 'multimedia.nt.qq.com.cn';
|
||||
const path = body.picture.urlPath ?? '';
|
||||
|
||||
if (path) {
|
||||
url = 'https://' + domain + path;
|
||||
|
||||
if (body.picture.ext?.originalParameter) {
|
||||
url += body.picture.ext.originalParameter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let url = ntImageUrlFromMsgInfo(body, isGroup);
|
||||
let fileId = fi.fileName || idx.fileUuid || '';
|
||||
|
||||
if (!url && idx.fileUuid) {
|
||||
url = ntImageUrlFromFileId(idx.fileUuid, isGroup);
|
||||
}
|
||||
|
||||
const me: MessageElement = {
|
||||
type: 'image',
|
||||
fileId,
|
||||
|
||||
Reference in new issue
Block a user