From 7ab44dcb34fe04712d553b6b84e18c25ced6c7ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Tue, 2 Sep 2025 09:35:56 +0800 Subject: [PATCH] Refactor video thumbnail generation logic Moved video thumbnail generation to occur before custom thumbnail copying, ensuring fallback to default thumbnail only if video info retrieval fails. Also reordered rkeyManager URLs for consistency. --- src/core/apis/file.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/core/apis/file.ts b/src/core/apis/file.ts index 4725aaf8..7029508e 100644 --- a/src/core/apis/file.ts +++ b/src/core/apis/file.ts @@ -42,8 +42,8 @@ export class NTQQFileApi { this.context = context; this.core = core; this.rkeyManager = new RkeyManager([ - 'https://secret-service.bietiaop.com/rkeys', 'http://ss.xingzhige.com/music_card/rkey', + 'https://secret-service.bietiaop.com/rkeys', ], this.context.logger ); @@ -260,23 +260,22 @@ export class NTQQFileApi { const thumbDir = path.replace(`${pathLib.sep}Ori${pathLib.sep}`, `${pathLib.sep}Thumb${pathLib.sep}`); fs.mkdirSync(pathLib.dirname(thumbDir), { recursive: true }); const thumbPath = pathLib.join(pathLib.dirname(thumbDir), `${md5}_0.png`); + try { + videoInfo = await FFmpegService.getVideoInfo(filePath, thumbPath); + if (!fs.existsSync(thumbPath)) { + this.context.logger.logError('获取视频缩略图失败', new Error('缩略图不存在')); + throw new Error('获取视频缩略图失败'); + } + } catch (e) { + this.context.logger.logError('获取视频信息失败', e); + fs.writeFileSync(thumbPath, Buffer.from(defaultVideoThumbB64, 'base64')); + } if (_diyThumbPath) { try { await this.copyFile(_diyThumbPath, thumbPath); } catch (e) { this.context.logger.logError('复制自定义缩略图失败', e); } - } else { - try { - videoInfo = await FFmpegService.getVideoInfo(filePath, thumbPath); - if (!fs.existsSync(thumbPath)) { - this.context.logger.logError('获取视频缩略图失败', new Error('缩略图不存在')); - throw new Error('获取视频缩略图失败'); - } - } catch (e) { - this.context.logger.logError('获取视频信息失败', e); - fs.writeFileSync(thumbPath, Buffer.from(defaultVideoThumbB64, 'base64')); - } } context.deleteAfterSentFiles.push(thumbPath); const thumbSize = (await fsPromises.stat(thumbPath)).size;