mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Compare commits
26 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7c113d6e04 | ||
![]() |
a6f22167ff | ||
![]() |
d49e69735a | ||
![]() |
eca73eae18 | ||
![]() |
d3a34dfdf9 | ||
![]() |
623188d884 | ||
![]() |
f093f52792 | ||
![]() |
d53607a118 | ||
![]() |
5f637e064a | ||
![]() |
e4b21e94f5 | ||
![]() |
fc37288827 | ||
![]() |
dad7245a3a | ||
![]() |
4190831081 | ||
![]() |
c509a01d7d | ||
![]() |
6d259593fd | ||
![]() |
bd3e06520f | ||
![]() |
41dccd98a9 | ||
![]() |
54e6d5c3f2 | ||
![]() |
3f6249f39c | ||
![]() |
a888714629 | ||
![]() |
17ef3231df | ||
![]() |
cc30b51d58 | ||
![]() |
9d40eacc15 | ||
![]() |
a0415c5f4e | ||
![]() |
941978b578 | ||
![]() |
06538b9122 |
Binary file not shown.
@@ -4,7 +4,7 @@
|
||||
"name": "NapCatQQ",
|
||||
"slug": "NapCat.Framework",
|
||||
"description": "高性能的 OneBot 11 协议实现",
|
||||
"version": "4.7.20",
|
||||
"version": "4.7.29",
|
||||
"icon": "./logo.png",
|
||||
"authors": [
|
||||
{
|
||||
|
@@ -2,7 +2,7 @@
|
||||
"name": "napcat",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"version": "4.7.20",
|
||||
"version": "4.7.29",
|
||||
"scripts": {
|
||||
"build:universal": "npm run build:webui && vite build --mode universal || exit 1",
|
||||
"build:framework": "npm run build:webui && vite build --mode framework || exit 1",
|
||||
@@ -21,7 +21,6 @@
|
||||
"@eslint/compat": "^1.2.2",
|
||||
"@eslint/eslintrc": "^3.1.0",
|
||||
"@eslint/js": "^9.14.0",
|
||||
"@ffmpeg.wasm/main": "^0.13.1",
|
||||
"@homebridge/node-pty-prebuilt-multiarch": "^0.12.0-beta.5",
|
||||
"@log4js-node/log4js-api": "^1.0.2",
|
||||
"@napneko/nap-proto-core": "^0.0.4",
|
||||
@@ -63,7 +62,6 @@
|
||||
"zod": "^3.24.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ffmpeg.wasm/core-mt": "^0.13.2",
|
||||
"express": "^5.0.0",
|
||||
"silk-wasm": "^3.6.1",
|
||||
"ws": "^8.18.0"
|
||||
|
14
src/common/coerce.ts
Normal file
14
src/common/coerce.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { z } from 'zod';
|
||||
const boolean = () => z.preprocess(
|
||||
val => typeof val === 'string' && (val.toLowerCase() === 'false' || val === '0') ? false : Boolean(val),
|
||||
z.boolean()
|
||||
);
|
||||
const number = () => z.preprocess(
|
||||
val => typeof val !== 'number' ? Number(val) : val,
|
||||
z.number()
|
||||
);
|
||||
const string = () => z.preprocess(
|
||||
val => typeof val !== 'string' ? String(val) : val,
|
||||
z.string()
|
||||
);
|
||||
export const coerce = { boolean, number, string };
|
352
src/common/download-ffmpeg.ts
Normal file
352
src/common/download-ffmpeg.ts
Normal file
@@ -0,0 +1,352 @@
|
||||
// 更正导入语句
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as https from 'https';
|
||||
import * as os from 'os';
|
||||
import * as compressing from 'compressing'; // 修正导入方式
|
||||
import { pipeline } from 'stream/promises';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { LogWrapper } from './log';
|
||||
|
||||
const downloadOri = "https://github.com/BtbN/FFmpeg-Builds/releases/download/autobuild-2025-04-16-12-54/ffmpeg-n7.1.1-6-g48c0f071d4-win64-lgpl-7.1.zip"
|
||||
const urls = [
|
||||
"https://github.moeyy.xyz/" + downloadOri,
|
||||
"https://ghp.ci/" + downloadOri,
|
||||
"https://gh.api.99988866.xyz/" + downloadOri,
|
||||
downloadOri
|
||||
];
|
||||
|
||||
/**
|
||||
* 测试URL是否可用
|
||||
* @param url 待测试的URL
|
||||
* @returns 如果URL可访问返回true,否则返回false
|
||||
*/
|
||||
async function testUrl(url: string): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
const req = https.get(url, { timeout: 5000 }, (res) => {
|
||||
// 检查状态码是否表示成功
|
||||
const statusCode = res.statusCode || 0;
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
// 终止请求并返回true
|
||||
req.destroy();
|
||||
resolve(true);
|
||||
} else {
|
||||
req.destroy();
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
|
||||
req.on('error', () => {
|
||||
resolve(false);
|
||||
});
|
||||
|
||||
req.on('timeout', () => {
|
||||
req.destroy();
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找第一个可用的URL
|
||||
* @returns 返回第一个可用的URL,如果都不可用则返回null
|
||||
*/
|
||||
async function findAvailableUrl(): Promise<string | null> {
|
||||
for (const url of urls) {
|
||||
try {
|
||||
const available = await testUrl(url);
|
||||
if (available) {
|
||||
return url;
|
||||
}
|
||||
} catch (error) {
|
||||
// 忽略错误
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 下载文件
|
||||
* @param url 下载URL
|
||||
* @param destPath 目标保存路径
|
||||
* @returns 成功返回true,失败返回false
|
||||
*/
|
||||
async function downloadFile(url: string, destPath: string, progressCallback?: (percent: number) => void): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
const file = fs.createWriteStream(destPath);
|
||||
|
||||
const req = https.get(url, (res) => {
|
||||
const statusCode = res.statusCode || 0;
|
||||
|
||||
if (statusCode >= 200 && statusCode < 300) {
|
||||
// 获取文件总大小
|
||||
const totalSize = parseInt(res.headers['content-length'] || '0', 10);
|
||||
let downloadedSize = 0;
|
||||
let lastReportedPercent = -1; // 上次报告的百分比
|
||||
let lastReportTime = 0; // 上次报告的时间戳
|
||||
|
||||
// 如果有内容长度和进度回调,则添加数据监听
|
||||
if (totalSize > 0 && progressCallback) {
|
||||
// 初始报告 0%
|
||||
progressCallback(0);
|
||||
lastReportTime = Date.now();
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
downloadedSize += chunk.length;
|
||||
const currentPercent = Math.floor((downloadedSize / totalSize) * 100);
|
||||
const now = Date.now();
|
||||
|
||||
// 只在以下条件触发回调:
|
||||
// 1. 百分比变化至少为1%
|
||||
// 2. 距离上次报告至少500毫秒
|
||||
// 3. 确保报告100%完成
|
||||
if ((currentPercent !== lastReportedPercent &&
|
||||
(currentPercent - lastReportedPercent >= 1 || currentPercent === 100)) &&
|
||||
(now - lastReportTime >= 1000 || currentPercent === 100)) {
|
||||
|
||||
progressCallback(currentPercent);
|
||||
lastReportedPercent = currentPercent;
|
||||
lastReportTime = now;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
pipeline(res, file)
|
||||
.then(() => {
|
||||
// 确保最后报告100%
|
||||
if (progressCallback && lastReportedPercent !== 100) {
|
||||
progressCallback(100);
|
||||
}
|
||||
resolve(true);
|
||||
})
|
||||
.catch(() => resolve(false));
|
||||
} else {
|
||||
file.close();
|
||||
fs.unlink(destPath, () => { });
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
|
||||
req.on('error', () => {
|
||||
file.close();
|
||||
fs.unlink(destPath, () => { });
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 解压缩zip文件中的特定内容
|
||||
* 只解压bin目录中的文件到目标目录
|
||||
* @param zipPath 压缩文件路径
|
||||
* @param extractDir 解压目标路径
|
||||
*/
|
||||
async function extractBinDirectory(zipPath: string, extractDir: string): Promise<void> {
|
||||
try {
|
||||
// 确保目标目录存在
|
||||
if (!fs.existsSync(extractDir)) {
|
||||
fs.mkdirSync(extractDir, { recursive: true });
|
||||
}
|
||||
|
||||
// 解压文件
|
||||
const zipStream = new compressing.zip.UncompressStream({ source: zipPath });
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
// 监听条目事件
|
||||
zipStream.on('entry', (header, stream, next) => {
|
||||
// 获取文件路径
|
||||
const filePath = header.name;
|
||||
|
||||
// 匹配内层bin目录中的文件
|
||||
// 例如:ffmpeg-n7.1.1-6-g48c0f071d4-win64-lgpl-7.1/bin/ffmpeg.exe
|
||||
if (filePath.includes('/bin/') && filePath.endsWith('.exe')) {
|
||||
// 提取文件名
|
||||
const fileName = path.basename(filePath);
|
||||
const targetPath = path.join(extractDir, fileName);
|
||||
|
||||
// 创建写入流
|
||||
const writeStream = fs.createWriteStream(targetPath);
|
||||
|
||||
// 将流管道连接到文件
|
||||
stream.pipe(writeStream);
|
||||
|
||||
// 监听写入完成事件
|
||||
writeStream.on('finish', () => {
|
||||
next();
|
||||
});
|
||||
|
||||
writeStream.on('error', () => {
|
||||
next();
|
||||
});
|
||||
} else {
|
||||
// 跳过不需要的文件
|
||||
stream.resume();
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
zipStream.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
zipStream.on('finish', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载并设置FFmpeg
|
||||
* @param destDir 目标安装目录,默认为用户临时目录下的ffmpeg文件夹
|
||||
* @param tempDir 临时文件目录,默认为系统临时目录
|
||||
* @returns 返回ffmpeg可执行文件的路径,如果失败则返回null
|
||||
*/
|
||||
export async function downloadFFmpeg(
|
||||
destDir?: string,
|
||||
tempDir?: string,
|
||||
progressCallback?: (percent: number, stage: string) => void
|
||||
): Promise<string | null> {
|
||||
// 仅限Windows
|
||||
if (os.platform() !== 'win32') {
|
||||
return null;
|
||||
}
|
||||
|
||||
const destinationDir = destDir || path.join(os.tmpdir(), 'ffmpeg');
|
||||
const tempDirectory = tempDir || os.tmpdir();
|
||||
const zipFilePath = path.join(tempDirectory, 'ffmpeg.zip'); // 临时下载到指定临时目录
|
||||
const ffmpegExePath = path.join(destinationDir, 'ffmpeg.exe');
|
||||
|
||||
// 确保目录存在
|
||||
if (!fs.existsSync(destinationDir)) {
|
||||
fs.mkdirSync(destinationDir, { recursive: true });
|
||||
}
|
||||
|
||||
// 确保临时目录存在
|
||||
if (!fs.existsSync(tempDirectory)) {
|
||||
fs.mkdirSync(tempDirectory, { recursive: true });
|
||||
}
|
||||
|
||||
// 如果ffmpeg已经存在,直接返回路径
|
||||
if (fs.existsSync(ffmpegExePath)) {
|
||||
if (progressCallback) progressCallback(100, '已找到FFmpeg');
|
||||
return ffmpegExePath;
|
||||
}
|
||||
|
||||
// 查找可用URL
|
||||
if (progressCallback) progressCallback(0, '查找可用下载源');
|
||||
const availableUrl = await findAvailableUrl();
|
||||
if (!availableUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 下载文件
|
||||
if (progressCallback) progressCallback(5, '开始下载FFmpeg');
|
||||
const downloaded = await downloadFile(
|
||||
availableUrl,
|
||||
zipFilePath,
|
||||
(percent) => {
|
||||
// 下载占总进度的70%
|
||||
if (progressCallback) progressCallback(5 + Math.floor(percent * 0.7), '下载FFmpeg');
|
||||
}
|
||||
);
|
||||
|
||||
if (!downloaded) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 直接解压bin目录文件到目标目录
|
||||
if (progressCallback) progressCallback(75, '解压FFmpeg');
|
||||
await extractBinDirectory(zipFilePath, destinationDir);
|
||||
|
||||
// 清理下载文件
|
||||
if (progressCallback) progressCallback(95, '清理临时文件');
|
||||
try {
|
||||
fs.unlinkSync(zipFilePath);
|
||||
} catch (err) {
|
||||
// 忽略清理临时文件失败的错误
|
||||
}
|
||||
|
||||
// 检查ffmpeg.exe是否成功解压
|
||||
if (fs.existsSync(ffmpegExePath)) {
|
||||
if (progressCallback) progressCallback(100, 'FFmpeg安装完成');
|
||||
return ffmpegExePath;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查系统PATH环境变量中是否存在指定可执行文件
|
||||
* @param executable 可执行文件名
|
||||
* @returns 如果找到返回完整路径,否则返回null
|
||||
*/
|
||||
function findExecutableInPath(executable: string): string | null {
|
||||
// 仅适用于Windows系统
|
||||
if (os.platform() !== 'win32') return null;
|
||||
|
||||
// 获取PATH环境变量
|
||||
const pathEnv = process.env['PATH'] || '';
|
||||
const pathDirs = pathEnv.split(';');
|
||||
|
||||
// 检查每个目录
|
||||
for (const dir of pathDirs) {
|
||||
if (!dir) continue;
|
||||
try {
|
||||
const filePath = path.join(dir, executable);
|
||||
if (fs.existsSync(filePath)) {
|
||||
return filePath;
|
||||
}
|
||||
} catch (error) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function downloadFFmpegIfNotExists(log: LogWrapper) {
|
||||
// 仅限Windows
|
||||
if (os.platform() !== 'win32') {
|
||||
return {
|
||||
path: null,
|
||||
reset: false
|
||||
};
|
||||
}
|
||||
const ffmpegInPath = findExecutableInPath('ffmpeg.exe');
|
||||
const ffprobeInPath = findExecutableInPath('ffprobe.exe');
|
||||
|
||||
if (ffmpegInPath && ffprobeInPath) {
|
||||
const ffmpegDir = path.dirname(ffmpegInPath);
|
||||
return {
|
||||
path: ffmpegDir,
|
||||
reset: true
|
||||
};
|
||||
}
|
||||
|
||||
// 如果环境变量中没有,检查项目目录中是否存在
|
||||
const currentPath = path.dirname(fileURLToPath(import.meta.url));
|
||||
const ffmpeg_exist = fs.existsSync(path.join(currentPath, 'ffmpeg', 'ffmpeg.exe'));
|
||||
const ffprobe_exist = fs.existsSync(path.join(currentPath, 'ffmpeg', 'ffprobe.exe'));
|
||||
|
||||
if (!ffmpeg_exist || !ffprobe_exist) {
|
||||
await downloadFFmpeg(path.join(currentPath, 'ffmpeg'), path.join(currentPath, 'cache'), (percentage: number, message: string) => {
|
||||
log.log(`[FFmpeg] [Download] ${percentage}% - ${message}`);
|
||||
});
|
||||
return {
|
||||
path: path.join(currentPath, 'ffmpeg'),
|
||||
reset: true
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
path: path.join(currentPath, 'ffmpeg'),
|
||||
reset: true
|
||||
}
|
||||
}
|
@@ -1,308 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { FFmpeg } from '@ffmpeg.wasm/main';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { readFileSync, statSync, writeFileSync } from 'fs';
|
||||
import type { VideoInfo } from './video';
|
||||
import { fileTypeFromFile } from 'file-type';
|
||||
import imageSize from 'image-size';
|
||||
import { parentPort } from 'worker_threads';
|
||||
export function recvTask<T>(cb: (taskData: T) => Promise<unknown>) {
|
||||
parentPort?.on('message', async (taskData: T) => {
|
||||
try {
|
||||
let ret = await cb(taskData);
|
||||
parentPort?.postMessage(ret);
|
||||
} catch (error: unknown) {
|
||||
parentPort?.postMessage({ error: (error as Error).message });
|
||||
}
|
||||
});
|
||||
}
|
||||
export function sendLog(_log: string) {
|
||||
//parentPort?.postMessage({ log });
|
||||
}
|
||||
class FFmpegService {
|
||||
public static async extractThumbnail(videoPath: string, thumbnailPath: string): Promise<void> {
|
||||
const ffmpegInstance = await FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' });
|
||||
const videoFileName = `${randomUUID()}.mp4`;
|
||||
const outputFileName = `${randomUUID()}.jpg`;
|
||||
try {
|
||||
ffmpegInstance.fs.writeFile(videoFileName, readFileSync(videoPath));
|
||||
const code = await ffmpegInstance.run('-i', videoFileName, '-ss', '00:00:01.000', '-vframes', '1', outputFileName);
|
||||
if (code !== 0) {
|
||||
throw new Error('Error extracting thumbnail: FFmpeg process exited with code ' + code);
|
||||
}
|
||||
const thumbnail = ffmpegInstance.fs.readFile(outputFileName);
|
||||
writeFileSync(thumbnailPath, thumbnail);
|
||||
} catch (error) {
|
||||
console.error('Error extracting thumbnail:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
try {
|
||||
ffmpegInstance.fs.unlink(outputFileName);
|
||||
} catch (unlinkError) {
|
||||
console.error('Error unlinking output file:', unlinkError);
|
||||
}
|
||||
try {
|
||||
ffmpegInstance.fs.unlink(videoFileName);
|
||||
} catch (unlinkError) {
|
||||
console.error('Error unlinking video file:', unlinkError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async convertFile(inputFile: string, outputFile: string, format: string): Promise<void> {
|
||||
const ffmpegInstance = await FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' });
|
||||
const inputFileName = `${randomUUID()}.pcm`;
|
||||
const outputFileName = `${randomUUID()}.${format}`;
|
||||
try {
|
||||
ffmpegInstance.fs.writeFile(inputFileName, readFileSync(inputFile));
|
||||
const params = format === 'amr'
|
||||
? ['-f', 's16le', '-ar', '24000', '-ac', '1', '-i', inputFileName, '-ar', '8000', '-b:a', '12.2k', outputFileName]
|
||||
: ['-f', 's16le', '-ar', '24000', '-ac', '1', '-i', inputFileName, outputFileName];
|
||||
const code = await ffmpegInstance.run(...params);
|
||||
if (code !== 0) {
|
||||
throw new Error('Error extracting thumbnail: FFmpeg process exited with code ' + code);
|
||||
}
|
||||
const outputData = ffmpegInstance.fs.readFile(outputFileName);
|
||||
writeFileSync(outputFile, outputData);
|
||||
} catch (error) {
|
||||
console.error('Error converting file:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
try {
|
||||
ffmpegInstance.fs.unlink(outputFileName);
|
||||
} catch (unlinkError) {
|
||||
console.error('Error unlinking output file:', unlinkError);
|
||||
}
|
||||
try {
|
||||
ffmpegInstance.fs.unlink(inputFileName);
|
||||
} catch (unlinkError) {
|
||||
console.error('Error unlinking input file:', unlinkError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static async convert(filePath: string, pcmPath: string): Promise<Buffer> {
|
||||
const ffmpegInstance = await FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' });
|
||||
const inputFileName = `${randomUUID()}.input`;
|
||||
const outputFileName = `${randomUUID()}.pcm`;
|
||||
try {
|
||||
ffmpegInstance.fs.writeFile(inputFileName, readFileSync(filePath));
|
||||
const params = ['-y', '-i', inputFileName, '-ar', '24000', '-ac', '1', '-f', 's16le', outputFileName];
|
||||
const code = await ffmpegInstance.run(...params);
|
||||
if (code !== 0) {
|
||||
throw new Error('FFmpeg process exited with code ' + code);
|
||||
}
|
||||
const outputData = ffmpegInstance.fs.readFile(outputFileName);
|
||||
writeFileSync(pcmPath, outputData);
|
||||
return Buffer.from(outputData);
|
||||
} catch (error: any) {
|
||||
throw new Error('FFmpeg处理转换出错: ' + error.message);
|
||||
} finally {
|
||||
try {
|
||||
ffmpegInstance.fs.unlink(outputFileName);
|
||||
} catch (unlinkError) {
|
||||
console.error('Error unlinking output file:', unlinkError);
|
||||
}
|
||||
try {
|
||||
ffmpegInstance.fs.unlink(inputFileName);
|
||||
} catch (unlinkError) {
|
||||
console.error('Error unlinking output file:', unlinkError);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static async getVideoInfo(videoPath: string, thumbnailPath: string): Promise<VideoInfo> {
|
||||
const startTime = Date.now();
|
||||
sendLog(`开始获取视频信息: ${videoPath}`);
|
||||
|
||||
// 创建一个超时包装函数
|
||||
const withTimeout = <T>(promise: Promise<T>, timeoutMs: number, taskName: string): Promise<T> => {
|
||||
return Promise.race([
|
||||
promise,
|
||||
new Promise<T>((_, reject) => {
|
||||
setTimeout(() => reject(new Error(`任务超时: ${taskName} (${timeoutMs}ms)`)), timeoutMs);
|
||||
})
|
||||
]);
|
||||
};
|
||||
|
||||
// 并行执行多个任务
|
||||
const [fileInfo, durationInfo] = await Promise.all([
|
||||
// 任务1: 获取文件信息和提取缩略图
|
||||
(async () => {
|
||||
sendLog('开始任务1: 获取文件信息和提取缩略图');
|
||||
|
||||
// 获取文件信息 (并行)
|
||||
const fileInfoStartTime = Date.now();
|
||||
const [fileType, fileSize] = await Promise.all([
|
||||
withTimeout(fileTypeFromFile(videoPath), 10000, '获取文件类型')
|
||||
.then(result => {
|
||||
sendLog(`获取文件类型完成,耗时: ${Date.now() - fileInfoStartTime}ms`);
|
||||
return result;
|
||||
}),
|
||||
(async () => {
|
||||
const result = statSync(videoPath).size;
|
||||
sendLog(`获取文件大小完成,耗时: ${Date.now() - fileInfoStartTime}ms`);
|
||||
return result;
|
||||
})()
|
||||
]);
|
||||
|
||||
// 直接实现缩略图提取 (不调用extractThumbnail方法)
|
||||
const thumbStartTime = Date.now();
|
||||
sendLog('开始提取缩略图');
|
||||
|
||||
const ffmpegInstance = await withTimeout(
|
||||
FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' }),
|
||||
15000,
|
||||
'创建FFmpeg实例(缩略图)'
|
||||
);
|
||||
|
||||
const videoFileName = `${randomUUID()}.mp4`;
|
||||
const outputFileName = `${randomUUID()}.jpg`;
|
||||
|
||||
try {
|
||||
// 写入视频文件到FFmpeg
|
||||
const writeFileStartTime = Date.now();
|
||||
ffmpegInstance.fs.writeFile(videoFileName, readFileSync(videoPath));
|
||||
sendLog(`写入视频文件到FFmpeg完成,耗时: ${Date.now() - writeFileStartTime}ms`);
|
||||
|
||||
// 提取缩略图
|
||||
const extractStartTime = Date.now();
|
||||
const code = await withTimeout(
|
||||
ffmpegInstance.run('-i', videoFileName, '-ss', '00:00:01.000', '-vframes', '1', outputFileName),
|
||||
30000,
|
||||
'提取缩略图'
|
||||
);
|
||||
sendLog(`FFmpeg提取缩略图命令执行完成,耗时: ${Date.now() - extractStartTime}ms`);
|
||||
|
||||
if (code !== 0) {
|
||||
throw new Error('Error extracting thumbnail: FFmpeg process exited with code ' + code);
|
||||
}
|
||||
|
||||
// 读取并保存缩略图
|
||||
const saveStartTime = Date.now();
|
||||
const thumbnail = ffmpegInstance.fs.readFile(outputFileName);
|
||||
writeFileSync(thumbnailPath, thumbnail);
|
||||
sendLog(`读取并保存缩略图完成,耗时: ${Date.now() - saveStartTime}ms`);
|
||||
|
||||
// 获取缩略图尺寸
|
||||
const imageSizeStartTime = Date.now();
|
||||
const image = imageSize(thumbnailPath);
|
||||
sendLog(`获取缩略图尺寸完成,耗时: ${Date.now() - imageSizeStartTime}ms`);
|
||||
|
||||
sendLog(`提取缩略图完成,总耗时: ${Date.now() - thumbStartTime}ms`);
|
||||
|
||||
return {
|
||||
format: fileType?.ext ?? 'mp4',
|
||||
size: fileSize,
|
||||
width: image.width ?? 100,
|
||||
height: image.height ?? 100
|
||||
};
|
||||
} finally {
|
||||
// 清理资源
|
||||
try {
|
||||
ffmpegInstance.fs.unlink(outputFileName);
|
||||
} catch (error) {
|
||||
sendLog(`清理输出文件失败: ${(error as Error).message}`);
|
||||
}
|
||||
|
||||
try {
|
||||
ffmpegInstance.fs.unlink(videoFileName);
|
||||
} catch (error) {
|
||||
sendLog(`清理视频文件失败: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
})(),
|
||||
|
||||
// 任务2: 获取视频时长
|
||||
(async () => {
|
||||
const task2StartTime = Date.now();
|
||||
sendLog('开始任务2: 获取视频时长');
|
||||
|
||||
// 创建FFmpeg实例
|
||||
const ffmpegCreateStartTime = Date.now();
|
||||
const ffmpegInstance = await withTimeout(
|
||||
FFmpeg.create({ core: '@ffmpeg.wasm/core-mt' }),
|
||||
15000,
|
||||
'创建FFmpeg实例(时长)'
|
||||
);
|
||||
sendLog(`创建FFmpeg实例完成,耗时: ${Date.now() - ffmpegCreateStartTime}ms`);
|
||||
|
||||
const inputFileName = `${randomUUID()}.mp4`;
|
||||
|
||||
try {
|
||||
// 写入文件
|
||||
const writeStartTime = Date.now();
|
||||
ffmpegInstance.fs.writeFile(inputFileName, readFileSync(videoPath));
|
||||
sendLog(`写入文件到FFmpeg完成,耗时: ${Date.now() - writeStartTime}ms`);
|
||||
|
||||
ffmpegInstance.setLogging(true);
|
||||
let duration = 60; // 默认值
|
||||
|
||||
ffmpegInstance.setLogger((_level, ...msg) => {
|
||||
const message = msg.join(' ');
|
||||
const durationMatch = message.match(/Duration: (\d+):(\d+):(\d+\.\d+)/);
|
||||
if (durationMatch) {
|
||||
const hours = parseInt(durationMatch[1] ?? '0', 10);
|
||||
const minutes = parseInt(durationMatch[2] ?? '0', 10);
|
||||
const seconds = parseFloat(durationMatch[3] ?? '0');
|
||||
duration = hours * 3600 + minutes * 60 + seconds;
|
||||
}
|
||||
});
|
||||
|
||||
// 执行FFmpeg
|
||||
const runStartTime = Date.now();
|
||||
await withTimeout(
|
||||
ffmpegInstance.run('-i', inputFileName),
|
||||
20000,
|
||||
'获取视频时长'
|
||||
);
|
||||
sendLog(`执行FFmpeg命令完成,耗时: ${Date.now() - runStartTime}ms`);
|
||||
|
||||
sendLog(`任务2(获取视频时长)完成,总耗时: ${Date.now() - task2StartTime}ms`);
|
||||
return { time: duration };
|
||||
} finally {
|
||||
try {
|
||||
ffmpegInstance.fs.unlink(inputFileName);
|
||||
} catch (error) {
|
||||
sendLog(`清理输入文件失败: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
})()
|
||||
]);
|
||||
|
||||
// 合并结果并返回
|
||||
const totalDuration = Date.now() - startTime;
|
||||
sendLog(`获取视频信息完成,总耗时: ${totalDuration}ms`);
|
||||
|
||||
return {
|
||||
width: fileInfo.width,
|
||||
height: fileInfo.height,
|
||||
time: durationInfo.time,
|
||||
format: fileInfo.format,
|
||||
size: fileInfo.size,
|
||||
filePath: videoPath
|
||||
};
|
||||
}
|
||||
}
|
||||
type FFmpegMethod = 'extractThumbnail' | 'convertFile' | 'convert' | 'getVideoInfo';
|
||||
|
||||
interface FFmpegTask {
|
||||
method: FFmpegMethod;
|
||||
args: any[];
|
||||
}
|
||||
export default async function handleFFmpegTask({ method, args }: FFmpegTask): Promise<any> {
|
||||
switch (method) {
|
||||
case 'extractThumbnail':
|
||||
return await FFmpegService.extractThumbnail(...args as [string, string]);
|
||||
case 'convertFile':
|
||||
return await FFmpegService.convertFile(...args as [string, string, string]);
|
||||
case 'convert':
|
||||
return await FFmpegService.convert(...args as [string, string]);
|
||||
case 'getVideoInfo':
|
||||
return await FFmpegService.getVideoInfo(...args as [string, string]);
|
||||
default:
|
||||
throw new Error(`Unknown method: ${method}`);
|
||||
}
|
||||
}
|
||||
recvTask<FFmpegTask>(async ({ method, args }: FFmpegTask) => {
|
||||
return await handleFFmpegTask({ method, args });
|
||||
});
|
@@ -1,36 +1,195 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { VideoInfo } from './video';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { runTask } from './worker';
|
||||
|
||||
type EncodeArgs = {
|
||||
method: 'extractThumbnail' | 'convertFile' | 'convert' | 'getVideoInfo';
|
||||
args: any[];
|
||||
import { readFileSync, statSync, existsSync, mkdirSync } from 'fs';
|
||||
import path, { dirname } from 'path';
|
||||
import { execFile } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import type { VideoInfo } from './video';
|
||||
import { fileTypeFromFile } from 'file-type';
|
||||
import imageSize from 'image-size';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { platform } from 'node:os';
|
||||
import { LogWrapper } from './log';
|
||||
const currentPath = dirname(fileURLToPath(import.meta.url));
|
||||
const execFileAsync = promisify(execFile);
|
||||
const getFFmpegPath = (tool: string): string => {
|
||||
if (process.platform === 'win32') {
|
||||
const exeName = `${tool}.exe`;
|
||||
const isLocalExeExists = existsSync(path.join(currentPath, 'ffmpeg', exeName));
|
||||
return isLocalExeExists ? path.join(currentPath, 'ffmpeg', exeName) : exeName;
|
||||
}
|
||||
return tool;
|
||||
};
|
||||
|
||||
type EncodeResult = any;
|
||||
|
||||
function getWorkerPath() {
|
||||
return path.join(path.dirname(fileURLToPath(import.meta.url)), './ffmpeg-worker.mjs');
|
||||
}
|
||||
|
||||
export let FFMPEG_CMD = getFFmpegPath('ffmpeg');
|
||||
export let FFPROBE_CMD = getFFmpegPath('ffprobe');
|
||||
export class FFmpegService {
|
||||
// 确保目标目录存在
|
||||
public static setFfmpegPath(ffmpegPath: string,logger:LogWrapper): void {
|
||||
if (platform() === 'win32') {
|
||||
FFMPEG_CMD = path.join(ffmpegPath, 'ffmpeg.exe');
|
||||
FFPROBE_CMD = path.join(ffmpegPath, 'ffprobe.exe');
|
||||
logger.log('[Check] ffmpeg:', FFMPEG_CMD);
|
||||
logger.log('[Check] ffprobe:', FFPROBE_CMD);
|
||||
}
|
||||
}
|
||||
private static ensureDirExists(filePath: string): void {
|
||||
const dir = dirname(filePath);
|
||||
if (!existsSync(dir)) {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
public static async extractThumbnail(videoPath: string, thumbnailPath: string): Promise<void> {
|
||||
await runTask<EncodeArgs, EncodeResult>(getWorkerPath(), { method: 'extractThumbnail', args: [videoPath, thumbnailPath] });
|
||||
try {
|
||||
this.ensureDirExists(thumbnailPath);
|
||||
|
||||
const { stderr } = await execFileAsync(FFMPEG_CMD, [
|
||||
'-i', videoPath,
|
||||
'-ss', '00:00:01.000',
|
||||
'-vframes', '1',
|
||||
'-y', // 覆盖输出文件
|
||||
thumbnailPath
|
||||
]);
|
||||
|
||||
if (!existsSync(thumbnailPath)) {
|
||||
throw new Error(`提取缩略图失败,输出文件不存在: ${stderr}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error extracting thumbnail:', error);
|
||||
throw new Error(`提取缩略图失败: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
public static async convertFile(inputFile: string, outputFile: string, format: string): Promise<void> {
|
||||
await runTask<EncodeArgs, EncodeResult>(getWorkerPath(), { method: 'convertFile', args: [inputFile, outputFile, format] });
|
||||
try {
|
||||
this.ensureDirExists(outputFile);
|
||||
|
||||
const params = format === 'amr'
|
||||
? [
|
||||
'-f', 's16le',
|
||||
'-ar', '24000',
|
||||
'-ac', '1',
|
||||
'-i', inputFile,
|
||||
'-ar', '8000',
|
||||
'-b:a', '12.2k',
|
||||
'-y',
|
||||
outputFile
|
||||
]
|
||||
: [
|
||||
'-f', 's16le',
|
||||
'-ar', '24000',
|
||||
'-ac', '1',
|
||||
'-i', inputFile,
|
||||
'-y',
|
||||
outputFile
|
||||
];
|
||||
|
||||
await execFileAsync(FFMPEG_CMD, params);
|
||||
|
||||
if (!existsSync(outputFile)) {
|
||||
throw new Error('转换失败,输出文件不存在');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error converting file:', error);
|
||||
throw new Error(`文件转换失败: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
public static async convert(filePath: string, pcmPath: string): Promise<Buffer> {
|
||||
const result = await runTask<EncodeArgs, EncodeResult>(getWorkerPath(), { method: 'convert', args: [filePath, pcmPath] });
|
||||
return result;
|
||||
try {
|
||||
this.ensureDirExists(pcmPath);
|
||||
|
||||
await execFileAsync(FFMPEG_CMD, [
|
||||
'-y',
|
||||
'-i', filePath,
|
||||
'-ar', '24000',
|
||||
'-ac', '1',
|
||||
'-f', 's16le',
|
||||
pcmPath
|
||||
]);
|
||||
|
||||
if (!existsSync(pcmPath)) {
|
||||
throw new Error('转换PCM失败,输出文件不存在');
|
||||
}
|
||||
|
||||
return readFileSync(pcmPath);
|
||||
} catch (error: any) {
|
||||
throw new Error(`FFmpeg处理转换出错: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
public static async getVideoInfo(videoPath: string, thumbnailPath: string): Promise<VideoInfo> {
|
||||
const result = await runTask<EncodeArgs, EncodeResult>(getWorkerPath(), { method: 'getVideoInfo', args: [videoPath, thumbnailPath] });
|
||||
return result;
|
||||
try {
|
||||
// 并行执行获取文件信息和提取缩略图
|
||||
const [fileInfo, duration] = await Promise.all([
|
||||
this.getFileInfo(videoPath, thumbnailPath),
|
||||
this.getVideoDuration(videoPath)
|
||||
]);
|
||||
|
||||
const result: VideoInfo = {
|
||||
width: fileInfo.width,
|
||||
height: fileInfo.height,
|
||||
time: duration,
|
||||
format: fileInfo.format,
|
||||
size: fileInfo.size,
|
||||
filePath: videoPath
|
||||
};
|
||||
return result;
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async getFileInfo(videoPath: string, thumbnailPath: string): Promise<{
|
||||
format: string,
|
||||
size: number,
|
||||
width: number,
|
||||
height: number
|
||||
}> {
|
||||
|
||||
// 获取文件大小和类型
|
||||
const [fileType, fileSize] = await Promise.all([
|
||||
fileTypeFromFile(videoPath).catch(() => {
|
||||
return null;
|
||||
}),
|
||||
Promise.resolve(statSync(videoPath).size)
|
||||
]);
|
||||
|
||||
|
||||
try {
|
||||
await this.extractThumbnail(videoPath, thumbnailPath);
|
||||
// 获取图片尺寸
|
||||
const dimensions = imageSize(thumbnailPath);
|
||||
|
||||
return {
|
||||
format: fileType?.ext ?? 'mp4',
|
||||
size: fileSize,
|
||||
width: dimensions.width ?? 100,
|
||||
height: dimensions.height ?? 100
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
format: fileType?.ext ?? 'mp4',
|
||||
size: fileSize,
|
||||
width: 100,
|
||||
height: 100
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static async getVideoDuration(videoPath: string): Promise<number> {
|
||||
try {
|
||||
// 使用FFprobe获取时长
|
||||
const { stdout } = await execFileAsync(FFPROBE_CMD, [
|
||||
'-v', 'error',
|
||||
'-show_entries', 'format=duration',
|
||||
'-of', 'default=noprint_wrappers=1:nokey=1',
|
||||
videoPath
|
||||
]);
|
||||
|
||||
const duration = parseFloat(stdout.trim());
|
||||
|
||||
return isNaN(duration) ? 60 : duration;
|
||||
} catch (error) {
|
||||
return 60; // 默认时长
|
||||
}
|
||||
}
|
||||
}
|
@@ -1 +1 @@
|
||||
export const napCatVersion = '4.7.20';
|
||||
export const napCatVersion = '4.7.29';
|
||||
|
4
src/core/external/appid.json
vendored
4
src/core/external/appid.json
vendored
@@ -242,5 +242,9 @@
|
||||
"3.2.17-34231": {
|
||||
"appid": 537279245,
|
||||
"qua": "V1_LNX_NQ_3.2.17_34231_GW_B"
|
||||
},
|
||||
"9.9.19-34362": {
|
||||
"appid": 537279260,
|
||||
"qua": "V1_WIN_NQ_9.9.19_34362_GW_B"
|
||||
}
|
||||
}
|
4
src/core/external/offset.json
vendored
4
src/core/external/offset.json
vendored
@@ -326,5 +326,9 @@
|
||||
"3.2.17-34231-arm64": {
|
||||
"send": "770CDC0",
|
||||
"recv": "77106F0"
|
||||
},
|
||||
"9.9.19-34362-x64":{
|
||||
"send": "3BD80D0",
|
||||
"recv": "3BDC8D0"
|
||||
}
|
||||
}
|
@@ -1,15 +1,16 @@
|
||||
import { ConfigBase } from '@/common/config-base';
|
||||
import { NapCatCore } from '@/core';
|
||||
import { coerce } from '@/common/coerce';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const NapcatConfigSchema = z.object({
|
||||
fileLog: z.coerce.boolean().default(false),
|
||||
consoleLog: z.coerce.boolean().default(true),
|
||||
fileLogLevel: z.coerce.string().default('debug'),
|
||||
consoleLogLevel: z.coerce.string().default('info'),
|
||||
packetBackend: z.coerce.string().default('auto'),
|
||||
packetServer: z.coerce.string().default(''),
|
||||
o3HookMode: z.coerce.number().default(0),
|
||||
fileLog: coerce.boolean().default(false),
|
||||
consoleLog: coerce.boolean().default(true),
|
||||
fileLogLevel: coerce.string().default('debug'),
|
||||
consoleLogLevel: coerce.string().default('info'),
|
||||
packetBackend: coerce.string().default('auto'),
|
||||
packetServer: coerce.string().default(''),
|
||||
o3HookMode: coerce.number().default(0),
|
||||
});
|
||||
|
||||
export type NapcatConfig = z.infer<typeof NapcatConfigSchema>;
|
||||
|
@@ -9,6 +9,8 @@ import { NodeIKernelLoginService } from '@/core/services';
|
||||
import { NodeIQQNTWrapperSession, WrapperNodeApi } from '@/core/wrapper';
|
||||
import { InitWebUi, WebUiConfig, webUiRuntimePort } from '@/webui';
|
||||
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||
import { downloadFFmpegIfNotExists } from '@/common/download-ffmpeg';
|
||||
import { FFmpegService } from '@/common/ffmpeg';
|
||||
|
||||
//Framework ES入口文件
|
||||
export async function getWebUiUrl() {
|
||||
@@ -36,6 +38,13 @@ export async function NCoreInitFramework(
|
||||
const logger = new LogWrapper(pathWrapper.logsPath);
|
||||
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
||||
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
||||
downloadFFmpegIfNotExists(logger).then(({ path, reset }) => {
|
||||
if (reset && path) {
|
||||
FFmpegService.setFfmpegPath(path,logger);
|
||||
}
|
||||
}).catch(e => {
|
||||
logger.logError('[Ffmpeg] Error:', e);
|
||||
});
|
||||
//直到登录成功后,执行下一步
|
||||
const selfInfo = await new Promise<SelfInfo>((resolveSelfInfo) => {
|
||||
const loginListener = new NodeIKernelLoginListener();
|
||||
|
Binary file not shown.
Binary file not shown.
@@ -1,13 +1,14 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OneBotAction } from '../OneBotAction';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.coerce.string(),
|
||||
bot_appid: z.coerce.string(),
|
||||
button_id: z.coerce.string().default(''),
|
||||
callback_data: z.coerce.string().default(''),
|
||||
msg_seq: z.coerce.string().default('10086'),
|
||||
group_id: coerce.string(),
|
||||
bot_appid: coerce.string(),
|
||||
button_id: coerce.string().default(''),
|
||||
callback_data: coerce.string().default(''),
|
||||
msg_seq: coerce.string().default('10086'),
|
||||
});
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
rawData: z.coerce.string(),
|
||||
brief: z.coerce.string(),
|
||||
rawData: coerce.string(),
|
||||
brief: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { z } from 'zod';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
count: z.coerce.number().default(48),
|
||||
count: coerce.number().default(48),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,12 +3,12 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { type NTQQMsgApi } from '@/core/apis';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
message_id: z.coerce.string(),
|
||||
emojiId: z.coerce.string(),
|
||||
emojiType: z.coerce.string(),
|
||||
count: z.coerce.number().default(20),
|
||||
message_id: coerce.string(),
|
||||
emojiId: coerce.string(),
|
||||
emojiType: coerce.string(),
|
||||
count: coerce.number().default(20),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,10 +2,10 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { AIVoiceChatType } from '@/core/packet/entities/aiChat';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.coerce.string(),
|
||||
chat_type: z.coerce.number().default(1),
|
||||
group_id: coerce.string(),
|
||||
chat_type: coerce.number().default(1),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,10 +2,10 @@ import { type NTQQCollectionApi } from '@/core/apis/collection';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
category: z.coerce.number(),
|
||||
count: z.coerce.number().default(1),
|
||||
category: coerce.number(),
|
||||
count: coerce.number().default(1),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,34 +3,34 @@ import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { MiniAppInfo, MiniAppInfoHelper } from '@/core/packet/utils/helper/miniAppHelper';
|
||||
import { MiniAppData, MiniAppRawData, MiniAppReqCustomParams, MiniAppReqParams } from '@/core/packet/entities/miniApp';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.union([
|
||||
z.object({
|
||||
type: z.union([z.literal('bili'), z.literal('weibo')]),
|
||||
title: z.coerce.string(),
|
||||
desc: z.coerce.string(),
|
||||
picUrl: z.coerce.string(),
|
||||
jumpUrl: z.coerce.string(),
|
||||
webUrl: z.coerce.string().optional(),
|
||||
rawArkData: z.coerce.string().optional()
|
||||
title: coerce.string(),
|
||||
desc: coerce.string(),
|
||||
picUrl: coerce.string(),
|
||||
jumpUrl: coerce.string(),
|
||||
webUrl: coerce.string().optional(),
|
||||
rawArkData: coerce.string().optional()
|
||||
}),
|
||||
z.object({
|
||||
title: z.coerce.string(),
|
||||
desc: z.coerce.string(),
|
||||
picUrl: z.coerce.string(),
|
||||
jumpUrl: z.coerce.string(),
|
||||
iconUrl: z.coerce.string(),
|
||||
webUrl: z.coerce.string().optional(),
|
||||
appId: z.coerce.string(),
|
||||
scene: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
templateType: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
businessType: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
verType: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
shareType: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
versionId: z.coerce.string(),
|
||||
sdkId: z.coerce.string(),
|
||||
withShareTicket: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
rawArkData: z.coerce.string().optional()
|
||||
title: coerce.string(),
|
||||
desc: coerce.string(),
|
||||
picUrl: coerce.string(),
|
||||
jumpUrl: coerce.string(),
|
||||
iconUrl: coerce.string(),
|
||||
webUrl: coerce.string().optional(),
|
||||
appId: coerce.string(),
|
||||
scene: z.union([coerce.number(), coerce.string()]),
|
||||
templateType: z.union([coerce.number(), coerce.string()]),
|
||||
businessType: z.union([coerce.number(), coerce.string()]),
|
||||
verType: z.union([coerce.number(), coerce.string()]),
|
||||
shareType: z.union([coerce.number(), coerce.string()]),
|
||||
versionId: coerce.string(),
|
||||
sdkId: coerce.string(),
|
||||
withShareTicket: z.union([coerce.number(), coerce.string()]),
|
||||
rawArkData: coerce.string().optional()
|
||||
})
|
||||
]);
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,11 @@ import { NTVoteInfo } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
user_id: z.coerce.string().optional(),
|
||||
start: z.coerce.number().default(0),
|
||||
count: z.coerce.number().default(10),
|
||||
user_id: coerce.string().optional(),
|
||||
start: coerce.number().default(0),
|
||||
count: coerce.number().default(10),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
user_id: z.coerce.number(),
|
||||
user_id: coerce.number(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,12 +2,12 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
file_id: z.coerce.string(),
|
||||
current_parent_directory: z.coerce.string(),
|
||||
target_parent_directory: z.coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
file_id: coerce.string(),
|
||||
current_parent_directory: coerce.string(),
|
||||
target_parent_directory: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -4,9 +4,9 @@ import { checkFileExist, uriToLocalFile } from '@/common/file';
|
||||
import fs from 'fs';
|
||||
import { z } from 'zod';
|
||||
import { GeneralCallResultStatus } from '@/core';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
image: z.coerce.string(),
|
||||
image: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,12 +2,12 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
file_id: z.coerce.string(),
|
||||
current_parent_directory: z.coerce.string(),
|
||||
new_name: z.coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
file_id: coerce.string(),
|
||||
current_parent_directory: coerce.string(),
|
||||
new_name: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,12 @@ import { PacketHexStr } from '@/core/packet/transformer/base';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
cmd: z.coerce.string(),
|
||||
data: z.coerce.string(),
|
||||
rsp: z.coerce.boolean().default(true),
|
||||
cmd: coerce.string(),
|
||||
data: coerce.string(),
|
||||
rsp: coerce.boolean().default(true),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
face_id: z.union([z.coerce.number(), z.coerce.string()]),// 参考 face_config.json 的 QSid
|
||||
face_type: z.union([z.coerce.number(), z.coerce.string()]).default('1'),
|
||||
wording: z.coerce.string().default(' '),
|
||||
face_id: coerce.string(),// 参考 face_config.json 的 QSid
|
||||
face_type: coerce.string().default('1'),
|
||||
wording: coerce.string().default(' '),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.coerce.string(),
|
||||
remark: z.coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
remark: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,10 +2,10 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { ChatType } from '@/core';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
event_type: z.coerce.number(),
|
||||
user_id: coerce.string(),
|
||||
event_type: coerce.number(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
longNick: z.coerce.string(),
|
||||
longNick: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
status: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
ext_status: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
battery_status: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
status: coerce.number(),
|
||||
ext_status: coerce.number(),
|
||||
battery_status: coerce.number(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,9 +3,9 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import fs from 'node:fs/promises';
|
||||
import { checkFileExist, uriToLocalFile } from '@/common/file';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
file: z.coerce.string(),
|
||||
file: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
special_title: z.coerce.string().default(''),
|
||||
group_id: coerce.string(),
|
||||
user_id: coerce.string(),
|
||||
special_title: coerce.string().default(''),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,11 @@ import { GeneralCallResult } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]).optional(),
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]).optional(),
|
||||
phoneNumber: z.coerce.string().default(''),
|
||||
user_id: coerce.string().optional(),
|
||||
group_id: coerce.string().optional(),
|
||||
phoneNumber: coerce.string().default(''),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
@@ -29,7 +29,7 @@ export class SharePeer extends OneBotAction<Payload, GeneralCallResult & {
|
||||
}
|
||||
|
||||
const SchemaDataGroupEx = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: coerce.string(),
|
||||
});
|
||||
|
||||
type PayloadGroupEx = z.infer<typeof SchemaDataGroupEx>;
|
||||
|
@@ -2,10 +2,10 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
file_id: z.coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
file_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
words: z.array(z.coerce.string()),
|
||||
words: z.array(coerce.string()),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -4,7 +4,7 @@ import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OB11MessageImage, OB11MessageVideo } from '@/onebot/types';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
export interface GetFileResponse {
|
||||
file?: string; // path
|
||||
url?: string;
|
||||
@@ -14,8 +14,8 @@ export interface GetFileResponse {
|
||||
}
|
||||
|
||||
const GetFileBase_PayloadSchema = z.object({
|
||||
file: z.coerce.string().optional(),
|
||||
file_id: z.coerce.string().optional(),
|
||||
file: coerce.string().optional(),
|
||||
file_id: coerce.string().optional(),
|
||||
});
|
||||
|
||||
|
||||
|
@@ -2,10 +2,10 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
file_id: z.coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
file_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,9 +2,9 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
file_id: z.coerce.string(),
|
||||
file_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
folder_name: z.coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
folder_name: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -4,10 +4,10 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { z } from 'zod';
|
||||
import { NTQQGroupApi } from '@/core/apis';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
file_id: z.coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
file_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,11 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { z } from 'zod';
|
||||
import { NTQQGroupApi } from '@/core/apis';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
folder_id: z.coerce.string().optional(),
|
||||
folder: z.coerce.string().optional(),
|
||||
group_id: coerce.string(),
|
||||
folder_id: coerce.string().optional(),
|
||||
folder: coerce.string().optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -5,16 +5,16 @@ import { join as joinPath } from 'node:path';
|
||||
import { calculateFileMD5, uriToLocalFile } from '@/common/file';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
interface FileResponse {
|
||||
file: string;
|
||||
}
|
||||
|
||||
const SchemaData = z.object({
|
||||
url: z.coerce.string().optional(),
|
||||
base64: z.coerce.string().optional(),
|
||||
name: z.coerce.string().optional(),
|
||||
headers: z.union([z.coerce.string(), z.array(z.coerce.string())]).optional(),
|
||||
url: coerce.string().optional(),
|
||||
base64: coerce.string().optional(),
|
||||
name: coerce.string().optional(),
|
||||
headers: z.union([coerce.string(), z.array(coerce.string())]).optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -5,10 +5,10 @@ import { MessageUnique } from '@/common/message-unique';
|
||||
import { ChatType, ElementType, MsgSourceType, NTMsgType, RawMessage } from '@/core';
|
||||
import { z } from 'zod';
|
||||
import { isNumeric } from '@/common/helper';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
message_id: z.coerce.string().optional(),
|
||||
id: z.coerce.string().optional(),
|
||||
message_id: coerce.string().optional(),
|
||||
id: coerce.string().optional(),
|
||||
});
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
||||
|
@@ -5,15 +5,16 @@ import { ChatType } from '@/core/types';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { z } from 'zod';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
interface Response {
|
||||
messages: OB11Message[];
|
||||
}
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
message_seq: z.union([z.coerce.number(), z.coerce.string()]).optional(),
|
||||
count: z.union([z.coerce.number(), z.coerce.string()]).default(20),
|
||||
reverseOrder: z.coerce.boolean().default(false)
|
||||
user_id: coerce.string(),
|
||||
message_seq: coerce.string().optional(),
|
||||
count: coerce.number().default(20),
|
||||
reverseOrder: coerce.boolean().default(false)
|
||||
});
|
||||
|
||||
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()])
|
||||
group_id: coerce.string()
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()])
|
||||
group_id: coerce.string()
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,12 +3,12 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
folder_id: z.coerce.string().optional(),
|
||||
folder: z.coerce.string().optional(),
|
||||
file_count: z.union([z.coerce.number(), z.coerce.string()]).default(50),
|
||||
group_id: coerce.string(),
|
||||
folder_id: coerce.string().optional(),
|
||||
folder: coerce.string().optional(),
|
||||
file_count: coerce.number().default(50),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,9 +2,9 @@ import { WebHonorType } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: coerce.string(),
|
||||
type: z.nativeEnum(WebHonorType).optional()
|
||||
});
|
||||
|
||||
|
@@ -5,16 +5,17 @@ import { ChatType, Peer } from '@/core/types';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { z } from 'zod';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
interface Response {
|
||||
messages: OB11Message[];
|
||||
}
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
message_seq: z.union([z.coerce.number(), z.coerce.string()]).optional(),
|
||||
count: z.union([z.coerce.number(), z.coerce.string()]).default(20),
|
||||
reverseOrder: z.coerce.boolean().default(false)
|
||||
group_id: coerce.string(),
|
||||
message_seq: coerce.string().optional(),
|
||||
count: coerce.number().default(20),
|
||||
reverseOrder: coerce.boolean().default(false)
|
||||
});
|
||||
|
||||
|
||||
|
@@ -4,10 +4,10 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { OB11GroupFile, OB11GroupFileFolder } from '@/onebot';
|
||||
import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
file_count: z.union([z.coerce.number(), z.coerce.string()]).default(50),
|
||||
group_id: coerce.string(),
|
||||
file_count: coerce.number().default(50),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -4,10 +4,11 @@ import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { calcQQLevel } from '@/common/helper';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
no_cache: z.coerce.boolean().default(false),
|
||||
user_id: coerce.string(),
|
||||
no_cache: coerce.boolean().default(false),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
url: z.coerce.string(),
|
||||
url: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,12 +1,13 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
friend_id: z.union([z.coerce.string(), z.coerce.number()]).optional(),
|
||||
user_id: z.union([z.coerce.string(), z.coerce.number()]).optional(),
|
||||
temp_block: z.coerce.boolean().optional(),
|
||||
temp_both_del: z.coerce.boolean().optional(),
|
||||
friend_id: coerce.string().optional(),
|
||||
user_id: coerce.string().optional(),
|
||||
temp_block: coerce.boolean().optional(),
|
||||
temp_both_del: coerce.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
model: z.coerce.string(),
|
||||
model: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,16 +3,16 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { unlink } from 'node:fs/promises';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
content: z.coerce.string(),
|
||||
image: z.coerce.string().optional(),
|
||||
pinned: z.union([z.coerce.number(), z.coerce.string()]).default(0),
|
||||
type: z.union([z.coerce.number(), z.coerce.string()]).default(1),
|
||||
confirm_required: z.union([z.coerce.number(), z.coerce.string()]).default(1),
|
||||
is_show_edit_card: z.union([z.coerce.number(), z.coerce.string()]).default(0),
|
||||
tip_window_type: z.union([z.coerce.number(), z.coerce.string()]).default(0),
|
||||
group_id: coerce.string(),
|
||||
content: coerce.string(),
|
||||
image: coerce.string().optional(),
|
||||
pinned: coerce.number().default(0),
|
||||
type: coerce.number().default(1),
|
||||
confirm_required: coerce.number().default(1),
|
||||
is_show_edit_card: coerce.number().default(0),
|
||||
tip_window_type: coerce.number().default(0),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -4,9 +4,10 @@ import { checkFileExistV2, uriToLocalFile } from '@/common/file';
|
||||
import { z } from 'zod';
|
||||
import fs from 'node:fs/promises';
|
||||
import { GeneralCallResult } from '@/core';
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
file: z.coerce.string(),
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()])
|
||||
file: coerce.string(),
|
||||
group_id: coerce.string()
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,11 @@ import { NTQQUserApi } from '@/core/apis';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
nickname: z.coerce.string(),
|
||||
personal_note: z.coerce.string().optional(),
|
||||
sex: z.union([z.coerce.number(), z.coerce.string()]).optional(), // 传Sex值?建议传0
|
||||
nickname: coerce.string(),
|
||||
personal_note: coerce.string().optional(),
|
||||
sex: coerce.string().optional(), // 传Sex值?建议传0
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -5,13 +5,13 @@ import fs from 'fs';
|
||||
import { uriToLocalFile } from '@/common/file';
|
||||
import { SendMessageContext } from '@/onebot/api';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
file: z.coerce.string(),
|
||||
name: z.coerce.string(),
|
||||
folder: z.coerce.string().optional(),
|
||||
folder_id: z.coerce.string().optional(),//临时扩展
|
||||
group_id: coerce.string(),
|
||||
file: coerce.string(),
|
||||
name: coerce.string(),
|
||||
folder: coerce.string().optional(),
|
||||
folder_id: coerce.string().optional(),//临时扩展
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -6,11 +6,11 @@ import { uriToLocalFile } from '@/common/file';
|
||||
import { SendMessageContext } from '@/onebot/api';
|
||||
import { ContextMode, createContext } from '@/onebot/action/msg/SendMsg';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
file: z.coerce.string(),
|
||||
name: z.coerce.string(),
|
||||
user_id: coerce.string(),
|
||||
file: coerce.string(),
|
||||
name: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,9 +2,9 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
message_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
@@ -16,7 +16,7 @@ export default class DelEssenceMsg extends OneBotAction<Payload, unknown> {
|
||||
const msg = MessageUnique.getMsgIdAndPeerByShortId(+payload.message_id);
|
||||
if (!msg) {
|
||||
const data = this.core.apis.GroupApi.essenceLRU.getValue(+payload.message_id);
|
||||
if(!data) throw new Error('消息不存在');
|
||||
if (!data) throw new Error('消息不存在');
|
||||
const { msg_seq, msg_random, group_id } = JSON.parse(data) as { msg_seq: string, msg_random: string, group_id: string };
|
||||
return await this.core.apis.GroupApi.removeGroupEssenceBySeq(group_id, msg_seq, msg_random);
|
||||
}
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
notice_id: z.coerce.string()
|
||||
group_id: coerce.string(),
|
||||
notice_id: coerce.string()
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,11 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { AIVoiceChatType } from '@/core/packet/entities/aiChat';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
character: z.coerce.string(),
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
text: z.coerce.string(),
|
||||
character: coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
text: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -5,9 +5,9 @@ import { MessageUnique } from '@/common/message-unique';
|
||||
import crypto from 'crypto';
|
||||
import { z } from 'zod';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,9 +3,9 @@ import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,9 +3,10 @@ import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
no_cache: z.coerce.boolean().default(false),
|
||||
no_cache: coerce.boolean().default(false),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,11 +3,12 @@ import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
no_cache: z.coerce.boolean().default(false),
|
||||
group_id: coerce.string(),
|
||||
user_id: coerce.string(),
|
||||
no_cache: coerce.boolean().default(false),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -4,10 +4,11 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { GroupMember } from '@/core';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
no_cache: z.coerce.boolean().default(false)
|
||||
group_id: coerce.string(),
|
||||
no_cache: coerce.boolean().default(false)
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,6 +2,7 @@ import { WebApiGroupNoticeFeed } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
interface GroupNotice {
|
||||
sender_id: number;
|
||||
publish_time: number;
|
||||
@@ -17,7 +18,7 @@ interface GroupNotice {
|
||||
}
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,9 +2,9 @@ import { ShutUpGroupMember } from '@/core';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: coerce.string(),
|
||||
user_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,11 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { AIVoiceChatType } from '@/core/packet/entities/aiChat';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
character: z.coerce.string(),
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
text: z.coerce.string(),
|
||||
character: coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
text: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,9 +2,9 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
message_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,12 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { NTGroupRequestOperateTypes } from '@/core/types';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
flag: z.union([z.coerce.string(), z.coerce.number()]),
|
||||
approve: z.coerce.boolean().default(true),
|
||||
reason: z.union([z.coerce.string(), z.null()]).default(' '),
|
||||
flag: coerce.string(),
|
||||
approve: coerce.boolean().default(true),
|
||||
reason: coerce.string().nullable().default(' '),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,12 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { NTGroupMemberRole } from '@/core/types';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
enable: z.coerce.boolean().default(false),
|
||||
group_id: coerce.string(),
|
||||
user_id: coerce.string(),
|
||||
enable: coerce.boolean().default(false),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
duration: z.union([z.coerce.number(), z.coerce.string()]).default(0),
|
||||
group_id: coerce.string(),
|
||||
user_id: coerce.string(),
|
||||
duration: coerce.number().default(0),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,11 +1,11 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
card: z.coerce.string().optional(),
|
||||
group_id: coerce.string(),
|
||||
user_id: coerce.string(),
|
||||
card: coerce.string().optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
reject_add_request: z.union([z.coerce.boolean(), z.coerce.string()]).optional(),
|
||||
group_id: coerce.string(),
|
||||
user_id: coerce.string(),
|
||||
reject_add_request: coerce.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
is_dismiss: z.coerce.boolean().optional(),
|
||||
group_id: coerce.string(),
|
||||
is_dismiss: coerce.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,10 +2,10 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_name: z.coerce.string(),
|
||||
group_id: coerce.string(),
|
||||
group_name: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
enable: z.union([z.coerce.boolean(), z.coerce.string()]).optional(),
|
||||
group_id: coerce.string(),
|
||||
enable: coerce.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,9 +2,10 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
message_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,11 +3,11 @@ import { ChatType, Peer } from '@/core/types';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: z.coerce.string().optional(),
|
||||
user_id: z.coerce.string().optional(),
|
||||
message_id: coerce.string(),
|
||||
group_id: coerce.string().optional(),
|
||||
user_id: coerce.string().optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -5,11 +5,11 @@ import { MessageUnique } from '@/common/message-unique';
|
||||
import { RawMessage } from '@/core';
|
||||
import { z } from 'zod';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
export type ReturnDataType = OB11Message
|
||||
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
message_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
@@ -29,7 +29,7 @@ class GetMsg extends OneBotAction<Payload, OB11Message> {
|
||||
}
|
||||
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
|
||||
const orimsg = this.obContext.recallMsgCache.get(msgIdWithPeer.MsgId);
|
||||
let msg: RawMessage|undefined;
|
||||
let msg: RawMessage | undefined;
|
||||
if (orimsg) {
|
||||
msg = orimsg;
|
||||
} else {
|
||||
|
@@ -3,11 +3,11 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { coerce } from '@/common/coerce';
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.coerce.string(), z.coerce.number()]).optional(),
|
||||
group_id: z.union([z.coerce.string(), z.coerce.number()]).optional(),
|
||||
message_id: z.union([z.coerce.string(), z.coerce.number()]).optional(),
|
||||
user_id: coerce.string().optional(),
|
||||
group_id: coerce.string().optional(),
|
||||
message_id: coerce.string().optional(),
|
||||
});
|
||||
|
||||
type PlayloadType = z.infer<typeof SchemaData>;
|
||||
|
@@ -2,11 +2,12 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { MessageUnique } from '@/common/message-unique';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
message_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
emoji_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
set: z.coerce.boolean().optional(),
|
||||
message_id: coerce.string(),
|
||||
emoji_id: coerce.string(),
|
||||
set: coerce.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
group_id: z.union([z.coerce.number(), z.coerce.string()]).optional(),
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()]),
|
||||
group_id: coerce.string().optional(),
|
||||
user_id: coerce.string(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
interface Response {
|
||||
cookies: string,
|
||||
@@ -8,7 +9,7 @@ interface Response {
|
||||
}
|
||||
|
||||
const SchemaData = z.object({
|
||||
domain: z.coerce.string()
|
||||
domain: coerce.string()
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,9 +1,10 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { GetPacketStatusDepends } from '@/onebot/action/packet/GetPacketStatus';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()])
|
||||
user_id: coerce.string()
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,13 +1,14 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
interface Response {
|
||||
cookies: string,
|
||||
bkn: string
|
||||
}
|
||||
|
||||
const SchemaData = z.object({
|
||||
domain: z.coerce.string()
|
||||
domain: coerce.string()
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,9 +3,10 @@ import { OB11Construct } from '@/onebot/helper/data';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
no_cache: z.coerce.boolean().optional(),
|
||||
no_cache: coerce.boolean().optional(),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -3,9 +3,10 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
count: z.coerce.number().default(10),
|
||||
count: coerce.number().default(10),
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,10 +1,11 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
times: z.union([z.coerce.number(), z.coerce.string()]).default(1),
|
||||
user_id: z.union([z.coerce.number(), z.coerce.string()])
|
||||
times: coerce.number().default(1),
|
||||
user_id: coerce.string()
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,11 +1,12 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '@/common/coerce';
|
||||
|
||||
const SchemaData = z.object({
|
||||
flag: z.union([z.coerce.string(), z.coerce.number()]),
|
||||
approve: z.union([z.coerce.string(), z.coerce.boolean()]).default(true),
|
||||
remark: z.union([z.coerce.string(), z.null()]).nullable().optional()
|
||||
flag: coerce.string(),
|
||||
approve: coerce.boolean().default(true),
|
||||
remark: coerce.string().nullable().optional()
|
||||
});
|
||||
|
||||
type Payload = z.infer<typeof SchemaData>;
|
||||
|
@@ -1,71 +1,72 @@
|
||||
import { z } from 'zod';
|
||||
import { coerce } from '../../common/coerce';
|
||||
|
||||
const HttpServerConfigSchema = z.object({
|
||||
name: z.coerce.string().default('http-server'),
|
||||
enable: z.coerce.boolean().default(false),
|
||||
port: z.coerce.number().default(3000),
|
||||
host: z.coerce.string().default('0.0.0.0'),
|
||||
enableCors: z.coerce.boolean().default(true),
|
||||
enableWebsocket: z.coerce.boolean().default(true),
|
||||
messagePostFormat: z.coerce.string().default('array'),
|
||||
token: z.coerce.string().default(''),
|
||||
debug: z.coerce.boolean().default(false)
|
||||
name: coerce.string().default('http-server'),
|
||||
enable: coerce.boolean().default(false),
|
||||
port: coerce.number().default(3000),
|
||||
host: coerce.string().default('0.0.0.0'),
|
||||
enableCors: coerce.boolean().default(true),
|
||||
enableWebsocket: coerce.boolean().default(true),
|
||||
messagePostFormat: coerce.string().default('array'),
|
||||
token: coerce.string().default(''),
|
||||
debug: coerce.boolean().default(false)
|
||||
});
|
||||
|
||||
const HttpSseServerConfigSchema = z.object({
|
||||
name: z.coerce.string().default('http-sse-server'),
|
||||
enable: z.coerce.boolean().default(false),
|
||||
port: z.coerce.number().default(3000),
|
||||
host: z.coerce.string().default('0.0.0.0'),
|
||||
enableCors: z.coerce.boolean().default(true),
|
||||
enableWebsocket: z.coerce.boolean().default(true),
|
||||
messagePostFormat: z.coerce.string().default('array'),
|
||||
token: z.coerce.string().default(''),
|
||||
debug: z.coerce.boolean().default(false),
|
||||
reportSelfMessage: z.coerce.boolean().default(false)
|
||||
name: coerce.string().default('http-sse-server'),
|
||||
enable: coerce.boolean().default(false),
|
||||
port: coerce.number().default(3000),
|
||||
host: coerce.string().default('0.0.0.0'),
|
||||
enableCors: coerce.boolean().default(true),
|
||||
enableWebsocket: coerce.boolean().default(true),
|
||||
messagePostFormat: coerce.string().default('array'),
|
||||
token: coerce.string().default(''),
|
||||
debug: coerce.boolean().default(false),
|
||||
reportSelfMessage: coerce.boolean().default(false)
|
||||
});
|
||||
|
||||
const HttpClientConfigSchema = z.object({
|
||||
name: z.coerce.string().default('http-client'),
|
||||
enable: z.coerce.boolean().default(false),
|
||||
url: z.coerce.string().default('http://localhost:8080'),
|
||||
messagePostFormat: z.coerce.string().default('array'),
|
||||
reportSelfMessage: z.coerce.boolean().default(false),
|
||||
token: z.coerce.string().default(''),
|
||||
debug: z.coerce.boolean().default(false)
|
||||
name: coerce.string().default('http-client'),
|
||||
enable: coerce.boolean().default(false),
|
||||
url: coerce.string().default('http://localhost:8080'),
|
||||
messagePostFormat: coerce.string().default('array'),
|
||||
reportSelfMessage: coerce.boolean().default(false),
|
||||
token: coerce.string().default(''),
|
||||
debug: coerce.boolean().default(false)
|
||||
});
|
||||
|
||||
const WebsocketServerConfigSchema = z.object({
|
||||
name: z.coerce.string().default('websocket-server'),
|
||||
enable: z.coerce.boolean().default(false),
|
||||
host: z.coerce.string().default('0.0.0.0'),
|
||||
port: z.coerce.number().default(3001),
|
||||
messagePostFormat: z.coerce.string().default('array'),
|
||||
reportSelfMessage: z.coerce.boolean().default(false),
|
||||
token: z.coerce.string().default(''),
|
||||
enableForcePushEvent: z.coerce.boolean().default(true),
|
||||
debug: z.coerce.boolean().default(false),
|
||||
heartInterval: z.coerce.number().default(30000)
|
||||
name: coerce.string().default('websocket-server'),
|
||||
enable: coerce.boolean().default(false),
|
||||
host: coerce.string().default('0.0.0.0'),
|
||||
port: coerce.number().default(3001),
|
||||
messagePostFormat: coerce.string().default('array'),
|
||||
reportSelfMessage: coerce.boolean().default(false),
|
||||
token: coerce.string().default(''),
|
||||
enableForcePushEvent: coerce.boolean().default(true),
|
||||
debug: coerce.boolean().default(false),
|
||||
heartInterval: coerce.number().default(30000)
|
||||
});
|
||||
|
||||
const WebsocketClientConfigSchema = z.object({
|
||||
name: z.coerce.string().default('websocket-client'),
|
||||
enable: z.coerce.boolean().default(false),
|
||||
url: z.coerce.string().default('ws://localhost:8082'),
|
||||
messagePostFormat: z.coerce.string().default('array'),
|
||||
reportSelfMessage: z.coerce.boolean().default(false),
|
||||
reconnectInterval: z.coerce.number().default(5000),
|
||||
token: z.coerce.string().default(''),
|
||||
debug: z.coerce.boolean().default(false),
|
||||
heartInterval: z.coerce.number().default(30000)
|
||||
name: coerce.string().default('websocket-client'),
|
||||
enable: coerce.boolean().default(false),
|
||||
url: coerce.string().default('ws://localhost:8082'),
|
||||
messagePostFormat: coerce.string().default('array'),
|
||||
reportSelfMessage: coerce.boolean().default(false),
|
||||
reconnectInterval: coerce.number().default(5000),
|
||||
token: coerce.string().default(''),
|
||||
debug: coerce.boolean().default(false),
|
||||
heartInterval: coerce.number().default(30000)
|
||||
});
|
||||
|
||||
const PluginConfigSchema = z.object({
|
||||
name: z.coerce.string().default('plugin'),
|
||||
enable: z.coerce.boolean().default(false),
|
||||
messagePostFormat: z.coerce.string().default('array'),
|
||||
reportSelfMessage: z.coerce.boolean().default(false),
|
||||
debug: z.coerce.boolean().default(false),
|
||||
name: coerce.string().default('plugin'),
|
||||
enable: coerce.boolean().default(false),
|
||||
messagePostFormat: coerce.string().default('array'),
|
||||
reportSelfMessage: coerce.boolean().default(false),
|
||||
debug: coerce.boolean().default(false),
|
||||
});
|
||||
|
||||
const NetworkConfigSchema = z.object({
|
||||
@@ -79,9 +80,9 @@ const NetworkConfigSchema = z.object({
|
||||
|
||||
export const OneBotConfigSchema = z.object({
|
||||
network: NetworkConfigSchema,
|
||||
musicSignUrl: z.coerce.string().default(''),
|
||||
enableLocalFile2Url: z.coerce.boolean().default(false),
|
||||
parseMultMsg: z.coerce.boolean().default(false)
|
||||
musicSignUrl: coerce.string().default(''),
|
||||
enableLocalFile2Url: coerce.boolean().default(false),
|
||||
parseMultMsg: coerce.boolean().default(false)
|
||||
});
|
||||
|
||||
export type OneBotConfig = z.infer<typeof OneBotConfigSchema>;
|
||||
|
@@ -31,7 +31,9 @@ import { WebUiDataRuntime } from '@/webui/src/helper/Data';
|
||||
import { napCatVersion } from '@/common/version';
|
||||
import { NodeIO3MiscListener } from '@/core/listeners/NodeIO3MiscListener';
|
||||
import { sleep } from '@/common/helper';
|
||||
|
||||
import { downloadFFmpegIfNotExists } from '@/common/download-ffmpeg';
|
||||
import { FFmpegService } from '@/common/ffmpeg';
|
||||
import { connectToNamedPipe } from '@/shell/pipe';
|
||||
// NapCat Shell App ES 入口文件
|
||||
async function handleUncaughtExceptions(logger: LogWrapper) {
|
||||
process.on('uncaughtException', (err) => {
|
||||
@@ -220,7 +222,7 @@ async function handleLoginInner(context: { isLogined: boolean }, logger: LogWrap
|
||||
logger.log(`可用于快速登录的 QQ:\n${historyLoginList
|
||||
.map((u, index) => `${index + 1}. ${u.uin} ${u.nickName}`)
|
||||
.join('\n')
|
||||
}`);
|
||||
}`);
|
||||
}
|
||||
loginService.getQRCodePicture();
|
||||
try {
|
||||
@@ -311,6 +313,14 @@ export async function NCoreInitShell() {
|
||||
const pathWrapper = new NapCatPathWrapper();
|
||||
const logger = new LogWrapper(pathWrapper.logsPath);
|
||||
handleUncaughtExceptions(logger);
|
||||
await connectToNamedPipe(logger).catch(e => logger.logError('命名管道连接失败', e));
|
||||
downloadFFmpegIfNotExists(logger).then(({ path, reset }) => {
|
||||
if (reset && path) {
|
||||
FFmpegService.setFfmpegPath(path, logger);
|
||||
}
|
||||
}).catch(e => {
|
||||
logger.logError('[Ffmpeg] Error:', e);
|
||||
});
|
||||
const basicInfoWrapper = new QQBasicInfoWrapper({ logger });
|
||||
const wrapper = loadQQWrapper(basicInfoWrapper.getFullQQVesion());
|
||||
|
||||
|
@@ -1,37 +1,2 @@
|
||||
import { NCoreInitShell } from './base';
|
||||
import * as net from 'net'; // 引入 net 模块
|
||||
import * as process from 'process';
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
const pid = process.pid;
|
||||
const pipePath = `\\\\.\\pipe\\NapCat_${pid}`;
|
||||
try {
|
||||
const pipeSocket = net.connect(pipePath, () => {
|
||||
console.log(`已连接到命名管道: ${pipePath}`);
|
||||
process.stdout.write = (
|
||||
chunk: any,
|
||||
encoding?: BufferEncoding | (() => void),
|
||||
cb?: () => void
|
||||
): boolean => {
|
||||
if (typeof encoding === 'function') {
|
||||
cb = encoding;
|
||||
encoding = undefined;
|
||||
}
|
||||
return pipeSocket.write(chunk, encoding as BufferEncoding, cb);
|
||||
};
|
||||
console.log(`stdout 已重定向到命名管道: ${pipePath}`);
|
||||
});
|
||||
|
||||
pipeSocket.on('error', (err) => {
|
||||
console.log(`连接命名管道 ${pipePath} 时出错:`, err);
|
||||
});
|
||||
|
||||
pipeSocket.on('end', () => {
|
||||
console.log('命名管道连接已关闭');
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log(`尝试连接命名管道 ${pipePath} 时发生异常:`, error);
|
||||
}
|
||||
}
|
||||
NCoreInitShell();
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user