mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
@@ -17,6 +17,8 @@ import fs from 'fs';
|
|||||||
import fsPromises from 'fs/promises';
|
import fsPromises from 'fs/promises';
|
||||||
import { InstanceContext, NapCatCore, SearchResultItem } from '@/core';
|
import { InstanceContext, NapCatCore, SearchResultItem } from '@/core';
|
||||||
import { fileTypeFromFile } from 'file-type';
|
import { fileTypeFromFile } from 'file-type';
|
||||||
|
import imageSize from 'image-size';
|
||||||
|
import { ISizeCalculationResult } from 'image-size/dist/types/interface';
|
||||||
import { RkeyManager } from '@/core/helper/rkey';
|
import { RkeyManager } from '@/core/helper/rkey';
|
||||||
import { calculateFileMD5 } from '@/common/file';
|
import { calculateFileMD5 } from '@/common/file';
|
||||||
import pathLib from 'node:path';
|
import pathLib from 'node:path';
|
||||||
@@ -26,7 +28,6 @@ import { SendMessageContext } from '@/onebot/api';
|
|||||||
import { getFileTypeForSendType } from '../helper/msg';
|
import { getFileTypeForSendType } from '../helper/msg';
|
||||||
import { FFmpegService } from '@/common/ffmpeg';
|
import { FFmpegService } from '@/common/ffmpeg';
|
||||||
import { rkeyDataType } from '../types/file';
|
import { rkeyDataType } from '../types/file';
|
||||||
import { imageSizeFromFile } from 'image-size/dist/fromFile'
|
|
||||||
|
|
||||||
export class NTQQFileApi {
|
export class NTQQFileApi {
|
||||||
context: InstanceContext;
|
context: InstanceContext;
|
||||||
@@ -136,7 +137,7 @@ export class NTQQFileApi {
|
|||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw new Error('文件异常,大小为0');
|
throw new Error('文件异常,大小为0');
|
||||||
}
|
}
|
||||||
const imageSize = await imageSizeFromFile(picPath);
|
const imageSize = await this.core.apis.FileApi.getImageSize(picPath);
|
||||||
context.deleteAfterSentFiles.push(path);
|
context.deleteAfterSentFiles.push(path);
|
||||||
return {
|
return {
|
||||||
elementType: ElementType.PIC,
|
elementType: ElementType.PIC,
|
||||||
@@ -355,6 +356,20 @@ export class NTQQFileApi {
|
|||||||
return completeRetData.filePath;
|
return completeRetData.filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getImageSize(filePath: string): Promise<ISizeCalculationResult> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
imageSize(filePath, (err: Error | null, dimensions) => {
|
||||||
|
if (err) {
|
||||||
|
reject(new Error(err.message));
|
||||||
|
} else if (!dimensions) {
|
||||||
|
reject(new Error('获取图片尺寸失败'));
|
||||||
|
} else {
|
||||||
|
resolve(dimensions);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async searchForFile(keys: string[]): Promise<SearchResultItem | undefined> {
|
async searchForFile(keys: string[]): Promise<SearchResultItem | undefined> {
|
||||||
const randomResultId = 100000 + Math.floor(Math.random() * 10000);
|
const randomResultId = 100000 + Math.floor(Math.random() * 10000);
|
||||||
let searchId = 0;
|
let searchId = 0;
|
||||||
|
Reference in New Issue
Block a user