mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
fix: image size
This commit is contained in:
@@ -4,10 +4,10 @@ import { execFile } from 'child_process';
|
|||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import type { VideoInfo } from './video';
|
import type { VideoInfo } from './video';
|
||||||
import { fileTypeFromFile } from 'file-type';
|
import { fileTypeFromFile } from 'file-type';
|
||||||
import imageSize from 'image-size';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import { platform } from 'node:os';
|
import { platform } from 'node:os';
|
||||||
import { LogWrapper } from './log';
|
import { LogWrapper } from './log';
|
||||||
|
import { imageSizeFallBack } from '@/image-size';
|
||||||
const currentPath = dirname(fileURLToPath(import.meta.url));
|
const currentPath = dirname(fileURLToPath(import.meta.url));
|
||||||
const execFileAsync = promisify(execFile);
|
const execFileAsync = promisify(execFile);
|
||||||
const getFFmpegPath = (tool: string): string => {
|
const getFFmpegPath = (tool: string): string => {
|
||||||
@@ -157,7 +157,7 @@ export class FFmpegService {
|
|||||||
try {
|
try {
|
||||||
await this.extractThumbnail(videoPath, thumbnailPath);
|
await this.extractThumbnail(videoPath, thumbnailPath);
|
||||||
// 获取图片尺寸
|
// 获取图片尺寸
|
||||||
const dimensions = imageSize(thumbnailPath);
|
const dimensions = await imageSizeFallBack(thumbnailPath);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
format: fileType?.ext ?? 'mp4',
|
format: fileType?.ext ?? 'mp4',
|
||||||
|
@@ -17,8 +17,6 @@ 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';
|
||||||
@@ -30,6 +28,7 @@ import { FFmpegService } from '@/common/ffmpeg';
|
|||||||
import { rkeyDataType } from '../types/file';
|
import { rkeyDataType } from '../types/file';
|
||||||
import { NapProtoMsg } from '@napneko/nap-proto-core';
|
import { NapProtoMsg } from '@napneko/nap-proto-core';
|
||||||
import { FileId } from '../packet/transformer/proto/misc/fileid';
|
import { FileId } from '../packet/transformer/proto/misc/fileid';
|
||||||
|
import { imageSizeFallBack } from '@/image-size';
|
||||||
|
|
||||||
export class NTQQFileApi {
|
export class NTQQFileApi {
|
||||||
context: InstanceContext;
|
context: InstanceContext;
|
||||||
@@ -209,7 +208,7 @@ export class NTQQFileApi {
|
|||||||
if (fileSize === 0) {
|
if (fileSize === 0) {
|
||||||
throw new Error('文件异常,大小为0');
|
throw new Error('文件异常,大小为0');
|
||||||
}
|
}
|
||||||
const imageSize = await this.core.apis.FileApi.getImageSize(picPath);
|
const imageSize = await imageSizeFallBack(picPath);
|
||||||
context.deleteAfterSentFiles.push(path);
|
context.deleteAfterSentFiles.push(path);
|
||||||
return {
|
return {
|
||||||
elementType: ElementType.PIC,
|
elementType: ElementType.PIC,
|
||||||
@@ -437,19 +436,6 @@ 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);
|
||||||
|
Reference in New Issue
Block a user